Skip to content

Commit

Permalink
restructure the services code
Browse files Browse the repository at this point in the history
  • Loading branch information
simar7 committed Sep 26, 2023
1 parent 0b177fa commit f6180c0
Show file tree
Hide file tree
Showing 62 changed files with 229 additions and 181 deletions.
16 changes: 16 additions & 0 deletions internal/adapters/cloud/adapt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cloud

import (
"context"

"github.com/aquasecurity/defsec/pkg/state"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/options"
)

// Adapt ...
func Adapt(ctx context.Context, opt options.Options) (*state.State, error) {
cloudState := &state.State{}
err := aws.Adapt(ctx, cloudState, opt)
return cloudState, err
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import (
"github.com/aquasecurity/defsec/pkg/providers/aws/accessanalyzer"
"github.com/aquasecurity/defsec/pkg/state"
"github.com/aquasecurity/defsec/pkg/types"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
"github.com/aws/aws-sdk-go-v2/aws/arn"
api "github.com/aws/aws-sdk-go-v2/service/accessanalyzer"
aatypes "github.com/aws/aws-sdk-go-v2/service/accessanalyzer/types"

"github.com/aquasecurity/trivy-aws/internal/adapters"
"github.com/aquasecurity/trivy-aws/pkg/concurrency"
)

type adapter struct {
*adapters.RootAdapter
*aws.RootAdapter
api *api.Client
}

func init() {
adapters.RegisterServiceAdapter(&adapter{})
aws.RegisterServiceAdapter(&adapter{})
}

func (a *adapter) Provider() string {
Expand All @@ -31,7 +31,7 @@ func (a *adapter) Name() string {
return "accessanalyzer"
}

func (a *adapter) Adapt(root *adapters.RootAdapter, state *state.State) error {
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error {

a.RootAdapter = root
a.api = api.NewFromConfig(root.SessionConfig())
Expand Down
25 changes: 11 additions & 14 deletions internal/adapters/adapt.go → internal/adapters/cloud/aws/adapt.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package adapters
package aws

import (
"context"
"fmt"

"github.com/aquasecurity/defsec/pkg/types"
"github.com/aquasecurity/trivy-aws/pkg/concurrency"
"github.com/aquasecurity/trivy-aws/pkg/errs"

"github.com/aquasecurity/defsec/pkg/debug"

"github.com/aws/aws-sdk-go-v2/service/sts"

"github.com/aquasecurity/defsec/pkg/state"
"github.com/aquasecurity/defsec/pkg/types"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/options"
"github.com/aquasecurity/trivy-aws/pkg/progress"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/sts"

"github.com/aquasecurity/trivy-aws/pkg/concurrency"
"github.com/aquasecurity/trivy-aws/pkg/errs"
"github.com/aquasecurity/trivy-aws/pkg/progress"
)

var registeredAdapters []ServiceAdapter
Expand Down Expand Up @@ -129,13 +132,7 @@ func AllServices() []string {
return services
}

func Adapt(ctx context.Context, opt Options) (*state.State, error) {
cloudState := &state.State{}
err := adapt(ctx, cloudState, opt)
return cloudState, err
}

func adapt(ctx context.Context, state *state.State, opt Options) error {
func Adapt(ctx context.Context, state *state.State, opt options.Options) error {
c := &RootAdapter{
ctx: ctx,
tracker: opt.ProgressTracker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ package api_gateway

import (
"github.com/aquasecurity/defsec/pkg/state"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
apiv1 "github.com/aws/aws-sdk-go-v2/service/apigateway"
apiv2 "github.com/aws/aws-sdk-go-v2/service/apigatewayv2"

"github.com/aquasecurity/trivy-aws/internal/adapters"
)

type adapter struct {
*adapters.RootAdapter
*aws.RootAdapter
clientV1 *apiv1.Client
clientV2 *apiv2.Client
}

func init() {
adapters.RegisterServiceAdapter(&adapter{})
aws.RegisterServiceAdapter(&adapter{})
}

func (a *adapter) Provider() string {
Expand All @@ -26,7 +25,7 @@ func (a *adapter) Name() string {
return "api-gateway"
}

func (a *adapter) Adapt(root *adapters.RootAdapter, state *state.State) error {
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error {

a.RootAdapter = root
a.clientV1 = apiv1.NewFromConfig(root.SessionConfig())
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
"github.com/aquasecurity/defsec/pkg/providers/aws/athena"
"github.com/aquasecurity/defsec/pkg/state"
defsecTypes "github.com/aquasecurity/defsec/pkg/types"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
api "github.com/aws/aws-sdk-go-v2/service/athena"
"github.com/aws/aws-sdk-go-v2/service/athena/types"

"github.com/aquasecurity/trivy-aws/internal/adapters"
"github.com/aquasecurity/trivy-aws/pkg/concurrency"
)

type adapter struct {
*adapters.RootAdapter
*aws.RootAdapter
client *api.Client
}

func init() {
adapters.RegisterServiceAdapter(&adapter{})
aws.RegisterServiceAdapter(&adapter{})
}

func (a *adapter) Provider() string {
Expand All @@ -30,7 +30,7 @@ func (a *adapter) Name() string {
return "athena"
}

func (a *adapter) Adapt(root *adapters.RootAdapter, state *state.State) error {
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error {

a.RootAdapter = root
a.client = api.NewFromConfig(root.SessionConfig())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import (
"github.com/aquasecurity/defsec/pkg/providers/aws/cloudfront"
"github.com/aquasecurity/defsec/pkg/state"
defsecTypes "github.com/aquasecurity/defsec/pkg/types"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
api "github.com/aws/aws-sdk-go-v2/service/cloudfront"
"github.com/aws/aws-sdk-go-v2/service/cloudfront/types"

"github.com/aquasecurity/trivy-aws/internal/adapters"
"github.com/aquasecurity/trivy-aws/pkg/concurrency"
)

type adapter struct {
*adapters.RootAdapter
*aws.RootAdapter
client *api.Client
}

func init() {
adapters.RegisterServiceAdapter(&adapter{})
aws.RegisterServiceAdapter(&adapter{})
}

func (a *adapter) Provider() string {
Expand All @@ -28,7 +28,7 @@ func (a *adapter) Name() string {
return "cloudfront"
}

func (a *adapter) Adapt(root *adapters.RootAdapter, state *state.State) error {
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error {

a.RootAdapter = root
a.client = api.NewFromConfig(root.SessionConfig())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import (
"github.com/aquasecurity/defsec/pkg/providers/aws/cloudtrail"
"github.com/aquasecurity/defsec/pkg/state"
defsecTypes "github.com/aquasecurity/defsec/pkg/types"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
api "github.com/aws/aws-sdk-go-v2/service/cloudtrail"
"github.com/aws/aws-sdk-go-v2/service/cloudtrail/types"

"github.com/aquasecurity/trivy-aws/internal/adapters"
"github.com/aquasecurity/trivy-aws/pkg/concurrency"
)

type adapter struct {
*adapters.RootAdapter
*aws.RootAdapter
client *api.Client
}

func init() {
adapters.RegisterServiceAdapter(&adapter{})
aws.RegisterServiceAdapter(&adapter{})
}

func (a *adapter) Provider() string {
Expand All @@ -28,7 +28,7 @@ func (a *adapter) Name() string {
return "cloudtrail"
}

func (a *adapter) Adapt(root *adapters.RootAdapter, state *state.State) error {
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error {

a.RootAdapter = root
a.client = api.NewFromConfig(root.SessionConfig())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import (
"github.com/aquasecurity/defsec/pkg/providers/aws/cloudwatch"
"github.com/aquasecurity/defsec/pkg/state"
defsecTypes "github.com/aquasecurity/defsec/pkg/types"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
cwApi "github.com/aws/aws-sdk-go-v2/service/cloudwatch"
cwTypes "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
api "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"

"github.com/aquasecurity/trivy-aws/internal/adapters"
"github.com/aquasecurity/trivy-aws/pkg/concurrency"
)

type adapter struct {
*adapters.RootAdapter
*aws.RootAdapter
logsClient *api.Client
alarmsClient *cwApi.Client
}

func init() {
adapters.RegisterServiceAdapter(&adapter{})
aws.RegisterServiceAdapter(&adapter{})
}

func (a *adapter) Provider() string {
Expand All @@ -31,7 +31,7 @@ func (a *adapter) Name() string {
return "cloudwatch"
}

func (a *adapter) Adapt(root *adapters.RootAdapter, state *state.State) error {
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error {

a.RootAdapter = root
a.logsClient = api.NewFromConfig(root.SessionConfig())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"github.com/aquasecurity/defsec/pkg/providers/aws/codebuild"
"github.com/aquasecurity/defsec/pkg/state"
defsecTypes "github.com/aquasecurity/defsec/pkg/types"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
api "github.com/aws/aws-sdk-go-v2/service/codebuild"

"github.com/aquasecurity/trivy-aws/internal/adapters"
"github.com/aquasecurity/trivy-aws/pkg/concurrency"
)

type adapter struct {
*adapters.RootAdapter
*aws.RootAdapter
client *api.Client
}

func init() {
adapters.RegisterServiceAdapter(&adapter{})
aws.RegisterServiceAdapter(&adapter{})
}

func (a *adapter) Provider() string {
Expand All @@ -27,7 +27,7 @@ func (a *adapter) Name() string {
return "codebuild"
}

func (a *adapter) Adapt(root *adapters.RootAdapter, state *state.State) error {
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error {

a.RootAdapter = root
a.client = api.NewFromConfig(root.SessionConfig())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import (
"github.com/aquasecurity/defsec/pkg/providers/aws/documentdb"
"github.com/aquasecurity/defsec/pkg/state"
defsecTypes "github.com/aquasecurity/defsec/pkg/types"
"github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
api "github.com/aws/aws-sdk-go-v2/service/docdb"
"github.com/aws/aws-sdk-go-v2/service/docdb/types"

"github.com/aquasecurity/trivy-aws/internal/adapters"
"github.com/aquasecurity/trivy-aws/pkg/concurrency"
)

type adapter struct {
*adapters.RootAdapter
*aws.RootAdapter
client *api.Client
}

func init() {
adapters.RegisterServiceAdapter(&adapter{})
aws.RegisterServiceAdapter(&adapter{})
}

func (a *adapter) Provider() string {
Expand All @@ -28,7 +28,7 @@ func (a *adapter) Name() string {
return "documentdb"
}

func (a *adapter) Adapt(root *adapters.RootAdapter, state *state.State) error {
func (a *adapter) Adapt(root *aws.RootAdapter, state *state.State) error {

a.RootAdapter = root
a.client = api.NewFromConfig(root.SessionConfig())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"github.com/aquasecurity/defsec/pkg/providers/aws/dynamodb"
"github.com/aquasecurity/defsec/pkg/state"
defsecTypes "github.com/aquasecurity/defsec/pkg/types"
aws2 "github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
"github.com/aws/aws-sdk-go-v2/aws"
dynamodbApi "github.com/aws/aws-sdk-go-v2/service/dynamodb"
dynamodbTypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"

"github.com/aquasecurity/trivy-aws/internal/adapters"
"github.com/aquasecurity/trivy-aws/pkg/concurrency"
)

type adapter struct {
*adapters.RootAdapter
*aws2.RootAdapter
client *dynamodbApi.Client
}

func init() {
adapters.RegisterServiceAdapter(&adapter{})
aws2.RegisterServiceAdapter(&adapter{})
}

func (a *adapter) Name() string {
Expand All @@ -29,7 +29,7 @@ func (a *adapter) Provider() string {
return "aws"
}

func (a *adapter) Adapt(root *adapters.RootAdapter, state *state.State) error {
func (a *adapter) Adapt(root *aws2.RootAdapter, state *state.State) error {
a.RootAdapter = root
a.client = dynamodbApi.NewFromConfig(root.SessionConfig())
var err error
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import (
"github.com/aquasecurity/defsec/pkg/providers/aws/ec2"
"github.com/aquasecurity/defsec/pkg/state"
defsecTypes "github.com/aquasecurity/defsec/pkg/types"
aws2 "github.com/aquasecurity/trivy-aws/internal/adapters/cloud/aws"
"github.com/aws/aws-sdk-go-v2/aws"
ec2api "github.com/aws/aws-sdk-go-v2/service/ec2"
ec2Types "github.com/aws/aws-sdk-go-v2/service/ec2/types"

"github.com/aquasecurity/trivy-aws/internal/adapters"
"github.com/aquasecurity/trivy-aws/pkg/concurrency"
)

type adapter struct {
*adapters.RootAdapter
*aws2.RootAdapter
client *ec2api.Client
}

func init() {
adapters.RegisterServiceAdapter(&adapter{})
aws2.RegisterServiceAdapter(&adapter{})
}

func (a *adapter) Provider() string {
Expand All @@ -33,7 +33,7 @@ func (a *adapter) Name() string {
return "ec2"
}

func (a *adapter) Adapt(root *adapters.RootAdapter, state *state.State) error {
func (a *adapter) Adapt(root *aws2.RootAdapter, state *state.State) error {

a.RootAdapter = root
a.client = ec2api.NewFromConfig(root.SessionConfig())
Expand Down
Loading

0 comments on commit f6180c0

Please sign in to comment.