-
Notifications
You must be signed in to change notification settings - Fork 38
/
aws.go
38 lines (30 loc) · 849 Bytes
/
aws.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package cli
import (
"fmt"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
const (
// AWSRegionFlag is the generic AWS Region Flag
AWSRegionFlag string = "aws-region"
// aws-sdk-go-v2 does not expose a constant for the regions anymore
AWSRegionUSGovWest1 = "us-gov-west-1"
)
type errInvalidRegion struct {
Region string
}
func (e *errInvalidRegion) Error() string {
return fmt.Sprintf("invalid region %s", e.Region)
}
// InitAWSFlags initializes AWS command line flags
func InitAWSFlags(flag *pflag.FlagSet) {
flag.String(AWSRegionFlag, AWSRegionUSGovWest1, "The AWS Region")
}
// CheckAWSRegion validates the AWS Region command line flags
func CheckAWSRegion(v *viper.Viper) (string, error) {
region := v.GetString(AWSRegionFlag)
if len(region) == 0 {
return "", &errInvalidRegion{Region: region}
}
return region, nil
}