-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
258 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func taskDefinitionsEnvRun(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
} | ||
|
||
var taskDefinitionsEnvCmd = &cobra.Command{ | ||
Use: "env [command]", | ||
Short: "Commands to manage Task Definitions' environment variables", | ||
Run: taskDefinitionsEnvRun, | ||
} | ||
|
||
func init() { | ||
taskDefinitionsCmd.AddCommand(taskDefinitionsEnvCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ecs" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func taskDefinitionsEnvDeleteRun(cmd *cobra.Command, args []string) { | ||
tdDescription, err := ecsI.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{ | ||
TaskDefinition: aws.String(args[0]), | ||
}) | ||
t.Must(err) | ||
|
||
td := tdDescription.TaskDefinition | ||
|
||
var cdToUpdate *ecs.ContainerDefinition | ||
|
||
if containerName == "" { | ||
cdToUpdate = td.ContainerDefinitions[0] | ||
} else { | ||
for _, cd := range td.ContainerDefinitions { | ||
if aws.StringValue(cd.Name) == containerName { | ||
cdToUpdate = cd | ||
break | ||
} | ||
} | ||
} | ||
|
||
if cdToUpdate == nil { | ||
t.Exitf("No container on the Task Family %s\n", aws.StringValue(td.Family)) | ||
} | ||
|
||
env := cdToUpdate.Environment | ||
|
||
envKeys := viper.GetStringSlice("keys") | ||
|
||
for _, key := range envKeys { | ||
for i, envKeyValuePair := range env { | ||
if aws.StringValue(envKeyValuePair.Name) == key { | ||
env = append(env[:i], env[i+1:]...) | ||
break | ||
} | ||
} | ||
} | ||
|
||
cdToUpdate.Environment = env | ||
|
||
t.Must(ecsI.RegisterTaskDefinition(&ecs.RegisterTaskDefinitionInput{ | ||
ContainerDefinitions: td.ContainerDefinitions, | ||
Cpu: td.Cpu, | ||
ExecutionRoleArn: td.ExecutionRoleArn, | ||
Family: td.Family, | ||
IpcMode: td.IpcMode, | ||
Memory: td.Memory, | ||
NetworkMode: td.NetworkMode, | ||
PidMode: td.PidMode, | ||
PlacementConstraints: td.PlacementConstraints, | ||
ProxyConfiguration: td.ProxyConfiguration, | ||
RequiresCompatibilities: td.RequiresCompatibilities, | ||
TaskRoleArn: td.TaskRoleArn, | ||
Volumes: td.Volumes, | ||
})) | ||
} | ||
|
||
var taskDefinitionsEnvDeleteCmd = &cobra.Command{ | ||
Use: "delete [task-definition]", | ||
Short: "Delete a Task Definition's environment variables", | ||
Args: cobra.ExactArgs(1), | ||
Run: taskDefinitionsEnvDeleteRun, | ||
PersistentPreRun: persistentPreRun, | ||
} | ||
|
||
func init() { | ||
taskDefinitionsEnvCmd.AddCommand(taskDefinitionsEnvDeleteCmd) | ||
|
||
flags := taskDefinitionsEnvDeleteCmd.Flags() | ||
|
||
flags.StringVar(&containerName, "container", "", containerNameSpec) | ||
viper.BindPFlag("container", taskDefinitionsEnvDeleteCmd.Flags().Lookup("container")) | ||
|
||
flags.StringSliceP("keys", "k", []string{}, "Delete Environment Variables of the Task. Inform the variable names. Can be informed multiple times.") | ||
viper.BindPFlag("keys", taskDefinitionsEnvDeleteCmd.Flags().Lookup("keys")) | ||
|
||
flags.BoolVar(&taskDefinitionsEnvOverride, "override", false, taskDefinitionsEnvOverrideSpec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ecs" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func taskDefinitionsEnvListRun(cmd *cobra.Command, args []string) { | ||
tdDescription, err := ecsI.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{ | ||
TaskDefinition: aws.String(args[0]), | ||
}) | ||
t.Must(err) | ||
|
||
td := tdDescription.TaskDefinition | ||
|
||
var targetCd *ecs.ContainerDefinition | ||
|
||
if containerName == "" { | ||
targetCd = td.ContainerDefinitions[0] | ||
} else { | ||
for _, cd := range td.ContainerDefinitions { | ||
if aws.StringValue(cd.Name) == containerName { | ||
targetCd = cd | ||
break | ||
} | ||
} | ||
} | ||
|
||
if targetCd == nil { | ||
t.Exitf("No container on the Task Family %s\n", aws.StringValue(td.Family)) | ||
} | ||
|
||
for _, envVar := range targetCd.Environment { | ||
t.Outf("%s=%s\n", aws.StringValue(envVar.Name), aws.StringValue(envVar.Value)) | ||
} | ||
} | ||
|
||
var taskDefinitionsEnvListCmd = &cobra.Command{ | ||
Use: "list [task-definition]", | ||
Short: "List a Task Definition's environment variables", | ||
Args: cobra.ExactArgs(1), | ||
Run: taskDefinitionsEnvListRun, | ||
PersistentPreRun: persistentPreRun, | ||
} | ||
|
||
func init() { | ||
taskDefinitionsEnvCmd.AddCommand(taskDefinitionsEnvListCmd) | ||
|
||
flags := taskDefinitionsEnvListCmd.Flags() | ||
|
||
flags.StringVar(&containerName, "container", "", containerNameSpec) | ||
viper.BindPFlag("container", taskDefinitionsEnvListCmd.Flags().Lookup("container")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package cmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ecs" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func taskDefinitionsEnvSetRun(cmd *cobra.Command, args []string) { | ||
tdDescription, err := ecsI.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{ | ||
TaskDefinition: aws.String(args[0]), | ||
}) | ||
t.Must(err) | ||
|
||
td := tdDescription.TaskDefinition | ||
|
||
var cdToUpdate *ecs.ContainerDefinition | ||
|
||
if containerName == "" { | ||
cdToUpdate = td.ContainerDefinitions[0] | ||
} else { | ||
for _, cd := range td.ContainerDefinitions { | ||
if aws.StringValue(cd.Name) == containerName { | ||
cdToUpdate = cd | ||
break | ||
} | ||
} | ||
} | ||
|
||
if cdToUpdate == nil { | ||
t.Exitf("No container on the Task Family %s\n", aws.StringValue(td.Family)) | ||
} | ||
|
||
env := cdToUpdate.Environment | ||
|
||
if taskDefinitionsEnvOverride { | ||
env = make([]*ecs.KeyValuePair, 0) | ||
} | ||
|
||
for _, envPair := range environmentVariables { | ||
envSlice := strings.Split(envPair, "=") | ||
if len(envSlice) != 2 { | ||
continue | ||
} | ||
|
||
env = append(env, &ecs.KeyValuePair{Name: aws.String(envSlice[0]), Value: aws.String(envSlice[1])}) | ||
} | ||
|
||
cdToUpdate.Environment = env | ||
|
||
t.Must(ecsI.RegisterTaskDefinition(&ecs.RegisterTaskDefinitionInput{ | ||
ContainerDefinitions: td.ContainerDefinitions, | ||
Cpu: td.Cpu, | ||
ExecutionRoleArn: td.ExecutionRoleArn, | ||
Family: td.Family, | ||
IpcMode: td.IpcMode, | ||
Memory: td.Memory, | ||
NetworkMode: td.NetworkMode, | ||
PidMode: td.PidMode, | ||
PlacementConstraints: td.PlacementConstraints, | ||
ProxyConfiguration: td.ProxyConfiguration, | ||
RequiresCompatibilities: td.RequiresCompatibilities, | ||
TaskRoleArn: td.TaskRoleArn, | ||
Volumes: td.Volumes, | ||
})) | ||
} | ||
|
||
var taskDefinitionsEnvSetCmd = &cobra.Command{ | ||
Use: "set [task-definition]", | ||
Short: "Set a Task Definition's environment variables", | ||
Args: cobra.ExactArgs(1), | ||
Run: taskDefinitionsEnvSetRun, | ||
PersistentPreRun: persistentPreRun, | ||
} | ||
|
||
func init() { | ||
taskDefinitionsEnvCmd.AddCommand(taskDefinitionsEnvSetCmd) | ||
|
||
flags := taskDefinitionsEnvSetCmd.Flags() | ||
|
||
flags.StringVar(&containerName, "container", "", containerNameSpec) | ||
viper.BindPFlag("container", taskDefinitionsEnvSetCmd.Flags().Lookup("container")) | ||
|
||
flags.StringSliceVarP(&environmentVariables, "env", "e", []string{}, environmentVariablesSpec) | ||
|
||
flags.BoolVar(&taskDefinitionsEnvOverride, "override", false, taskDefinitionsEnvOverrideSpec) | ||
} |