github.com/aavshr/aws-sdk-go@v1.41.3/service/ecr/examples_test.go (about)

     1  // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
     2  
     3  package ecr_test
     4  
     5  import (
     6  	"fmt"
     7  	"strings"
     8  	"time"
     9  
    10  	"github.com/aavshr/aws-sdk-go/aws"
    11  	"github.com/aavshr/aws-sdk-go/aws/awserr"
    12  	"github.com/aavshr/aws-sdk-go/aws/session"
    13  	"github.com/aavshr/aws-sdk-go/service/ecr"
    14  )
    15  
    16  var _ time.Duration
    17  var _ strings.Reader
    18  var _ aws.Config
    19  
    20  func parseTime(layout, value string) *time.Time {
    21  	t, err := time.Parse(layout, value)
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  	return &t
    26  }
    27  
    28  // To delete multiple images
    29  //
    30  // This example deletes images with the tags precise and trusty in a repository called
    31  // ubuntu in the default registry for an account.
    32  func ExampleECR_BatchDeleteImage_shared00() {
    33  	svc := ecr.New(session.New())
    34  	input := &ecr.BatchDeleteImageInput{
    35  		ImageIds: []*ecr.ImageIdentifier{
    36  			{
    37  				ImageTag: aws.String("precise"),
    38  			},
    39  		},
    40  		RepositoryName: aws.String("ubuntu"),
    41  	}
    42  
    43  	result, err := svc.BatchDeleteImage(input)
    44  	if err != nil {
    45  		if aerr, ok := err.(awserr.Error); ok {
    46  			switch aerr.Code() {
    47  			case ecr.ErrCodeServerException:
    48  				fmt.Println(ecr.ErrCodeServerException, aerr.Error())
    49  			case ecr.ErrCodeInvalidParameterException:
    50  				fmt.Println(ecr.ErrCodeInvalidParameterException, aerr.Error())
    51  			case ecr.ErrCodeRepositoryNotFoundException:
    52  				fmt.Println(ecr.ErrCodeRepositoryNotFoundException, aerr.Error())
    53  			default:
    54  				fmt.Println(aerr.Error())
    55  			}
    56  		} else {
    57  			// Print the error, cast err to awserr.Error to get the Code and
    58  			// Message from an error.
    59  			fmt.Println(err.Error())
    60  		}
    61  		return
    62  	}
    63  
    64  	fmt.Println(result)
    65  }
    66  
    67  // To obtain multiple images in a single request
    68  //
    69  // This example obtains information for an image with a specified image digest ID from
    70  // the repository named ubuntu in the current account.
    71  func ExampleECR_BatchGetImage_shared00() {
    72  	svc := ecr.New(session.New())
    73  	input := &ecr.BatchGetImageInput{
    74  		ImageIds: []*ecr.ImageIdentifier{
    75  			{
    76  				ImageTag: aws.String("precise"),
    77  			},
    78  		},
    79  		RepositoryName: aws.String("ubuntu"),
    80  	}
    81  
    82  	result, err := svc.BatchGetImage(input)
    83  	if err != nil {
    84  		if aerr, ok := err.(awserr.Error); ok {
    85  			switch aerr.Code() {
    86  			case ecr.ErrCodeServerException:
    87  				fmt.Println(ecr.ErrCodeServerException, aerr.Error())
    88  			case ecr.ErrCodeInvalidParameterException:
    89  				fmt.Println(ecr.ErrCodeInvalidParameterException, aerr.Error())
    90  			case ecr.ErrCodeRepositoryNotFoundException:
    91  				fmt.Println(ecr.ErrCodeRepositoryNotFoundException, aerr.Error())
    92  			default:
    93  				fmt.Println(aerr.Error())
    94  			}
    95  		} else {
    96  			// Print the error, cast err to awserr.Error to get the Code and
    97  			// Message from an error.
    98  			fmt.Println(err.Error())
    99  		}
   100  		return
   101  	}
   102  
   103  	fmt.Println(result)
   104  }
   105  
   106  // To create a new repository
   107  //
   108  // This example creates a repository called nginx-web-app inside the project-a namespace
   109  // in the default registry for an account.
   110  func ExampleECR_CreateRepository_shared00() {
   111  	svc := ecr.New(session.New())
   112  	input := &ecr.CreateRepositoryInput{
   113  		RepositoryName: aws.String("project-a/nginx-web-app"),
   114  	}
   115  
   116  	result, err := svc.CreateRepository(input)
   117  	if err != nil {
   118  		if aerr, ok := err.(awserr.Error); ok {
   119  			switch aerr.Code() {
   120  			case ecr.ErrCodeServerException:
   121  				fmt.Println(ecr.ErrCodeServerException, aerr.Error())
   122  			case ecr.ErrCodeInvalidParameterException:
   123  				fmt.Println(ecr.ErrCodeInvalidParameterException, aerr.Error())
   124  			case ecr.ErrCodeInvalidTagParameterException:
   125  				fmt.Println(ecr.ErrCodeInvalidTagParameterException, aerr.Error())
   126  			case ecr.ErrCodeTooManyTagsException:
   127  				fmt.Println(ecr.ErrCodeTooManyTagsException, aerr.Error())
   128  			case ecr.ErrCodeRepositoryAlreadyExistsException:
   129  				fmt.Println(ecr.ErrCodeRepositoryAlreadyExistsException, aerr.Error())
   130  			case ecr.ErrCodeLimitExceededException:
   131  				fmt.Println(ecr.ErrCodeLimitExceededException, aerr.Error())
   132  			case ecr.ErrCodeKmsException:
   133  				fmt.Println(ecr.ErrCodeKmsException, aerr.Error())
   134  			default:
   135  				fmt.Println(aerr.Error())
   136  			}
   137  		} else {
   138  			// Print the error, cast err to awserr.Error to get the Code and
   139  			// Message from an error.
   140  			fmt.Println(err.Error())
   141  		}
   142  		return
   143  	}
   144  
   145  	fmt.Println(result)
   146  }
   147  
   148  // To force delete a repository
   149  //
   150  // This example force deletes a repository named ubuntu in the default registry for
   151  // an account. The force parameter is required if the repository contains images.
   152  func ExampleECR_DeleteRepository_shared00() {
   153  	svc := ecr.New(session.New())
   154  	input := &ecr.DeleteRepositoryInput{
   155  		Force:          aws.Bool(true),
   156  		RepositoryName: aws.String("ubuntu"),
   157  	}
   158  
   159  	result, err := svc.DeleteRepository(input)
   160  	if err != nil {
   161  		if aerr, ok := err.(awserr.Error); ok {
   162  			switch aerr.Code() {
   163  			case ecr.ErrCodeServerException:
   164  				fmt.Println(ecr.ErrCodeServerException, aerr.Error())
   165  			case ecr.ErrCodeInvalidParameterException:
   166  				fmt.Println(ecr.ErrCodeInvalidParameterException, aerr.Error())
   167  			case ecr.ErrCodeRepositoryNotFoundException:
   168  				fmt.Println(ecr.ErrCodeRepositoryNotFoundException, aerr.Error())
   169  			case ecr.ErrCodeRepositoryNotEmptyException:
   170  				fmt.Println(ecr.ErrCodeRepositoryNotEmptyException, aerr.Error())
   171  			case ecr.ErrCodeKmsException:
   172  				fmt.Println(ecr.ErrCodeKmsException, aerr.Error())
   173  			default:
   174  				fmt.Println(aerr.Error())
   175  			}
   176  		} else {
   177  			// Print the error, cast err to awserr.Error to get the Code and
   178  			// Message from an error.
   179  			fmt.Println(err.Error())
   180  		}
   181  		return
   182  	}
   183  
   184  	fmt.Println(result)
   185  }
   186  
   187  // To delete the policy associated with a repository
   188  //
   189  // This example deletes the policy associated with the repository named ubuntu in the
   190  // current account.
   191  func ExampleECR_DeleteRepositoryPolicy_shared00() {
   192  	svc := ecr.New(session.New())
   193  	input := &ecr.DeleteRepositoryPolicyInput{
   194  		RepositoryName: aws.String("ubuntu"),
   195  	}
   196  
   197  	result, err := svc.DeleteRepositoryPolicy(input)
   198  	if err != nil {
   199  		if aerr, ok := err.(awserr.Error); ok {
   200  			switch aerr.Code() {
   201  			case ecr.ErrCodeServerException:
   202  				fmt.Println(ecr.ErrCodeServerException, aerr.Error())
   203  			case ecr.ErrCodeInvalidParameterException:
   204  				fmt.Println(ecr.ErrCodeInvalidParameterException, aerr.Error())
   205  			case ecr.ErrCodeRepositoryNotFoundException:
   206  				fmt.Println(ecr.ErrCodeRepositoryNotFoundException, aerr.Error())
   207  			case ecr.ErrCodeRepositoryPolicyNotFoundException:
   208  				fmt.Println(ecr.ErrCodeRepositoryPolicyNotFoundException, aerr.Error())
   209  			default:
   210  				fmt.Println(aerr.Error())
   211  			}
   212  		} else {
   213  			// Print the error, cast err to awserr.Error to get the Code and
   214  			// Message from an error.
   215  			fmt.Println(err.Error())
   216  		}
   217  		return
   218  	}
   219  
   220  	fmt.Println(result)
   221  }
   222  
   223  // To describe all repositories in the current account
   224  //
   225  // The following example obtains a list and description of all repositories in the default
   226  // registry to which the current user has access.
   227  func ExampleECR_DescribeRepositories_shared00() {
   228  	svc := ecr.New(session.New())
   229  	input := &ecr.DescribeRepositoriesInput{}
   230  
   231  	result, err := svc.DescribeRepositories(input)
   232  	if err != nil {
   233  		if aerr, ok := err.(awserr.Error); ok {
   234  			switch aerr.Code() {
   235  			case ecr.ErrCodeServerException:
   236  				fmt.Println(ecr.ErrCodeServerException, aerr.Error())
   237  			case ecr.ErrCodeInvalidParameterException:
   238  				fmt.Println(ecr.ErrCodeInvalidParameterException, aerr.Error())
   239  			case ecr.ErrCodeRepositoryNotFoundException:
   240  				fmt.Println(ecr.ErrCodeRepositoryNotFoundException, aerr.Error())
   241  			default:
   242  				fmt.Println(aerr.Error())
   243  			}
   244  		} else {
   245  			// Print the error, cast err to awserr.Error to get the Code and
   246  			// Message from an error.
   247  			fmt.Println(err.Error())
   248  		}
   249  		return
   250  	}
   251  
   252  	fmt.Println(result)
   253  }
   254  
   255  // To obtain an authorization token
   256  //
   257  // This example gets an authorization token for your default registry.
   258  func ExampleECR_GetAuthorizationToken_shared00() {
   259  	svc := ecr.New(session.New())
   260  	input := &ecr.GetAuthorizationTokenInput{}
   261  
   262  	result, err := svc.GetAuthorizationToken(input)
   263  	if err != nil {
   264  		if aerr, ok := err.(awserr.Error); ok {
   265  			switch aerr.Code() {
   266  			case ecr.ErrCodeServerException:
   267  				fmt.Println(ecr.ErrCodeServerException, aerr.Error())
   268  			case ecr.ErrCodeInvalidParameterException:
   269  				fmt.Println(ecr.ErrCodeInvalidParameterException, aerr.Error())
   270  			default:
   271  				fmt.Println(aerr.Error())
   272  			}
   273  		} else {
   274  			// Print the error, cast err to awserr.Error to get the Code and
   275  			// Message from an error.
   276  			fmt.Println(err.Error())
   277  		}
   278  		return
   279  	}
   280  
   281  	fmt.Println(result)
   282  }
   283  
   284  // To get the current policy for a repository
   285  //
   286  // This example obtains the repository policy for the repository named ubuntu.
   287  func ExampleECR_GetRepositoryPolicy_shared00() {
   288  	svc := ecr.New(session.New())
   289  	input := &ecr.GetRepositoryPolicyInput{
   290  		RepositoryName: aws.String("ubuntu"),
   291  	}
   292  
   293  	result, err := svc.GetRepositoryPolicy(input)
   294  	if err != nil {
   295  		if aerr, ok := err.(awserr.Error); ok {
   296  			switch aerr.Code() {
   297  			case ecr.ErrCodeServerException:
   298  				fmt.Println(ecr.ErrCodeServerException, aerr.Error())
   299  			case ecr.ErrCodeInvalidParameterException:
   300  				fmt.Println(ecr.ErrCodeInvalidParameterException, aerr.Error())
   301  			case ecr.ErrCodeRepositoryNotFoundException:
   302  				fmt.Println(ecr.ErrCodeRepositoryNotFoundException, aerr.Error())
   303  			case ecr.ErrCodeRepositoryPolicyNotFoundException:
   304  				fmt.Println(ecr.ErrCodeRepositoryPolicyNotFoundException, aerr.Error())
   305  			default:
   306  				fmt.Println(aerr.Error())
   307  			}
   308  		} else {
   309  			// Print the error, cast err to awserr.Error to get the Code and
   310  			// Message from an error.
   311  			fmt.Println(err.Error())
   312  		}
   313  		return
   314  	}
   315  
   316  	fmt.Println(result)
   317  }
   318  
   319  // To list all images in a repository
   320  //
   321  // This example lists all of the images in the repository named ubuntu in the default
   322  // registry in the current account.
   323  func ExampleECR_ListImages_shared00() {
   324  	svc := ecr.New(session.New())
   325  	input := &ecr.ListImagesInput{
   326  		RepositoryName: aws.String("ubuntu"),
   327  	}
   328  
   329  	result, err := svc.ListImages(input)
   330  	if err != nil {
   331  		if aerr, ok := err.(awserr.Error); ok {
   332  			switch aerr.Code() {
   333  			case ecr.ErrCodeServerException:
   334  				fmt.Println(ecr.ErrCodeServerException, aerr.Error())
   335  			case ecr.ErrCodeInvalidParameterException:
   336  				fmt.Println(ecr.ErrCodeInvalidParameterException, aerr.Error())
   337  			case ecr.ErrCodeRepositoryNotFoundException:
   338  				fmt.Println(ecr.ErrCodeRepositoryNotFoundException, aerr.Error())
   339  			default:
   340  				fmt.Println(aerr.Error())
   341  			}
   342  		} else {
   343  			// Print the error, cast err to awserr.Error to get the Code and
   344  			// Message from an error.
   345  			fmt.Println(err.Error())
   346  		}
   347  		return
   348  	}
   349  
   350  	fmt.Println(result)
   351  }