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 public repository to control access permissions. For more information, see Amazon ECR Repository Policies in the Amazon Elastic Container Registry User Guide.

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

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 that you want to set on a repository policy would prevent you from setting another policy in the future, you must force the SetRepositoryPolicy operation. This prevents accidental repository lockouts.

Parameter registryId : The Amazon Web Services account ID that's associated with the registry that contains the repository. If you do not specify a registry, the default public registry is assumed.

Implementation

Future<SetRepositoryPolicyResponse> setRepositoryPolicy({
  required String policyText,
  required String repositoryName,
  bool? force,
  String? registryId,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'SpencerFrontendService.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);
}