Skip to content

Commit

Permalink
Merge pull request #324 from ekristen/rebuy-1023
Browse files Browse the repository at this point in the history
feat(resource): implements gamelift and pinpoint
  • Loading branch information
ekristen authored Sep 27, 2024
2 parents ffa18ec + ad4d880 commit f4c02e9
Show file tree
Hide file tree
Showing 11 changed files with 11,689 additions and 0 deletions.
6,229 changes: 6,229 additions & 0 deletions mocks/mock_gameliftiface/mock.go

Large diffs are not rendered by default.

4,830 changes: 4,830 additions & 0 deletions mocks/mock_pinpointsmsvoicev2iface/mock.go

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions resources/gamelift-build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package resources

import (
"context"
"time"

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

"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"
)

const GameLiftBuildResource = "GameLiftBuild"

func init() {
registry.Register(&registry.Registration{
Name: GameLiftBuildResource,
Scope: nuke.Account,
Lister: &GameLiftBuildLister{},
})
}

type GameLiftBuildLister struct{}

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

svc := gamelift.New(opts.Session)

params := &gamelift.ListBuildsInput{}

for {
resp, err := svc.ListBuilds(params)
if err != nil {
return nil, err
}

for _, build := range resp.Builds {
resources = append(resources, &GameLiftBuild{
svc: svc,
BuildID: build.BuildId,
Name: build.Name,
Status: build.Status,
Version: build.Version,
CreationDate: build.CreationTime,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

type GameLiftBuild struct {
svc *gamelift.GameLift
BuildID *string
Name *string
Status *string
Version *string
CreationDate *time.Time
}

func (r *GameLiftBuild) Remove(_ context.Context) error {
params := &gamelift.DeleteBuildInput{
BuildId: r.BuildID,
}

_, err := r.svc.DeleteBuild(params)
if err != nil {
return err
}

return nil
}

func (r *GameLiftBuild) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *GameLiftBuild) String() string {
return *r.BuildID
}
83 changes: 83 additions & 0 deletions resources/gamelift-fleet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package resources

import (
"context"

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

"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"
)

const GameLiftFleetResource = "GameLiftFleet"

func init() {
registry.Register(&registry.Registration{
Name: GameLiftFleetResource,
Scope: nuke.Account,
Lister: &GameLiftFleetLister{},
})
}

type GameLiftFleetLister struct{}

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

svc := gamelift.New(opts.Session)

params := &gamelift.ListFleetsInput{}

for {
resp, err := svc.ListFleets(params)
if err != nil {
return nil, err
}

for _, fleetID := range resp.FleetIds {
fleet := &GameLiftFleet{
svc: svc,
FleetID: fleetID,
}
resources = append(resources, fleet)
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

type GameLiftFleet struct {
svc *gamelift.GameLift
FleetID *string
}

func (r *GameLiftFleet) Remove(_ context.Context) error {
params := &gamelift.DeleteFleetInput{
FleetId: r.FleetID,
}

_, err := r.svc.DeleteFleet(params)
if err != nil {
return err
}

return nil
}

func (r *GameLiftFleet) String() string {
return *r.FleetID
}

func (r *GameLiftFleet) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}
86 changes: 86 additions & 0 deletions resources/gamelift-mm-config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package resources

import (
"context"
"time"

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

"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"
)

const GameLiftMatchmakingConfigurationResource = "GameLiftMatchmakingConfiguration"

func init() {
registry.Register(&registry.Registration{
Name: GameLiftMatchmakingConfigurationResource,
Scope: nuke.Account,
Lister: &GameLiftMatchmakingConfigurationLister{},
})
}

type GameLiftMatchmakingConfigurationLister struct{}

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

svc := gamelift.New(opts.Session)

params := &gamelift.DescribeMatchmakingConfigurationsInput{}

for {
resp, err := svc.DescribeMatchmakingConfigurations(params)
if err != nil {
return nil, err
}

for _, config := range resp.Configurations {
q := &GameLiftMatchmakingConfiguration{
svc: svc,
Name: config.Name,
CreationTime: config.CreationTime,
}
resources = append(resources, q)
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

type GameLiftMatchmakingConfiguration struct {
svc *gamelift.GameLift
Name *string
CreationTime *time.Time
}

func (r *GameLiftMatchmakingConfiguration) Remove(_ context.Context) error {
params := &gamelift.DeleteMatchmakingConfigurationInput{
Name: r.Name,
}

_, err := r.svc.DeleteMatchmakingConfiguration(params)
if err != nil {
return err
}

return nil
}

func (r *GameLiftMatchmakingConfiguration) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *GameLiftMatchmakingConfiguration) String() string {
return *r.Name
}
83 changes: 83 additions & 0 deletions resources/gamelift-mm-rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package resources

import (
"context"

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

"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"
)

const GameLiftMatchmakingRuleSetResource = "GameLiftMatchmakingRuleSet"

func init() {
registry.Register(&registry.Registration{
Name: GameLiftMatchmakingRuleSetResource,
Scope: nuke.Account,
Lister: &GameLiftMatchmakingRuleSetLister{},
})
}

type GameLiftMatchmakingRuleSetLister struct{}

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

svc := gamelift.New(opts.Session)

params := &gamelift.DescribeMatchmakingRuleSetsInput{}

for {
resp, err := svc.DescribeMatchmakingRuleSets(params)
if err != nil {
return nil, err
}

for _, ruleSet := range resp.RuleSets {
q := &GameLiftMatchmakingRuleSet{
svc: svc,
Name: ruleSet.RuleSetName,
}
resources = append(resources, q)
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

type GameLiftMatchmakingRuleSet struct {
svc *gamelift.GameLift
Name *string
}

func (r *GameLiftMatchmakingRuleSet) Remove(_ context.Context) error {
params := &gamelift.DeleteMatchmakingRuleSetInput{
Name: r.Name,
}

_, err := r.svc.DeleteMatchmakingRuleSet(params)
if err != nil {
return err
}

return nil
}

func (r *GameLiftMatchmakingRuleSet) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *GameLiftMatchmakingRuleSet) String() string {
return *r.Name
}
Loading

0 comments on commit f4c02e9

Please sign in to comment.