putResourcePolicy method

Future<PutResourcePolicyResponse> putResourcePolicy({
  1. required String policyInJson,
  2. EnableHybridValues? enableHybrid,
  3. ExistCondition? policyExistsCondition,
  4. String? policyHashCondition,
  5. String? resourceArn,
})

Sets the Data Catalog resource policy for access control.

May throw EntityNotFoundException. May throw InternalServiceException. May throw OperationTimeoutException. May throw InvalidInputException. May throw ConditionCheckFailureException.

Parameter policyInJson : Contains the policy document to set, in JSON format.

Parameter enableHybrid : Allows you to specify if you want to use both resource-level and account/catalog-level resource policies. A resource-level policy is a policy attached to an individual resource such as a database or a table.

The default value of NO indicates that resource-level policies cannot co-exist with an account-level policy. A value of YES means the use of both resource-level and account/catalog-level resource policies is allowed.

Parameter policyExistsCondition : A value of MUST_EXIST is used to update a policy. A value of NOT_EXIST is used to create a new policy. If a value of NONE or a null value is used, the call will not depend on the existence of a policy.

Parameter policyHashCondition : The hash value returned when the previous policy was set using PutResourcePolicy. Its purpose is to prevent concurrent modifications of a policy. Do not use this parameter if no previous policy has been set.

Parameter resourceArn : The ARN of the AWS Glue resource for the resource policy to be set. For more information about AWS Glue resource ARNs, see the AWS Glue ARN string pattern

Implementation

Future<PutResourcePolicyResponse> putResourcePolicy({
  required String policyInJson,
  EnableHybridValues? enableHybrid,
  ExistCondition? policyExistsCondition,
  String? policyHashCondition,
  String? resourceArn,
}) async {
  ArgumentError.checkNotNull(policyInJson, 'policyInJson');
  _s.validateStringLength(
    'policyInJson',
    policyInJson,
    2,
    10240,
    isRequired: true,
  );
  _s.validateStringLength(
    'policyHashCondition',
    policyHashCondition,
    1,
    255,
  );
  _s.validateStringLength(
    'resourceArn',
    resourceArn,
    1,
    10240,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSGlue.PutResourcePolicy'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'PolicyInJson': policyInJson,
      if (enableHybrid != null) 'EnableHybrid': enableHybrid.toValue(),
      if (policyExistsCondition != null)
        'PolicyExistsCondition': policyExistsCondition.toValue(),
      if (policyHashCondition != null)
        'PolicyHashCondition': policyHashCondition,
      if (resourceArn != null) 'ResourceArn': resourceArn,
    },
  );

  return PutResourcePolicyResponse.fromJson(jsonResponse.body);
}