in ecs-cli/modules/cli/regcreds/regcreds_app.go [42:134]
func Up(c *cli.Context) {
args := c.Args()
if len(args) != 1 {
log.Fatal("Exactly 1 credential file is required. Found: ", len(args))
}
// create clients
commandConfig := getNewCommandConfig(c)
smClient := secretsClient.NewSecretsManagerClient(commandConfig)
kmsClient := kms.NewKMSClient(commandConfig)
iamClient := iam.NewIAMClient(commandConfig)
// validate provided values before creating any resources
credsInput, err := regcredio.ReadCredsInput(args[0])
if err != nil {
log.Fatal("Error executing 'up': ", err)
}
validatedRegCreds, err := validateCredsInput(*credsInput, kmsClient)
if err != nil {
log.Fatal("Error executing 'up': ", err)
}
roleName := c.String(flags.RoleNameFlag)
skipRole := c.Bool(flags.NoRoleFlag)
err = validateRoleDetails(roleName, skipRole)
if err != nil {
log.Fatal("Error executing 'up': ", err)
}
outputDir := c.String(flags.OutputDirFlag)
skipOutput := c.Bool(flags.NoOutputFileFlag)
err = validateOutputOptions(outputDir, skipOutput)
if err != nil {
log.Fatal("Error executing 'up': ", err)
}
// find or create secrets, role
updateAllowed := c.Bool(flags.UpdateExistingSecretsFlag)
credentialOutput, err := getOrCreateRegistryCredentials(validatedRegCreds, smClient, updateAllowed)
if err != nil {
log.Fatal("Error executing 'up': ", err)
}
var tags map[string]*string
if tagVal := c.String(flags.ResourceTagsFlag); tagVal != "" {
tags, err = utils.GetTagsMap(tagVal)
if err != nil {
log.Fatal("Error executing 'up': ", err)
}
}
var policyCreateTime *time.Time
if !skipRole {
region := commandConfig.Session.Config.Region
roleParams := executionRoleParams{
CredEntries: credentialOutput,
RoleName: roleName,
Region: *region,
Tags: tags,
}
policyCreateTime, err = createTaskExecutionRole(roleParams, iamClient, kmsClient)
if err != nil {
log.Fatal("Error executing 'up': ", err)
}
} else {
log.Info("Skipping role creation.")
}
if len(tags) > 0 {
taggingClient := tagging.NewTaggingClient(commandConfig)
err = tagRegistryCredentials(credentialOutput, tags, taggingClient)
if err != nil {
log.Fatal("Failed to tag resources: ", err)
}
}
// produce output file
if !skipOutput {
regcredio.GenerateCredsOutput(credentialOutput, roleName, outputDir, policyCreateTime)
} else {
log.Info("Skipping generation of registry credentials output file.")
}
log.Info("\nIf your input file contains sensitive information, make sure that you delete it after use.")
}