Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
feat: enable rawoutput format
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Csati <bcsati@cisco.com>
Co-authored-by: Adam Tagscherer <atagsche@cisco.com>

a
  • Loading branch information
csatib02 committed May 29, 2024
1 parent b5931ff commit 6e91297
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 26 deletions.
6 changes: 6 additions & 0 deletions plugins/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ components:
description: Describes data saved to a JSON file when a scan finishes successfully.
required:
- vmclarity
- rawJSON
properties:
annotations:
# Can be used to attach some scan data consumable by third-party service.
Expand All @@ -208,6 +209,11 @@ components:
# Specifies concrete scan result data that can be consumed by VMClarity API.
# Required.
$ref: '#/components/schemas/VMClarityData'
rawJSON:
# Specifies raw scan result data.
# Required.
type: object
description: Defines scan result data that is unfornatted.

VMClarityData:
type: object
Expand Down
46 changes: 23 additions & 23 deletions plugins/sdk-go/internal/plugin/plugin.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions plugins/sdk-go/types/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 33 additions & 3 deletions plugins/sdk-python/plugin/models/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,31 @@ class Result(Model):
Do not edit the class manually.
"""

def __init__(self, annotations=None, vmclarity=None): # noqa: E501
def __init__(self, annotations=None, vmclarity=None, raw_json=None): # noqa: E501
"""Result - a model defined in OpenAPI
:param annotations: The annotations of this Result. # noqa: E501
:type annotations: Dict[str, str]
:param vmclarity: The vmclarity of this Result. # noqa: E501
:type vmclarity: VMClarityData
:param raw_json: The raw_json of this Result. # noqa: E501
:type raw_json: object
"""
self.openapi_types = {
'annotations': Dict[str, str],
'vmclarity': VMClarityData
'vmclarity': VMClarityData,
'raw_json': object
}

self.attribute_map = {
'annotations': 'annotations',
'vmclarity': 'vmclarity'
'vmclarity': 'vmclarity',
'raw_json': 'rawJSON'
}

self._annotations = annotations
self._vmclarity = vmclarity
self._raw_json = raw_json

@classmethod
def from_dict(cls, dikt) -> 'Result':
Expand Down Expand Up @@ -91,3 +96,28 @@ def vmclarity(self, vmclarity: VMClarityData):
raise ValueError("Invalid value for `vmclarity`, must not be `None`") # noqa: E501

self._vmclarity = vmclarity

@property
def raw_json(self) -> object:
"""Gets the raw_json of this Result.
Defines scan result data that is unfornatted. # noqa: E501
:return: The raw_json of this Result.
:rtype: object
"""
return self._raw_json

@raw_json.setter
def raw_json(self, raw_json: object):
"""Sets the raw_json of this Result.
Defines scan result data that is unfornatted. # noqa: E501
:param raw_json: The raw_json of this Result.
:type raw_json: object
"""
if raw_json is None:
raise ValueError("Invalid value for `raw_json`, must not be `None`") # noqa: E501

self._raw_json = raw_json
14 changes: 14 additions & 0 deletions plugins/store/kics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,25 @@ func (s *Scanner) formatOutput(rawFile, outputFile string) error {
}
}

// Marshal the kICS summary back to JSON
summaryJSON, err := json.MarshalIndent(summary, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal KICS summary: %w", err)
}

// Unmarshal the KICS summary to a map to extract the raw data
var rawData map[string]interface{}
err = json.Unmarshal(summaryJSON, &rawData)
if err != nil {
return fmt.Errorf("failed to unmarshal KICS summary: %w", err)
}

// Save result
result := types.Result{
Vmclarity: types.VMClarityData{
Misconfigurations: &misconfigurations,
},
RawJSON: rawData,
}
if err := result.Export(outputFile); err != nil {
return fmt.Errorf("failed to save KICS result: %w", err)
Expand Down

0 comments on commit 6e91297

Please sign in to comment.