Skip to content

Commit

Permalink
Merge pull request #296 from MSchouwPablo/cognito-pipes-tags
Browse files Browse the repository at this point in the history
feat(resource): enable support for tags in cognito userpools & pipes
  • Loading branch information
ekristen authored Sep 13, 2024
2 parents 8c6b514 + d3baf7d commit 90d6dcf
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
6 changes: 3 additions & 3 deletions resources/cognito-identity-providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (l *CognitoIdentityProviderLister) List(ctx context.Context, o interface{})
}

listParams := &cognitoidentityprovider.ListIdentityProvidersInput{
UserPoolId: userPool.id,
UserPoolId: userPool.ID,
MaxResults: aws.Int64(50),
}

Expand All @@ -66,8 +66,8 @@ func (l *CognitoIdentityProviderLister) List(ctx context.Context, o interface{})
svc: svc,
name: provider.ProviderName,
providerType: provider.ProviderType,
userPoolName: userPool.name,
userPoolID: userPool.id,
userPoolName: userPool.Name,
userPoolID: userPool.ID,
})
}

Expand Down
6 changes: 3 additions & 3 deletions resources/cognito-userpool-clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (l *CognitoUserPoolClientLister) List(ctx context.Context, o interface{}) (
}

listParams := &cognitoidentityprovider.ListUserPoolClientsInput{
UserPoolId: userPool.id,
UserPoolId: userPool.ID,
MaxResults: aws.Int64(50),
}

Expand All @@ -64,8 +64,8 @@ func (l *CognitoUserPoolClientLister) List(ctx context.Context, o interface{}) (
svc: svc,
id: client.ClientId,
name: client.ClientName,
userPoolName: userPool.name,
userPoolID: userPool.id,
userPoolName: userPool.Name,
userPoolID: userPool.ID,
})
}

Expand Down
6 changes: 3 additions & 3 deletions resources/cognito-userpool-domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (l *CognitoUserPoolDomainLister) List(ctx context.Context, o interface{}) (
}

describeParams := &cognitoidentityprovider.DescribeUserPoolInput{
UserPoolId: userPool.id,
UserPoolId: userPool.ID,
}
userPoolDetails, err := svc.DescribeUserPool(describeParams)
if err != nil {
Expand All @@ -60,8 +60,8 @@ func (l *CognitoUserPoolDomainLister) List(ctx context.Context, o interface{}) (
resources = append(resources, &CognitoUserPoolDomain{
svc: svc,
name: userPoolDetails.UserPool.Domain,
userPoolName: userPool.name,
userPoolID: userPool.id,
userPoolName: userPool.Name,
userPoolID: userPool.ID,
})
}

Expand Down
50 changes: 43 additions & 7 deletions resources/cognito-userpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ package resources

import (
"context"
"fmt"

"github.com/gotidy/ptr"
"github.com/sirupsen/logrus"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/aws/aws-sdk-go/service/sts/stsiface"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)
Expand All @@ -27,14 +34,29 @@ func init() {
})
}

type CognitoUserPoolLister struct{}
type CognitoUserPoolLister struct {
stsService stsiface.STSAPI
}

func (l *CognitoUserPoolLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

var stsSvc stsiface.STSAPI
if l.stsService != nil {
stsSvc = l.stsService
} else {
stsSvc = sts.New(opts.Session)
}

svc := cognitoidentityprovider.New(opts.Session)
resources := make([]resource.Resource, 0)

identityOutput, err := stsSvc.GetCallerIdentity(nil)
if err != nil {
return nil, err
}
accountID := identityOutput.Account

params := &cognitoidentityprovider.ListUserPoolsInput{
MaxResults: aws.Int64(50),
}
Expand All @@ -46,10 +68,19 @@ func (l *CognitoUserPoolLister) List(_ context.Context, o interface{}) ([]resour
}

for _, pool := range output.UserPools {
tagResp, tagsErr := svc.ListTagsForResource(&cognitoidentityprovider.ListTagsForResourceInput{
ResourceArn: ptr.String(fmt.Sprintf("arn:aws:cognito-idp:%s:%s:userpool/%s", opts.Region.Name, *accountID, *pool.Id)),
})

if tagsErr != nil {
logrus.WithError(tagsErr).Error("unable to get tags for userpool")
}

resources = append(resources, &CognitoUserPool{
svc: svc,
name: pool.Name,
id: pool.Id,
Name: pool.Name,
ID: pool.Id,
Tags: tagResp.Tags,
})
}

Expand All @@ -65,18 +96,23 @@ func (l *CognitoUserPoolLister) List(_ context.Context, o interface{}) ([]resour

type CognitoUserPool struct {
svc *cognitoidentityprovider.CognitoIdentityProvider
name *string
id *string
Name *string
ID *string
Tags map[string]*string
}

func (f *CognitoUserPool) Remove(_ context.Context) error {
_, err := f.svc.DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{
UserPoolId: f.id,
UserPoolId: f.ID,
})

return err
}

func (f *CognitoUserPool) Properties() types.Properties {
return types.NewPropertiesFromStruct(f)
}

func (f *CognitoUserPool) String() string {
return *f.name
return *f.Name
}
12 changes: 12 additions & 0 deletions resources/pipes-pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"time"

"github.com/sirupsen/logrus"

"github.com/aws/aws-sdk-go/service/pipes"

"github.com/ekristen/libnuke/pkg/registry"
Expand Down Expand Up @@ -36,6 +38,14 @@ func (l *PipesPipeLister) List(_ context.Context, o interface{}) ([]resource.Res
}

for _, p := range res.Pipes {
tagResp, tagsErr := svc.ListTagsForResource(&pipes.ListTagsForResourceInput{
ResourceArn: p.Arn,
})

if tagsErr != nil {
logrus.WithError(tagsErr).Error("unable to get tags for pipe")
}

resources = append(resources, &PipesPipes{
svc: svc,
Name: p.Name,
Expand All @@ -44,6 +54,7 @@ func (l *PipesPipeLister) List(_ context.Context, o interface{}) ([]resource.Res
Target: p.Target,
CreationDate: p.CreationTime,
ModifiedDate: p.LastModifiedTime,
Tags: tagResp.Tags,
})
}

Expand All @@ -58,6 +69,7 @@ type PipesPipes struct {
Target *string
CreationDate *time.Time
ModifiedDate *time.Time
Tags map[string]*string
}

func (r *PipesPipes) Remove(_ context.Context) error {
Expand Down

0 comments on commit 90d6dcf

Please sign in to comment.