Skip to content

Commit

Permalink
Merge pull request #449 from ekristen/fix-iottwinmaker
Browse files Browse the repository at this point in the history
fix(iot-twin-maker): limit to the supported regions
  • Loading branch information
ekristen authored Dec 9, 2024
2 parents 2018a5c + 7c24146 commit 5546c46
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 10 deletions.
10 changes: 8 additions & 2 deletions resources/iottwinmaker-component-type.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ func init() {
})
}

type IoTTwinMakerComponentTypeLister struct{}
type IoTTwinMakerComponentTypeLister struct {
IoTTwinMaker
}

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

if !l.IsSupportedRegion(opts.Region.Name) {
return resources, nil
}

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

// Require to have workspaces identifiers to query components
workspaceListResponse, err := ListWorkspacesComponentType(svc)
Expand Down
10 changes: 8 additions & 2 deletions resources/iottwinmaker-entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ func init() {
})
}

type IoTTwinMakerEntityLister struct{}
type IoTTwinMakerEntityLister struct {
IoTTwinMaker
}

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

if !l.IsSupportedRegion(opts.Region.Name) {
return resources, nil
}

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

// Require to have workspaces identifiers to query entities
workspaceListResponse, err := ListWorkspacesEntities(svc)
Expand Down
10 changes: 8 additions & 2 deletions resources/iottwinmaker-scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ func init() {
})
}

type IoTTwinMakerSceneLister struct{}
type IoTTwinMakerSceneLister struct {
IoTTwinMaker
}

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

if !l.IsSupportedRegion(opts.Region.Name) {
return resources, nil
}

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

// Require to have workspaces identifiers to query scenes
workspaceListResponse, err := ListWorkspacesScene(svc)
Expand Down
10 changes: 8 additions & 2 deletions resources/iottwinmaker-sync-job.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ func init() {
})
}

type IoTTwinMakerSyncJobLister struct{}
type IoTTwinMakerSyncJobLister struct {
IoTTwinMaker
}

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

if !l.IsSupportedRegion(opts.Region.Name) {
return resources, nil
}

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

// Require to have workspaces identifiers to query sync jobs
workspaceListResponse, err := ListWorkspacesSyncJob(svc)
Expand Down
10 changes: 8 additions & 2 deletions resources/iottwinmaker-workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ func init() {
})
}

type IoTTwinMakerWorkspaceLister struct{}
type IoTTwinMakerWorkspaceLister struct {
IoTTwinMaker
}

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

if !l.IsSupportedRegion(opts.Region.Name) {
return resources, nil
}

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

params := &iottwinmaker.ListWorkspacesInput{
MaxResults: aws.Int64(25),
Expand Down
23 changes: 23 additions & 0 deletions resources/iottwinmaker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package resources

import "slices"

type IoTTwinMaker struct{}

func (i *IoTTwinMaker) IsSupportedRegion(region string) bool {
// ref: https://docs.aws.amazon.com/general/latest/gr/iot-twinmaker.html
supportedRegions := []string{
"us-east-1",
"us-west-2",
"ap-south-1",
"ap-northeast-2",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"eu-central-1",
"eu-west-1",
"us-gov-west-1",
}

return slices.Contains(supportedRegions, region)
}

0 comments on commit 5546c46

Please sign in to comment.