updatePolicy method
Modifies a Cedar static policy in the specified policy store. You can change only certain elements of the UpdatePolicyDefinition parameter. You can directly update only static policies. To change a template-linked policy, you must update the template instead, using UpdatePolicyTemplate.
- If policy validation is enabled in the policy store, then updating a static policy causes Verified Permissions to validate the policy against the schema in the policy store. If the updated static policy doesn't pass validation, the operation fails and the update isn't stored.
-
When you edit a static policy, you can change only certain elements of a
static policy:
- The action referenced by the policy.
- A condition clause, such as when and unless.
- Changing a policy from a static policy to a template-linked policy.
- Changing the effect of a static policy from permit or forbid.
- The principal referenced by a static policy.
- The resource referenced by a static policy.
- To update a template-linked policy, you must update the template instead.
May throw ConflictException.
May throw ResourceNotFoundException.
May throw ServiceQuotaExceededException.
Parameter policyId :
Specifies the ID of the policy that you want to update. To find this
value, you can use ListPolicies.
You can use the policy name in place of the policy ID. When using a name,
prefix it with name/. For example:
-
ID:
SPEXAMPLEabcdefg111111 -
Name:
name/example-policy
Parameter policyStoreId :
Specifies the ID of the policy store that contains the policy that you
want to update.
To specify a policy store, use its ID or alias name. When using an alias
name, prefix it with policy-store-alias/. For example:
-
ID:
PSEXAMPLEabcdefg111111 -
Alias name:
policy-store-alias/example-policy-store
Parameter definition :
Specifies the updated policy content that you want to replace on the
specified policy. The content must be valid Cedar policy language text.
If you don't specify this parameter, the existing policy definition remains unchanged.
You can change only the following elements from the policy definition:
-
The
actionreferenced by the policy. -
Any conditional clauses, such as
whenorunlessclauses.
-
Changing from
statictotemplateLinked. -
Changing the effect of the policy from
permitorforbid. -
The
principalreferenced by the policy. -
The
resourcereferenced by the policy.
Parameter name :
Specifies a name for the policy that is unique among all policies within
the policy store. You can use the name in place of the policy ID in API
operations that reference the policy. The name must be prefixed with
name/.
If you specify a name that is already associated with another policy in
the policy store, you receive a ConflictException error.
Implementation
Future<UpdatePolicyOutput> updatePolicy({
required String policyId,
required String policyStoreId,
UpdatePolicyDefinition? definition,
String? name,
}) async {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'VerifiedPermissions.UpdatePolicy'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'policyId': policyId,
'policyStoreId': policyStoreId,
if (definition != null) 'definition': definition,
if (name != null) 'name': name,
},
);
return UpdatePolicyOutput.fromJson(jsonResponse.body);
}