This repository has been archived by the owner on Jan 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: multiple adapters added(kendra, kinesis, kinesisvideo, proton, q… (
#1227) * add: multiple adapters added(kendra, kinesis, kinesisvideo, proton, qldb, ses, shield, timestreamwrite, transfer, translate, waf, wafv2, xray) * added comment * updated go.mod and go.sum files * fix * fix adapters * Update internal/adapters/cloud/aws/kinesisvideo/adapt.go * Update internal/adapters/cloud/aws/waf/adapt.go * Update internal/adapters/cloud/aws/wafv2/adapt.go * fix issues Signed-off-by: Simar <[email protected]> --------- Signed-off-by: Simar <[email protected]> Co-authored-by: simar7 <[email protected]> Co-authored-by: Simar <[email protected]>
- Loading branch information
1 parent
8b5e832
commit 1a1ff87
Showing
54 changed files
with
2,154 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package kendra | ||
|
||
import ( | ||
"github.com/aquasecurity/defsec/internal/adapters/cloud/aws" | ||
"github.com/aquasecurity/defsec/pkg/concurrency" | ||
"github.com/aquasecurity/defsec/pkg/providers/aws/kendra" | ||
"github.com/aquasecurity/defsec/pkg/state" | ||
defsecTypes "github.com/aquasecurity/defsec/pkg/types" | ||
api "github.com/aws/aws-sdk-go-v2/service/kendra" | ||
aatypes "github.com/aws/aws-sdk-go-v2/service/kendra/types" | ||
) | ||
|
||
type adapter struct { | ||
*aws.RootAdapter | ||
api *api.Client | ||
} | ||
|
||
func init() { | ||
aws.RegisterServiceAdapter(&adapter{}) | ||
} | ||
|
||
func (a *adapter) Provider() string { | ||
return "aws" | ||
} | ||
|
||
func (a *adapter) Name() string { | ||
return "kendra" | ||
} | ||
|
||
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error { | ||
|
||
a.RootAdapter = root | ||
a.api = api.NewFromConfig(root.SessionConfig()) | ||
var err error | ||
|
||
state.AWS.Kendra.ListIndices, err = a.getListIndex() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *adapter) getListIndex() ([]kendra.ListIndices, error) { | ||
|
||
a.Tracker().SetServiceLabel("Discovering ListIndices...") | ||
|
||
var apiListIndex []aatypes.IndexConfigurationSummary | ||
var input api.ListIndicesInput | ||
for { | ||
output, err := a.api.ListIndices(a.Context(), &input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
apiListIndex = append(apiListIndex, output.IndexConfigurationSummaryItems...) | ||
a.Tracker().SetTotalResources(len(apiListIndex)) | ||
if output.IndexConfigurationSummaryItems == nil { | ||
break | ||
} | ||
input.NextToken = output.NextToken | ||
} | ||
|
||
a.Tracker().SetServiceLabel("Adapting List Indices...") | ||
return concurrency.Adapt(apiListIndex, a.RootAdapter, a.adaptListIndex), nil | ||
} | ||
|
||
func (a *adapter) adaptListIndex(index aatypes.IndexConfigurationSummary) (*kendra.ListIndices, error) { | ||
|
||
metadata := a.CreateMetadata(*index.Name) | ||
|
||
getkey, err := a.api.DescribeIndex(a.Context(), &api.DescribeIndexInput{ | ||
Id: index.Id, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var key string | ||
if getkey.ServerSideEncryptionConfiguration.KmsKeyId != nil { | ||
key = *getkey.ServerSideEncryptionConfiguration.KmsKeyId | ||
} | ||
|
||
return &kendra.ListIndices{ | ||
Metadata: metadata, | ||
KmsKey: kendra.KmsKey{ | ||
Metadata: metadata, | ||
KmsKeyId: defsecTypes.String(key, metadata), | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package kinesisvideo | ||
|
||
import ( | ||
"github.com/aquasecurity/defsec/internal/adapters/cloud/aws" | ||
"github.com/aquasecurity/defsec/pkg/concurrency" | ||
"github.com/aquasecurity/defsec/pkg/providers/aws/kinesisvideo" | ||
"github.com/aquasecurity/defsec/pkg/state" | ||
defsecTypes "github.com/aquasecurity/defsec/pkg/types" | ||
api "github.com/aws/aws-sdk-go-v2/service/kinesisvideo" | ||
aatypes "github.com/aws/aws-sdk-go-v2/service/kinesisvideo/types" | ||
) | ||
|
||
type adapter struct { | ||
*aws.RootAdapter | ||
api *api.Client | ||
} | ||
|
||
func init() { | ||
aws.RegisterServiceAdapter(&adapter{}) | ||
} | ||
|
||
func (a *adapter) Provider() string { | ||
return "aws" | ||
} | ||
|
||
func (a *adapter) Name() string { | ||
return "kinesisvideo" | ||
} | ||
|
||
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error { | ||
|
||
a.RootAdapter = root | ||
a.api = api.NewFromConfig(root.SessionConfig()) | ||
var err error | ||
|
||
state.AWS.Kinesisvideo.StreamInfoList, err = a.getStreamInfo() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *adapter) getStreamInfo() ([]kinesisvideo.StreamInfo, error) { | ||
|
||
a.Tracker().SetServiceLabel("Discovering Stream Info...") | ||
|
||
var apiStreamInfo []aatypes.StreamInfo | ||
var input api.ListStreamsInput | ||
for { | ||
output, err := a.api.ListStreams(a.Context(), &input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
apiStreamInfo = append(apiStreamInfo, output.StreamInfoList...) | ||
a.Tracker().SetTotalResources(len(apiStreamInfo)) | ||
if output.StreamInfoList == nil { | ||
break | ||
} | ||
input.NextToken = output.NextToken | ||
} | ||
|
||
a.Tracker().SetServiceLabel("Adapting Stream Info...") | ||
return concurrency.Adapt(apiStreamInfo, a.RootAdapter, a.adaptStreamInfo), nil | ||
} | ||
|
||
func (a *adapter) adaptStreamInfo(apiStreamInfo aatypes.StreamInfo) (*kinesisvideo.StreamInfo, error) { | ||
|
||
metadata := a.CreateMetadataFromARN(*apiStreamInfo.StreamARN) | ||
|
||
var key string | ||
if apiStreamInfo.KmsKeyId != nil { | ||
key = *apiStreamInfo.KmsKeyId | ||
} | ||
|
||
return &kinesisvideo.StreamInfo{ | ||
Metadata: metadata, | ||
KmsKeyId: defsecTypes.String(key, metadata), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package proton | ||
|
||
import ( | ||
"github.com/aquasecurity/defsec/internal/adapters/cloud/aws" | ||
"github.com/aquasecurity/defsec/pkg/concurrency" | ||
"github.com/aquasecurity/defsec/pkg/providers/aws/proton" | ||
"github.com/aquasecurity/defsec/pkg/state" | ||
defsecTypes "github.com/aquasecurity/defsec/pkg/types" | ||
api "github.com/aws/aws-sdk-go-v2/service/proton" | ||
aatypes "github.com/aws/aws-sdk-go-v2/service/proton/types" | ||
) | ||
|
||
type adapter struct { | ||
*aws.RootAdapter | ||
api *api.Client | ||
} | ||
|
||
func init() { | ||
aws.RegisterServiceAdapter(&adapter{}) | ||
} | ||
|
||
func (a *adapter) Provider() string { | ||
return "aws" | ||
} | ||
|
||
func (a *adapter) Name() string { | ||
return "proton" | ||
} | ||
|
||
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error { | ||
|
||
a.RootAdapter = root | ||
a.api = api.NewFromConfig(root.SessionConfig()) | ||
var err error | ||
|
||
state.AWS.Proton.ListEnvironmentTemplates, err = a.getEnvironmentTemplate() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *adapter) getEnvironmentTemplate() ([]proton.EnvironmentTemplate, error) { | ||
|
||
a.Tracker().SetServiceLabel("Discovering Environment Template ...") | ||
|
||
var apiEnvironmentTemplate []aatypes.EnvironmentTemplateSummary | ||
var input api.ListEnvironmentTemplatesInput | ||
for { | ||
output, err := a.api.ListEnvironmentTemplates(a.Context(), &input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
apiEnvironmentTemplate = append(apiEnvironmentTemplate, output.Templates...) | ||
a.Tracker().SetTotalResources(len(apiEnvironmentTemplate)) | ||
if output.Templates == nil { | ||
break | ||
} | ||
input.NextToken = output.NextToken | ||
} | ||
|
||
a.Tracker().SetServiceLabel("Adapting Stream Info...") | ||
return concurrency.Adapt(apiEnvironmentTemplate, a.RootAdapter, a.adaptEnvironmentTemplate), nil | ||
} | ||
|
||
func (a *adapter) adaptEnvironmentTemplate(apiEnvironmentTemplate aatypes.EnvironmentTemplateSummary) (*proton.EnvironmentTemplate, error) { | ||
|
||
metadata := a.CreateMetadataFromARN(*apiEnvironmentTemplate.Arn) | ||
|
||
getEncrytpitonKey, err := a.api.GetEnvironmentTemplate(a.Context(), &api.GetEnvironmentTemplateInput{ | ||
Name: apiEnvironmentTemplate.Name, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var encryptionkey string | ||
if getEncrytpitonKey.EnvironmentTemplate.EncryptionKey != nil { | ||
encryptionkey = *getEncrytpitonKey.EnvironmentTemplate.EncryptionKey | ||
} | ||
|
||
return &proton.EnvironmentTemplate{ | ||
Metadata: metadata, | ||
EncryptionKey: defsecTypes.String(encryptionkey, metadata), | ||
}, nil | ||
} |
Oops, something went wrong.