setRepositoryPolicy method

Future<SetRepositoryPolicyResponse> setRepositoryPolicy({
  1. required String policyText,
  2. required String repositoryName,
  3. bool? force,
  4. String? registryId,
})

Applies a repository policy to the specified repository to control access permissions. For more information, see Amazon ECR Repository Policies in the Amazon Elastic Container Registry User Guide.

May throw ServerException. May throw InvalidParameterException. May throw RepositoryNotFoundException.

Parameter policyText : The JSON repository policy text to apply to the repository. For more information, see Amazon ECR Repository Policies in the Amazon Elastic Container Registry User Guide.

Parameter repositoryName : The name of the repository to receive the policy.

Parameter force : If the policy you are attempting to set on a repository policy would prevent you from setting another policy in the future, you must force the SetRepositoryPolicy operation. This is intended to prevent accidental repository lock outs.

Parameter registryId : The AWS account ID associated with the registry that contains the repository. If you do not specify a registry, the default registry is assumed.

Implementation

Future<SetRepositoryPolicyResponse> setRepositoryPolicy({
  required String policyText,
  required String repositoryName,
  bool? force,
  String? registryId,
}) async {
  ArgumentError.checkNotNull(policyText, 'policyText');
  _s.validateStringLength(
    'policyText',
    policyText,
    0,
    10240,
    isRequired: true,
  );
  ArgumentError.checkNotNull(repositoryName, 'repositoryName');
  _s.validateStringLength(
    'repositoryName',
    repositoryName,
    2,
    256,
    isRequired: true,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AmazonEC2ContainerRegistry_V20150921.SetRepositoryPolicy'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'policyText': policyText,
      'repositoryName': repositoryName,
      if (force != null) 'force': force,
      if (registryId != null) 'registryId': registryId,
    },
  );

  return SetRepositoryPolicyResponse.fromJson(jsonResponse.body);
}