Пример #1
0
// createECSConfigFromCli creates a new CliConfig object from the CLI context.
// It reads CLI flags to validate the ecs-cli config fields.
func createECSConfigFromCli(context *cli.Context) (*config.CliConfig, error) {
	accessKey := context.String(ecscli.AccessKeyFlag)
	secretKey := context.String(ecscli.SecretKeyFlag)
	region := context.String(ecscli.RegionFlag)
	profile := context.String(ecscli.ProfileFlag)
	cluster := context.String(ecscli.ClusterFlag)

	if cluster == "" {
		return nil, fmt.Errorf("Missing required argument '%s'", ecscli.ClusterFlag)
	}

	// ONLY allow for profile OR access keys to be specified
	isProfileSpecified := profile != ""
	isAccessKeySpecified := accessKey != "" || secretKey != ""
	if isProfileSpecified && isAccessKeySpecified {
		return nil, fmt.Errorf("Both AWS Access/Secret Keys and Profile were provided; only one of the two can be specified")
	}

	ecsConfig := config.NewCliConfig(cluster)
	ecsConfig.AwsProfile = profile
	ecsConfig.AwsAccessKey = accessKey
	ecsConfig.AwsSecretKey = secretKey
	ecsConfig.Region = region

	return ecsConfig, nil
}
Пример #2
0
// createECSConfigFromCli creates a new CliConfig object from the CLI context.
// It reads CLI flags to validate the ecs-cli config fields.
func createECSConfigFromCli(context *cli.Context) (*config.CliConfig, error) {
	accessKey := context.String(ecscli.AccessKeyFlag)
	secretKey := context.String(ecscli.SecretKeyFlag)
	region := context.String(ecscli.RegionFlag)
	profile := context.String(ecscli.ProfileFlag)
	cluster := context.String(ecscli.ClusterFlag)

	if cluster == "" {
		return nil, fmt.Errorf("Missing required argument '%s'", ecscli.ClusterFlag)
	}

	if profile == "" {
		if accessKey == "" || secretKey == "" {
			return nil, fmt.Errorf("Missing required credentials. Specify either '%s' with the name of an existing named profile in ~/.aws/credentials, or your AWS credentials with '%s' and '%s'", ecscli.ProfileFlag, ecscli.AccessKeyFlag, ecscli.SecretKeyFlag)
		}
	}

	ecsConfig := config.NewCliConfig(cluster)
	ecsConfig.AwsProfile = profile
	ecsConfig.AwsAccessKey = accessKey
	ecsConfig.AwsSecretKey = secretKey
	ecsConfig.Region = region

	return ecsConfig, nil
}
Пример #3
0
func (rdwr *mockReadWriter) GetConfig() (*config.CliConfig, error) {
	return config.NewCliConfig(clusterName), nil
}