Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions aws/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"aws_codebuild_report_group": tableAwsCodeBuildReportGroup(ctx),
"aws_codebuild_source_credential": tableAwsCodeBuildSourceCredential(ctx),
"aws_codecommit_repository": tableAwsCodeCommitRepository(ctx),
"aws_codeconnections_connection": tableAwsCodeConnectionsConnection(ctx),
"aws_codeconnections_host": tableAwsCodeConnectionsHost(ctx),
"aws_codeconnections_repository_link": tableAwsCodeConnectionsRepositoryLink(ctx),
"aws_codeconnections_sync_configuration": tableAwsCodeConnectionsSyncConfiguration(ctx),
"aws_codedeploy_app": tableAwsCodeDeployApplication(ctx),
"aws_codedeploy_deployment_config": tableAwsCodeDeployDeploymentConfig(ctx),
"aws_codedeploy_deployment_group": tableAwsCodeDeployDeploymentGroup(ctx),
Expand Down
13 changes: 13 additions & 0 deletions aws/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/codeartifact"
"github.com/aws/aws-sdk-go-v2/service/codebuild"
"github.com/aws/aws-sdk-go-v2/service/codecommit"
"github.com/aws/aws-sdk-go-v2/service/codeconnections"
"github.com/aws/aws-sdk-go-v2/service/codedeploy"
"github.com/aws/aws-sdk-go-v2/service/codepipeline"
"github.com/aws/aws-sdk-go-v2/service/codestarnotifications"
Expand Down Expand Up @@ -493,6 +494,18 @@ func CodeBuildClient(ctx context.Context, d *plugin.QueryData) (*codebuild.Clien
return codebuild.NewFromConfig(*cfg), nil
}

// CodeConnectionsClient returns the service client for AWS CodeConnections.
func CodeConnectionsClient(ctx context.Context, d *plugin.QueryData) (*codeconnections.Client, error) {
cfg, err := getClientForQuerySupportedRegion(ctx, d, AWS_CODESTAR_CONNECTIONS_SERVICE_ID)
if err != nil {
return nil, err
}
if cfg == nil {
return nil, nil
}
return codeconnections.NewFromConfig(*cfg), nil
}

func CodeDeployClient(ctx context.Context, d *plugin.QueryData) (*codedeploy.Client, error) {
cfg, err := getClientForQueryRegion(ctx, d)
if err != nil {
Expand Down
131 changes: 131 additions & 0 deletions aws/table_aws_codeconnections_connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package aws

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/codeconnections"
"github.com/aws/aws-sdk-go-v2/service/codeconnections/types"

"github.com/turbot/steampipe-plugin-sdk/v6/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v6/plugin"
"github.com/turbot/steampipe-plugin-sdk/v6/plugin/transform"
"github.com/turbot/steampipe-plugin-sdk/v6/query_cache"
)

func tableAwsCodeConnectionsConnection(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_codeconnections_connection",
Description: "AWS CodeConnections Connection",
Get: &plugin.GetConfig{
KeyColumns: plugin.SingleColumn("arn"),
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ResourceNotFoundException"}),
},
Hydrate: getCodeConnectionsConnection,
Tags: map[string]string{"service": "codeconnections", "action": "GetConnection"},
},
List: &plugin.ListConfig{
Hydrate: listCodeConnectionsConnections,
KeyColumns: plugin.KeyColumnSlice{
{Name: "provider_type", Require: plugin.Optional, CacheMatch: query_cache.CacheMatchExact},
{Name: "host_arn", Require: plugin.Optional, CacheMatch: query_cache.CacheMatchExact},
},
Tags: map[string]string{"service": "codeconnections", "action": "ListConnections"},
},
HydrateConfig: []plugin.HydrateConfig{
{
Func: listCodeConnectionsConnectionTags,
Tags: map[string]string{"service": "codeconnections", "action": "ListTagsForResource"},
},
},
GetMatrixItemFunc: SupportedRegionMatrix(AWS_CODESTAR_CONNECTIONS_SERVICE_ID),
Columns: awsRegionalColumns([]*plugin.Column{
{Name: "arn", Description: "The Amazon Resource Name (ARN) of the connection.", Type: proto.ColumnType_STRING, Transform: transform.FromField("ConnectionArn")},
{Name: "name", Description: "The name of the connection.", Type: proto.ColumnType_STRING, Transform: transform.FromField("ConnectionName")},
{Name: "provider_type", Description: "The external provider where the third-party code repository is configured.", Type: proto.ColumnType_STRING},
{Name: "owner_account_id", Description: "The identifier of the external provider account that owns the repository.", Type: proto.ColumnType_STRING},
{Name: "connection_status", Description: "The current status of the connection.", Type: proto.ColumnType_STRING},
{Name: "host_arn", Description: "The ARN of the host associated with the connection.", Type: proto.ColumnType_STRING},
{Name: "tags_src", Description: "A list of tags associated with the connection.", Type: proto.ColumnType_JSON, Hydrate: listCodeConnectionsConnectionTags, Transform: transform.FromField("Tags")},
{Name: "title", Description: resourceInterfaceDescription("title"), Type: proto.ColumnType_STRING, Transform: transform.FromField("ConnectionName")},
{Name: "tags", Description: resourceInterfaceDescription("tags"), Type: proto.ColumnType_JSON, Hydrate: listCodeConnectionsConnectionTags, Transform: transform.From(codeConnectionsTurbotTags)},
{Name: "akas", Description: resourceInterfaceDescription("akas"), Type: proto.ColumnType_JSON, Transform: transform.FromField("ConnectionArn").Transform(transform.EnsureStringArray)},
}),
}
}

func listCodeConnectionsConnections(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
svc, err := CodeConnectionsClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_codeconnections_connection.listCodeConnectionsConnections", "connection_error", err)
return nil, err
}
if svc == nil {
return nil, nil
}

maxLimit := int32(100)
if d.QueryContext.Limit != nil && int32(*d.QueryContext.Limit) < maxLimit {
maxLimit = int32(*d.QueryContext.Limit)
}
input := &codeconnections.ListConnectionsInput{MaxResults: maxLimit}
if providerType := d.EqualsQualString("provider_type"); providerType != "" {
input.ProviderTypeFilter = types.ProviderType(providerType)
}
if hostArn := d.EqualsQualString("host_arn"); hostArn != "" {
input.HostArnFilter = aws.String(hostArn)
}

paginator := codeconnections.NewListConnectionsPaginator(svc, input, func(o *codeconnections.ListConnectionsPaginatorOptions) {
o.Limit = maxLimit
o.StopOnDuplicateToken = true
})
for paginator.HasMorePages() {
d.WaitForListRateLimit(ctx)
output, err := paginator.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("aws_codeconnections_connection.listCodeConnectionsConnections", "api_error", err)
return nil, err
}
for _, connection := range output.Connections {
d.StreamListItem(ctx, connection)
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}
return nil, nil
}

func getCodeConnectionsConnection(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
arn := d.EqualsQualString("arn")
if arn == "" {
return nil, nil
}
svc, err := CodeConnectionsClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_codeconnections_connection.getCodeConnectionsConnection", "connection_error", err)
return nil, err
}
if svc == nil {
return nil, nil
}
output, err := svc.GetConnection(ctx, &codeconnections.GetConnectionInput{ConnectionArn: aws.String(arn)})
if err != nil {
plugin.Logger(ctx).Error("aws_codeconnections_connection.getCodeConnectionsConnection", "api_error", err)
return nil, err
}
return output.Connection, nil
}

func listCodeConnectionsConnectionTags(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
var arn *string
switch item := h.Item.(type) {
case types.Connection:
arn = item.ConnectionArn
case *types.Connection:
arn = item.ConnectionArn
}
return listCodeConnectionsTags(ctx, d, arn)
}
126 changes: 126 additions & 0 deletions aws/table_aws_codeconnections_host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package aws

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/codeconnections"
"github.com/aws/aws-sdk-go-v2/service/codeconnections/types"

"github.com/turbot/steampipe-plugin-sdk/v6/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v6/plugin"
"github.com/turbot/steampipe-plugin-sdk/v6/plugin/transform"
)

func tableAwsCodeConnectionsHost(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_codeconnections_host",
Description: "AWS CodeConnections Host",
Get: &plugin.GetConfig{
KeyColumns: plugin.SingleColumn("arn"),
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ResourceNotFoundException"}),
},
Hydrate: getCodeConnectionsHost,
Tags: map[string]string{"service": "codeconnections", "action": "GetHost"},
},
List: &plugin.ListConfig{
Hydrate: listCodeConnectionsHosts,
Tags: map[string]string{"service": "codeconnections", "action": "ListHosts"},
},
HydrateConfig: []plugin.HydrateConfig{
{
Func: listCodeConnectionsHostTags,
Tags: map[string]string{"service": "codeconnections", "action": "ListTagsForResource"},
},
},
GetMatrixItemFunc: SupportedRegionMatrix(AWS_CODESTAR_CONNECTIONS_SERVICE_ID),
Columns: awsRegionalColumns([]*plugin.Column{
{Name: "arn", Description: "The Amazon Resource Name (ARN) of the host.", Type: proto.ColumnType_STRING, Transform: transform.FromField("HostArn")},
{Name: "name", Description: "The name of the host.", Type: proto.ColumnType_STRING},
{Name: "provider_type", Description: "The installed provider associated with the host.", Type: proto.ColumnType_STRING},
{Name: "provider_endpoint", Description: "The endpoint of the infrastructure where the provider is installed.", Type: proto.ColumnType_STRING},
{Name: "status", Description: "The current status of the host.", Type: proto.ColumnType_STRING},
{Name: "status_message", Description: "The status description for the host.", Type: proto.ColumnType_STRING},
{Name: "vpc_configuration", Description: "The VPC configuration provisioned for the host.", Type: proto.ColumnType_JSON},
{Name: "tags_src", Description: "A list of tags associated with the host.", Type: proto.ColumnType_JSON, Hydrate: listCodeConnectionsHostTags, Transform: transform.FromField("Tags")},
{Name: "title", Description: resourceInterfaceDescription("title"), Type: proto.ColumnType_STRING, Transform: transform.FromField("Name")},
{Name: "tags", Description: resourceInterfaceDescription("tags"), Type: proto.ColumnType_JSON, Hydrate: listCodeConnectionsHostTags, Transform: transform.From(codeConnectionsTurbotTags)},
{Name: "akas", Description: resourceInterfaceDescription("akas"), Type: proto.ColumnType_JSON, Transform: transform.FromField("HostArn").Transform(transform.EnsureStringArray)},
}),
}
}

func listCodeConnectionsHosts(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
svc, err := CodeConnectionsClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_codeconnections_host.listCodeConnectionsHosts", "connection_error", err)
return nil, err
}
if svc == nil {
return nil, nil
}
maxLimit := int32(100)
if d.QueryContext.Limit != nil && int32(*d.QueryContext.Limit) < maxLimit {
maxLimit = int32(*d.QueryContext.Limit)
}
input := &codeconnections.ListHostsInput{MaxResults: maxLimit}
paginator := codeconnections.NewListHostsPaginator(svc, input, func(o *codeconnections.ListHostsPaginatorOptions) {
o.Limit = maxLimit
o.StopOnDuplicateToken = true
})
for paginator.HasMorePages() {
d.WaitForListRateLimit(ctx)
output, err := paginator.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("aws_codeconnections_host.listCodeConnectionsHosts", "api_error", err)
return nil, err
}
for _, host := range output.Hosts {
d.StreamListItem(ctx, host)
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}
return nil, nil
}

func getCodeConnectionsHost(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
arn := d.EqualsQualString("arn")
if arn == "" {
return nil, nil
}
svc, err := CodeConnectionsClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_codeconnections_host.getCodeConnectionsHost", "connection_error", err)
return nil, err
}
if svc == nil {
return nil, nil
}
output, err := svc.GetHost(ctx, &codeconnections.GetHostInput{HostArn: aws.String(arn)})
if err != nil {
plugin.Logger(ctx).Error("aws_codeconnections_host.getCodeConnectionsHost", "api_error", err)
return nil, err
}
return &types.Host{
HostArn: aws.String(arn),
Name: output.Name,
ProviderEndpoint: output.ProviderEndpoint,
ProviderType: output.ProviderType,
Status: output.Status,
VpcConfiguration: output.VpcConfiguration,
}, nil
}

func listCodeConnectionsHostTags(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
var arn *string
switch item := h.Item.(type) {
case types.Host:
arn = item.HostArn
case *types.Host:
arn = item.HostArn
}
return listCodeConnectionsTags(ctx, d, arn)
}
Loading