docker ECR login (go-aws-sdk)
This commit is contained in:
36
app/modules/aws_ledo/ecr_login.go
Normal file
36
app/modules/aws_ledo/ecr_login.go
Normal file
@ -0,0 +1,36 @@
|
||||
package aws_ledo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/ecr"
|
||||
"os"
|
||||
)
|
||||
|
||||
func getRegion() string {
|
||||
region, exists := os.LookupEnv("AWS_REGION")
|
||||
if !exists {
|
||||
fmt.Printf("AWS_REGION not set and unable to fetch region")
|
||||
os.Exit(1)
|
||||
}
|
||||
return region
|
||||
}
|
||||
|
||||
func EcrLogin() (*ecr.GetAuthorizationTokenOutput, error) {
|
||||
var input *ecr.GetAuthorizationTokenInput
|
||||
var token *ecr.GetAuthorizationTokenOutput
|
||||
|
||||
config := &aws.Config{
|
||||
Region: aws.String(getRegion()),
|
||||
}
|
||||
sess, _ := session.NewSession(config)
|
||||
_, err := sess.Config.Credentials.Get()
|
||||
if err != nil {
|
||||
return token, err
|
||||
}
|
||||
|
||||
ecrCtx := ecr.New(sess)
|
||||
token, err = ecrCtx.GetAuthorizationToken(input)
|
||||
return token, nil
|
||||
}
|
Reference in New Issue
Block a user