本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/ecr.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ExampleECR_GetAuthorizationToken
func ExampleECR_GetAuthorizationToken() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := ecr.New(sess)
params := &ecr.GetAuthorizationTokenInput{
RegistryIds: []*string{
aws.String("RegistryId"), // Required
// More values...
},
}
resp, err := svc.GetAuthorizationToken(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例2: ExampleECR_ListImages
func ExampleECR_ListImages() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := ecr.New(sess)
params := &ecr.ListImagesInput{
RepositoryName: aws.String("RepositoryName"), // Required
Filter: &ecr.ListImagesFilter{
TagStatus: aws.String("TagStatus"),
},
MaxResults: aws.Int64(1),
NextToken: aws.String("NextToken"),
RegistryId: aws.String("RegistryId"),
}
resp, err := svc.ListImages(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例3: ExampleECR_PutImage
func ExampleECR_PutImage() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := ecr.New(sess)
params := &ecr.PutImageInput{
ImageManifest: aws.String("ImageManifest"), // Required
RepositoryName: aws.String("RepositoryName"), // Required
RegistryId: aws.String("RegistryId"),
}
resp, err := svc.PutImage(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例4: ExampleECR_BatchCheckLayerAvailability
func ExampleECR_BatchCheckLayerAvailability() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := ecr.New(sess)
params := &ecr.BatchCheckLayerAvailabilityInput{
LayerDigests: []*string{ // Required
aws.String("BatchedOperationLayerDigest"), // Required
// More values...
},
RepositoryName: aws.String("RepositoryName"), // Required
RegistryId: aws.String("RegistryId"),
}
resp, err := svc.BatchCheckLayerAvailability(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例5: ExampleECR_UploadLayerPart
func ExampleECR_UploadLayerPart() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := ecr.New(sess)
params := &ecr.UploadLayerPartInput{
LayerPartBlob: []byte("PAYLOAD"), // Required
PartFirstByte: aws.Int64(1), // Required
PartLastByte: aws.Int64(1), // Required
RepositoryName: aws.String("RepositoryName"), // Required
UploadId: aws.String("UploadId"), // Required
RegistryId: aws.String("RegistryId"),
}
resp, err := svc.UploadLayerPart(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例6: ExampleECR_SetRepositoryPolicy
func ExampleECR_SetRepositoryPolicy() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := ecr.New(sess)
params := &ecr.SetRepositoryPolicyInput{
PolicyText: aws.String("RepositoryPolicyText"), // Required
RepositoryName: aws.String("RepositoryName"), // Required
Force: aws.Bool(true),
RegistryId: aws.String("RegistryId"),
}
resp, err := svc.SetRepositoryPolicy(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例7: newAuthProvider
func newAuthProvider(c *cli.Context) (dockerauth.AuthProvider, error) {
awsSession := newConfigProvider(c)
provider := dockerauth.NewMultiAuthProvider()
provider.AddProvider(dockerauth.NewECRAuthProvider(func(region string) dockerauth.ECR {
return ecr.New(awsSession, &aws.Config{Region: aws.String(region)})
}))
if dockerConfigPath := c.String(FlagDockerAuth); dockerConfigPath != "" {
dockerConfigFile, err := os.Open(dockerConfigPath)
if err != nil {
return nil, err
}
defer dockerConfigFile.Close()
dockerConfigProvider, err := dockerauth.NewDockerConfigAuthProvider(dockerConfigFile)
if err != nil {
return nil, err
}
provider.AddProvider(dockerConfigProvider)
}
return provider, nil
}
示例8: ExampleECR_DescribeRepositories
func ExampleECR_DescribeRepositories() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := ecr.New(sess)
params := &ecr.DescribeRepositoriesInput{
MaxResults: aws.Int64(1),
NextToken: aws.String("NextToken"),
RegistryId: aws.String("RegistryId"),
RepositoryNames: []*string{
aws.String("RepositoryName"), // Required
// More values...
},
}
resp, err := svc.DescribeRepositories(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例9: NewEcsImageCreator
//NewEcsImageCreator creates an instance of the EcsImageCreator from the docker environment variables, and returns the instance
func NewEcsImageCreator(repo string, region string) (ImageCreator, error) {
//
awsClient := ecr.New(session.New(), &aws.Config{Region: aws.String(region)})
//only try to pull a single repository as a test
describeRequest := &ecr.DescribeRepositoriesInput{
MaxResults: aws.Int64(1),
}
_, err := awsClient.DescribeRepositories(describeRequest)
if err != nil {
return nil, err
}
localDocker, err := NewLocalImageCreator(repo)
if err != nil {
return nil, err
}
return &EcsImageCreator{
awsClient: awsClient,
dockerCreator: localDocker,
}, nil
}
示例10: ExampleECR_BatchGetImage
func ExampleECR_BatchGetImage() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := ecr.New(sess)
params := &ecr.BatchGetImageInput{
ImageIds: []*ecr.ImageIdentifier{ // Required
{ // Required
ImageDigest: aws.String("ImageDigest"),
ImageTag: aws.String("ImageTag"),
},
// More values...
},
RepositoryName: aws.String("RepositoryName"), // Required
RegistryId: aws.String("RegistryId"),
}
resp, err := svc.BatchGetImage(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例11: NewClient
func (defaultClientFactory DefaultClientFactory) NewClient(region string) Client {
awsSession := session.New()
return &defaultClient{
ecrClient: ecr.New(awsSession, &aws.Config{Region: aws.String(region)}),
credentialCache: defaultClientFactory.buildCredentialsCache(awsSession, region),
}
}
示例12: DockerLogin
func DockerLogin(ac docker.AuthConfiguration) (string, error) {
if ac.Email == "" {
ac.Email = "[email protected]"
}
// if ECR URL, try Username and Password as IAM keys to get auth token
if match := regexpECR.FindStringSubmatch(ac.ServerAddress); len(match) > 1 {
ECR := ecr.New(session.New(), &aws.Config{
Credentials: credentials.NewStaticCredentials(ac.Username, ac.Password, ""),
Region: aws.String(match[2]),
})
res, err := ECR.GetAuthorizationToken(&ecr.GetAuthorizationTokenInput{
RegistryIds: []*string{aws.String(match[1])},
})
if err != nil {
return "", err
}
if len(res.AuthorizationData) < 1 {
return "", fmt.Errorf("no authorization data")
}
endpoint := *res.AuthorizationData[0].ProxyEndpoint
data, err := base64.StdEncoding.DecodeString(*res.AuthorizationData[0].AuthorizationToken)
if err != nil {
return "", err
}
parts := strings.SplitN(string(data), ":", 2)
ac.Password = parts[1]
ac.ServerAddress = endpoint[8:]
ac.Username = parts[0]
}
args := []string{"login", "-e", ac.Email, "-u", ac.Username, "-p", ac.Password, ac.ServerAddress}
out, err := exec.Command("docker", args...).CombinedOutput()
// log args with password masked
args[6] = "*****"
cmd := fmt.Sprintf("docker %s", strings.Trim(fmt.Sprint(args), "[]"))
if err != nil {
fmt.Printf("ns=kernel cn=docker at=DockerLogin state=error step=exec.Command cmd=%q out=%q err=%q\n", cmd, out, err)
} else {
fmt.Printf("ns=kernel cn=docker at=DockerLogin state=success step=exec.Command cmd=%q\n", cmd)
}
return ac.ServerAddress, err
}
示例13: GetECRAuth
// GetECRAuth requests AWS ECR API to get docker.AuthConfiguration token
func GetECRAuth(registry, region string) (result docker.AuthConfiguration, err error) {
_ecrAuthCache.mu.Lock()
defer _ecrAuthCache.mu.Unlock()
if token, ok := _ecrAuthCache.tokens[registry]; ok {
return token, nil
}
defer func() {
_ecrAuthCache.tokens[registry] = result
}()
cfg := &aws.Config{
Region: aws.String(region),
}
if log.StandardLogger().Level >= log.DebugLevel {
cfg.LogLevel = aws.LogLevel(aws.LogDebugWithRequestErrors)
}
split := strings.Split(registry, ".")
svc := ecr.New(session.New(), cfg)
params := &ecr.GetAuthorizationTokenInput{
RegistryIds: []*string{aws.String(split[0])},
}
res, err := svc.GetAuthorizationToken(params)
if err != nil {
return result, err
}
if len(res.AuthorizationData) == 0 {
return result, nil
}
data, err := base64.StdEncoding.DecodeString(*res.AuthorizationData[0].AuthorizationToken)
if err != nil {
return result, err
}
userpass := strings.Split(string(data), ":")
if len(userpass) != 2 {
return result, fmt.Errorf("Cannot parse token got from ECR: %s", string(data))
}
result = docker.AuthConfiguration{
Username: userpass[0],
Password: userpass[1],
ServerAddress: *res.AuthorizationData[0].ProxyEndpoint,
}
return
}
示例14: DockerLogin
func DockerLogin(ac docker.AuthConfiguration) (string, error) {
log := Logger.At("DockerLogin").Start()
if ac.Email == "" {
ac.Email = "[email protected]"
}
// if ECR URL, try Username and Password as IAM keys to get auth token
if match := regexpECR.FindStringSubmatch(ac.ServerAddress); len(match) > 1 {
ECR := ecr.New(session.New(), &aws.Config{
Credentials: credentials.NewStaticCredentials(ac.Username, ac.Password, ""),
Region: aws.String(match[2]),
})
res, err := ECR.GetAuthorizationToken(&ecr.GetAuthorizationTokenInput{
RegistryIds: []*string{aws.String(match[1])},
})
if err != nil {
return "", err
}
if len(res.AuthorizationData) < 1 {
return "", fmt.Errorf("no authorization data")
}
endpoint := *res.AuthorizationData[0].ProxyEndpoint
data, err := base64.StdEncoding.DecodeString(*res.AuthorizationData[0].AuthorizationToken)
if err != nil {
return "", err
}
parts := strings.SplitN(string(data), ":", 2)
ac.Password = parts[1]
ac.ServerAddress = endpoint[8:]
ac.Username = parts[0]
}
log = log.Namespace("host=%q user=%q", ac.ServerAddress, ac.Username)
args := []string{"login", "-e", ac.Email, "-u", ac.Username, "-p", ac.Password, ac.ServerAddress}
if _, err := exec.Command("docker", args...).CombinedOutput(); err != nil {
log.Error(err)
return "", err
}
log.Success()
return ac.ServerAddress, nil
}
示例15: CreateImageRepo
// CreateImageRepo create a repository for the image on amazon's ECR(EC2 Container Repository)
// if it doesn't exist as repository needs to be present before pushing and image into it.
func CreateImageRepo(reponame string, params map[string]string) error {
var (
accessKey string
secretKey string
regionName string
ok bool
)
accessKey, ok = params["accesskey"]
if !ok {
accessKey = ""
}
secretKey, ok = params["secretkey"]
if !ok {
secretKey = ""
}
regionName, ok = params["region"]
if !ok || fmt.Sprint(regionName) == "" {
return fmt.Errorf("No region parameter provided")
}
region := fmt.Sprint(regionName)
creds := credentials.NewChainCredentials([]credentials.Provider{
&credentials.StaticProvider{
Value: credentials.Value{
AccessKeyID: accessKey,
SecretAccessKey: secretKey,
},
},
&credentials.EnvProvider{},
&credentials.SharedCredentialsProvider{},
&ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(session.New())},
})
awsConfig := aws.NewConfig()
awsConfig.WithCredentials(creds)
awsConfig.WithRegion(region)
svc := ecr.New(session.New(awsConfig))
repoInput := &ecr.CreateRepositoryInput{
RepositoryName: aws.String(reponame),
}
_, err := svc.CreateRepository(repoInput)
if err != nil {
if s3Err, ok := err.(awserr.Error); ok && s3Err.Code() == "RepositoryAlreadyExistsException" {
return nil
}
return err
}
return nil
}