codedeploy

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CodeDeployCalls = []types.AWSService{
	{
		Name: "codedeploy:ListApplications",
		Call: func(ctx context.Context, sess *session.Session) (interface{}, error) {
			var allApps []cdApplication
			var lastErr error

			for _, region := range types.Regions {
				svc := codedeploy.New(sess, &aws.Config{Region: aws.String(region)})
				var allAppNames []*string
				var nextToken *string
				for {
					input := &codedeploy.ListApplicationsInput{}
					if nextToken != nil {
						input.NextToken = nextToken
					}
					output, err := svc.ListApplicationsWithContext(ctx, input)
					if err != nil {
						lastErr = err
						utils.HandleAWSError(false, "codedeploy:ListApplications", err)
						break
					}
					allAppNames = append(allAppNames, output.Applications...)
					if output.NextToken == nil {
						break
					}
					nextToken = output.NextToken
				}
				if len(allAppNames) > 0 {
					allApps = append(allApps, batchGetApplications(ctx, svc, allAppNames, region)...)
				}
			}

			if len(allApps) == 0 && lastErr != nil {
				return nil, lastErr
			}
			return allApps, nil
		},
		Process: func(output interface{}, err error, debug bool) []types.ScanResult {
			var results []types.ScanResult

			if err != nil {
				utils.HandleAWSError(debug, "codedeploy:ListApplications", err)
				return []types.ScanResult{
					{
						ServiceName: "CodeDeploy",
						MethodName:  "codedeploy:ListApplications",
						Error:       err,
						Timestamp:   time.Now(),
					},
				}
			}

			apps, ok := output.([]cdApplication)
			if !ok {
				utils.HandleAWSError(debug, "codedeploy:ListApplications", fmt.Errorf("unexpected output type %T", output))
				return results
			}

			for _, app := range apps {
				results = append(results, types.ScanResult{
					ServiceName:  "CodeDeploy",
					MethodName:   "codedeploy:ListApplications",
					ResourceType: "application",
					ResourceName: app.Name,
					Details: map[string]interface{}{
						"Name":            app.Name,
						"ApplicationId":   app.ApplicationId,
						"ComputePlatform": app.ComputePlatform,
						"CreateTime":      app.CreateTime,
						"LinkedToGitHub":  app.LinkedToGitHub,
						"Region":          app.Region,
					},
					Timestamp: time.Now(),
				})

				utils.PrintResult(debug, "", "codedeploy:ListApplications",
					fmt.Sprintf("CodeDeploy Application: %s (Platform: %s, Created: %s, Region: %s)", utils.ColorizeItem(app.Name), app.ComputePlatform, app.CreateTime, app.Region), nil)
			}
			return results
		},
		ModuleName: types.DefaultModuleName,
	},
	{
		Name: "codedeploy:ListDeploymentGroups",
		Call: func(ctx context.Context, sess *session.Session) (interface{}, error) {
			var allGroups []cdDeploymentGroup
			var lastErr error

			for _, region := range types.Regions {
				svc := codedeploy.New(sess, &aws.Config{Region: aws.String(region)})

				// Step 1: List all application names
				var appNames []*string
				var nextToken *string
				for {
					input := &codedeploy.ListApplicationsInput{}
					if nextToken != nil {
						input.NextToken = nextToken
					}
					output, err := svc.ListApplicationsWithContext(ctx, input)
					if err != nil {
						lastErr = err
						utils.HandleAWSError(false, "codedeploy:ListDeploymentGroups", err)
						break
					}
					appNames = append(appNames, output.Applications...)
					if output.NextToken == nil {
						break
					}
					nextToken = output.NextToken
				}

				for _, appNamePtr := range appNames {
					if appNamePtr == nil {
						continue
					}
					appName := *appNamePtr
					var groupNames []*string
					var dgNextToken *string
					for {
						dgInput := &codedeploy.ListDeploymentGroupsInput{
							ApplicationName: aws.String(appName),
						}
						if dgNextToken != nil {
							dgInput.NextToken = dgNextToken
						}
						dgOutput, err := svc.ListDeploymentGroupsWithContext(ctx, dgInput)
						if err != nil {
							utils.HandleAWSError(false, "codedeploy:ListDeploymentGroups", err)
							break
						}
						groupNames = append(groupNames, dgOutput.DeploymentGroups...)
						if dgOutput.NextToken == nil {
							break
						}
						dgNextToken = dgOutput.NextToken
					}
					if len(groupNames) > 0 {
						allGroups = append(allGroups, batchGetDeploymentGroups(ctx, svc, appName, groupNames, region)...)
					}
				}
			}

			if len(allGroups) == 0 && lastErr != nil {
				return nil, lastErr
			}
			return allGroups, nil
		},
		Process: func(output interface{}, err error, debug bool) []types.ScanResult {
			var results []types.ScanResult

			if err != nil {
				utils.HandleAWSError(debug, "codedeploy:ListDeploymentGroups", err)
				return []types.ScanResult{
					{
						ServiceName: "CodeDeploy",
						MethodName:  "codedeploy:ListDeploymentGroups",
						Error:       err,
						Timestamp:   time.Now(),
					},
				}
			}

			groups, ok := output.([]cdDeploymentGroup)
			if !ok {
				utils.HandleAWSError(debug, "codedeploy:ListDeploymentGroups", fmt.Errorf("unexpected output type %T", output))
				return results
			}

			for _, g := range groups {
				resourceName := g.GroupName
				if g.ApplicationName != "" {
					resourceName = g.ApplicationName + "/" + g.GroupName
				}

				results = append(results, types.ScanResult{
					ServiceName:  "CodeDeploy",
					MethodName:   "codedeploy:ListDeploymentGroups",
					ResourceType: "deployment-group",
					ResourceName: resourceName,
					Details: map[string]interface{}{
						"ApplicationName":      g.ApplicationName,
						"GroupName":            g.GroupName,
						"DeploymentGroupId":    g.DeploymentGroupId,
						"DeploymentConfigName": g.DeploymentConfigName,
						"ComputePlatform":      g.ComputePlatform,
						"ServiceRoleArn":       g.ServiceRoleArn,
						"Region":               g.Region,
					},
					Timestamp: time.Now(),
				})

				utils.PrintResult(debug, "", "codedeploy:ListDeploymentGroups",
					fmt.Sprintf("CodeDeploy Deployment Group: %s (App: %s, Config: %s, Role: %s, Region: %s)", utils.ColorizeItem(g.GroupName), g.ApplicationName, g.DeploymentConfigName, g.ServiceRoleArn, g.Region), nil)
			}
			return results
		},
		ModuleName: types.DefaultModuleName,
	},
	{
		Name: "codedeploy:ListDeploymentConfigs",
		Call: func(ctx context.Context, sess *session.Session) (interface{}, error) {
			var allConfigs []cdDeploymentConfig
			var lastErr error

			for _, region := range types.Regions {
				svc := codedeploy.New(sess, &aws.Config{Region: aws.String(region)})
				var configNames []*string
				var nextToken *string
				for {
					input := &codedeploy.ListDeploymentConfigsInput{}
					if nextToken != nil {
						input.NextToken = nextToken
					}
					output, err := svc.ListDeploymentConfigsWithContext(ctx, input)
					if err != nil {
						lastErr = err
						utils.HandleAWSError(false, "codedeploy:ListDeploymentConfigs", err)
						break
					}
					configNames = append(configNames, output.DeploymentConfigsList...)
					if output.NextToken == nil {
						break
					}
					nextToken = output.NextToken
				}

				for _, namePtr := range configNames {
					if namePtr == nil {
						continue
					}
					configName := *namePtr
					output, err := svc.GetDeploymentConfigWithContext(ctx, &codedeploy.GetDeploymentConfigInput{
						DeploymentConfigName: aws.String(configName),
					})
					if err != nil {
						utils.HandleAWSError(false, "codedeploy:ListDeploymentConfigs", err)
						continue
					}
					if output.DeploymentConfigInfo != nil {
						allConfigs = append(allConfigs, extractDeploymentConfig(output.DeploymentConfigInfo, region))
					}
				}
			}

			if len(allConfigs) == 0 && lastErr != nil {
				return nil, lastErr
			}
			return allConfigs, nil
		},
		Process: func(output interface{}, err error, debug bool) []types.ScanResult {
			var results []types.ScanResult

			if err != nil {
				utils.HandleAWSError(debug, "codedeploy:ListDeploymentConfigs", err)
				return []types.ScanResult{
					{
						ServiceName: "CodeDeploy",
						MethodName:  "codedeploy:ListDeploymentConfigs",
						Error:       err,
						Timestamp:   time.Now(),
					},
				}
			}

			configs, ok := output.([]cdDeploymentConfig)
			if !ok {
				utils.HandleAWSError(debug, "codedeploy:ListDeploymentConfigs", fmt.Errorf("unexpected output type %T", output))
				return results
			}

			for _, c := range configs {
				results = append(results, types.ScanResult{
					ServiceName:  "CodeDeploy",
					MethodName:   "codedeploy:ListDeploymentConfigs",
					ResourceType: "deployment-config",
					ResourceName: c.Name,
					Details: map[string]interface{}{
						"Name":               c.Name,
						"DeploymentConfigId": c.DeploymentConfigId,
						"ComputePlatform":    c.ComputePlatform,
						"CreateTime":         c.CreateTime,
						"Region":             c.Region,
					},
					Timestamp: time.Now(),
				})

				utils.PrintResult(debug, "", "codedeploy:ListDeploymentConfigs",
					fmt.Sprintf("CodeDeploy Deployment Config: %s (Platform: %s, Created: %s, Region: %s)", utils.ColorizeItem(c.Name), c.ComputePlatform, c.CreateTime, c.Region), nil)
			}
			return results
		},
		ModuleName: types.DefaultModuleName,
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL