Skip to content

Commit

Permalink
feat(aws): AWS ServiceCatalog (#3275)
Browse files Browse the repository at this point in the history
Implements #1410
  • Loading branch information
disq committed Oct 30, 2022
1 parent 97ef6cf commit d6f955c
Show file tree
Hide file tree
Showing 23 changed files with 867 additions and 12 deletions.
10 changes: 7 additions & 3 deletions plugins/source/aws/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generate mocks for mock/unit testing
.PHONY: generate-mocks
generate-mocks:
go generate ./client/services/...
.PHONY: gen-mocks
gen-mocks:
go generate ./client/...

# Test unit
.PHONY: test
Expand Down Expand Up @@ -31,3 +31,7 @@ lint:
.PHONY: gen-code
gen-code:
go run codegen/main.go

# All gen targets
.PHONY: gen
gen: gen-mocks gen-code gen-docs
8 changes: 7 additions & 1 deletion plugins/source/aws/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/docdb"
"strings"
"time"

Expand Down Expand Up @@ -38,6 +37,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/databasemigrationservice"
"github.com/aws/aws-sdk-go-v2/service/dax"
"github.com/aws/aws-sdk-go-v2/service/directconnect"
"github.com/aws/aws-sdk-go-v2/service/docdb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
Expand Down Expand Up @@ -79,6 +79,8 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3control"
"github.com/aws/aws-sdk-go-v2/service/sagemaker"
"github.com/aws/aws-sdk-go-v2/service/secretsmanager"
"github.com/aws/aws-sdk-go-v2/service/servicecatalog"
"github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry"
"github.com/aws/aws-sdk-go-v2/service/sesv2"
"github.com/aws/aws-sdk-go-v2/service/shield"
"github.com/aws/aws-sdk-go-v2/service/sns"
Expand Down Expand Up @@ -198,6 +200,8 @@ type Services struct {
S3Manager S3ManagerClient
SageMaker SageMakerClient
SecretsManager SecretsManagerClient
ServiceCatalog ServiceCatalogClient
ServiceCatalogAR ServiceCatalogAppRegistryClient
SES SESClient
Shield ShieldClient
SNS SnsClient
Expand Down Expand Up @@ -678,6 +682,8 @@ func initServices(region string, c aws.Config) Services {
S3Manager: newS3ManagerFromConfig(awsCfg),
SageMaker: sagemaker.NewFromConfig(awsCfg),
SecretsManager: secretsmanager.NewFromConfig(awsCfg),
ServiceCatalog: servicecatalog.NewFromConfig(awsCfg),
ServiceCatalogAR: servicecatalogappregistry.NewFromConfig(awsCfg),
SES: sesv2.NewFromConfig(awsCfg),
Shield: shield.NewFromConfig(awsCfg),
SNS: sns.NewFromConfig(awsCfg),
Expand Down
96 changes: 96 additions & 0 deletions plugins/source/aws/client/mocks/mock_service_catalog.go

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

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

14 changes: 14 additions & 0 deletions plugins/source/aws/client/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3control"
"github.com/aws/aws-sdk-go-v2/service/sagemaker"
"github.com/aws/aws-sdk-go-v2/service/secretsmanager"
"github.com/aws/aws-sdk-go-v2/service/servicecatalog"
"github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry"
"github.com/aws/aws-sdk-go-v2/service/sesv2"
"github.com/aws/aws-sdk-go-v2/service/shield"
"github.com/aws/aws-sdk-go-v2/service/sns"
Expand Down Expand Up @@ -837,6 +839,18 @@ type SecretsManagerClient interface {
ListSecrets(ctx context.Context, params *secretsmanager.ListSecretsInput, optFns ...func(*secretsmanager.Options)) (*secretsmanager.ListSecretsOutput, error)
}

//go:generate mockgen -package=mocks -destination=./mocks/mock_service_catalog.go . ServiceCatalogClient
type ServiceCatalogClient interface {
ListPortfolios(ctx context.Context, input *servicecatalog.ListPortfoliosInput, optFns ...func(*servicecatalog.Options)) (*servicecatalog.ListPortfoliosOutput, error)
SearchProductsAsAdmin(ctx context.Context, params *servicecatalog.SearchProductsAsAdminInput, optFns ...func(*servicecatalog.Options)) (*servicecatalog.SearchProductsAsAdminOutput, error)
SearchProvisionedProducts(ctx context.Context, params *servicecatalog.SearchProvisionedProductsInput, optFns ...func(*servicecatalog.Options)) (*servicecatalog.SearchProvisionedProductsOutput, error)
}

//go:generate mockgen -package=mocks -destination=./mocks/mock_service_catalog_app_registry.go . ServiceCatalogAppRegistryClient
type ServiceCatalogAppRegistryClient interface {
ListTagsForResource(ctx context.Context, params *servicecatalogappregistry.ListTagsForResourceInput, optFns ...func(*servicecatalogappregistry.Options)) (*servicecatalogappregistry.ListTagsForResourceOutput, error)
}

//go:generate mockgen -package=mocks -destination=./mocks/ses.go . SESClient
type SESClient interface {
GetEmailTemplate(ctx context.Context, params *sesv2.GetEmailTemplateInput, optFns ...func(*sesv2.Options)) (*sesv2.GetEmailTemplateOutput, error)
Expand Down
1 change: 1 addition & 0 deletions plugins/source/aws/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func main() {
resources = append(resources, recipes.S3Resources()...)
resources = append(resources, recipes.SagemakerResources()...)
resources = append(resources, recipes.SecretsManagerResources()...)
resources = append(resources, recipes.ServiceCatalogResources()...)
resources = append(resources, recipes.SESResources()...)
resources = append(resources, recipes.ShieldResources()...)
resources = append(resources, recipes.SNSResources()...)
Expand Down
81 changes: 81 additions & 0 deletions plugins/source/aws/codegen/recipes/servicecatalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package recipes

import (
"github.com/aws/aws-sdk-go-v2/service/servicecatalog/types"
"github.com/cloudquery/plugin-sdk/codegen"
"github.com/cloudquery/plugin-sdk/schema"
)

func ServiceCatalogResources() []*Resource {
resources := []*Resource{
{
SubService: "portfolios",
Struct: &types.PortfolioDetail{},
Description: "https://docs.aws.amazon.com/servicecatalog/latest/dg/API_PortfolioDetail.html",
SkipFields: []string{"ARN"},
ExtraColumns: append(
defaultAccountColumns,
[]codegen.ColumnDefinition{
{
Name: "arn",
Type: schema.TypeString,
Resolver: `schema.PathResolver("ARN")`,
Options: schema.ColumnCreationOptions{PrimaryKey: true},
},
{
Name: "tags",
Type: schema.TypeJSON,
Resolver: `resolvePortfolioTags`,
},
}...),
},
{
SubService: "products",
Struct: &types.ProductViewDetail{},
Description: "https://docs.aws.amazon.com/servicecatalog/latest/dg/API_ProductViewDetail.html",
SkipFields: []string{"ProductARN"},
ExtraColumns: append(
defaultAccountColumns,
[]codegen.ColumnDefinition{
{
Name: "arn",
Type: schema.TypeString,
Resolver: `schema.PathResolver("ProductARN")`,
Options: schema.ColumnCreationOptions{PrimaryKey: true},
},
{
Name: "tags",
Type: schema.TypeJSON,
Resolver: `resolveProductTags`,
},
}...),
}, {
SubService: "provisioned_products",
Struct: &types.ProvisionedProductAttribute{},
Description: "https://docs.aws.amazon.com/servicecatalog/latest/dg/API_ProvisionedProductAttribute.html",
SkipFields: []string{"Arn", "Tags"},
ExtraColumns: append(
defaultAccountColumns,
[]codegen.ColumnDefinition{
{
Name: "arn",
Type: schema.TypeString,
Resolver: `schema.PathResolver("Arn")`,
Options: schema.ColumnCreationOptions{PrimaryKey: true},
},
{
Name: "tags",
Type: schema.TypeJSON,
Resolver: `resolveProvisionedProductTags`,
},
}...),
},
}

// set default values
for _, r := range resources {
r.Service = "servicecatalog"
r.Multiplex = `client.ServiceAccountRegionMultiplexer("servicecatalog")`
}
return resources
}
3 changes: 3 additions & 0 deletions plugins/source/aws/docs/tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@
| [aws_sagemaker_notebook_instances](aws_sagemaker_notebook_instances.md) |
| [aws_sagemaker_training_jobs](aws_sagemaker_training_jobs.md) |
| [aws_secretsmanager_secrets](aws_secretsmanager_secrets.md) |
| [aws_servicecatalog_portfolios](aws_servicecatalog_portfolios.md) |
| [aws_servicecatalog_products](aws_servicecatalog_products.md) |
| [aws_servicecatalog_provisioned_products](aws_servicecatalog_provisioned_products.md) |
| [aws_ses_templates](aws_ses_templates.md) |
| [aws_shield_attacks](aws_shield_attacks.md) |
| [aws_shield_protection_groups](aws_shield_protection_groups.md) |
Expand Down
22 changes: 22 additions & 0 deletions plugins/source/aws/docs/tables/aws_servicecatalog_portfolios.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Table: aws_servicecatalog_portfolios

https://docs.aws.amazon.com/servicecatalog/latest/dg/API_PortfolioDetail.html

The primary key for this table is **arn**.


## Columns
| Name | Type |
| ------------- | ------------- |
|_cq_source_name|String|
|_cq_sync_time|Timestamp|
|_cq_id|UUID|
|_cq_parent_id|UUID|
|account_id|String|
|arn (PK)|String|
|tags|JSON|
|created_time|Timestamp|
|description|String|
|display_name|String|
|id|String|
|provider_name|String|
20 changes: 20 additions & 0 deletions plugins/source/aws/docs/tables/aws_servicecatalog_products.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Table: aws_servicecatalog_products

https://docs.aws.amazon.com/servicecatalog/latest/dg/API_ProductViewDetail.html

The primary key for this table is **arn**.


## Columns
| Name | Type |
| ------------- | ------------- |
|_cq_source_name|String|
|_cq_sync_time|Timestamp|
|_cq_id|UUID|
|_cq_parent_id|UUID|
|account_id|String|
|arn (PK)|String|
|tags|JSON|
|created_time|Timestamp|
|product_view_summary|JSON|
|status|String|

0 comments on commit d6f955c

Please sign in to comment.