add flag to use aws config cred
This commit is contained in:
parent
ef25ccc07b
commit
b113007969
21
main.go
21
main.go
@ -24,6 +24,7 @@ type RunFlag struct {
|
||||
KeepNum int
|
||||
ExcludeTag arrayFlag
|
||||
ListRepo bool
|
||||
CertProfile string
|
||||
}
|
||||
|
||||
type ImageArr []*ecr.ImageDetail
|
||||
@ -56,22 +57,30 @@ func init() {
|
||||
flag.IntVar(&runFlag.KeepNum, "keep", 5, "keep number images")
|
||||
flag.Var(&runFlag.ExcludeTag, "e", "exlude delete tag")
|
||||
flag.BoolVar(&runFlag.ListRepo, "list-repo", false, "list all repository")
|
||||
flag.StringVar(&runFlag.CertProfile, "profile", "", "aws config profile")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func main() {
|
||||
accessKey := os.Getenv("AWS_ACCESS_KEY")
|
||||
secretKey := os.Getenv("AWS_SECRET_KEY")
|
||||
var cred *credentials.Credentials
|
||||
_ = cred
|
||||
region := os.Getenv("AWS_REGION")
|
||||
if len(accessKey) == 0 || len(secretKey) == 0 {
|
||||
log.Fatal("aws access key or secret key env not found")
|
||||
}
|
||||
if len(region) == 0 {
|
||||
region = "us-east-1"
|
||||
}
|
||||
if len(runFlag.CertProfile) == 0 {
|
||||
accessKey := os.Getenv("AWS_ACCESS_KEY")
|
||||
secretKey := os.Getenv("AWS_SECRET_KEY")
|
||||
if len(accessKey) == 0 || len(secretKey) == 0 {
|
||||
log.Fatal("AWS_ACCESS_KEY or AWS_SECRET_KEY env not found")
|
||||
}
|
||||
cred = credentials.NewStaticCredentials(accessKey, secretKey, "")
|
||||
} else {
|
||||
cred = credentials.NewSharedCredentials("", runFlag.CertProfile)
|
||||
}
|
||||
conf := &aws.Config{
|
||||
Region: aws.String(region),
|
||||
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
|
||||
Credentials: cred,
|
||||
}
|
||||
sess := session.New(conf)
|
||||
svc = ecr.New(sess)
|
||||
|
Loading…
Reference in New Issue
Block a user