create_policy_template
¶
create_policy_template(
policy_store_id: PolicyStoreId,
statement: PolicyStatement,
*,
config_overrides: Optional[VerifiedPermissionsClientConfig] = None,
client_token: Optional[IdempotencyToken] = None,
description: Optional[PolicyTemplateDescription] = None,
name: Optional[PolicyTemplateName] = None,
) -> CreatePolicyTemplateOutput
Creates a policy template. A template can use placeholders for the principal and resource. A template must be instantiated into a policy by associating it with specific principals and resources to use for the placeholders. That instantiated policy can then be considered in authorization decisions. The instantiated policy works identically to any other policy, except that it is dynamically linked to the template. If the template changes, then any policies that are linked to that template are immediately updated as well.
Verified Permissions is eventually consistent . It can take a few seconds for a new or changed element to propagate through the service and be visible in the results of other Verified Permissions operations.
Parameters:
-
client_token(Optional[IdempotencyToken], default:None) –Specifies a unique, case-sensitive ID that you provide to ensure the idempotency of the request. This lets you safely retry the request without accidentally performing the same operation a second time. Passing the same value to a later call to an operation requires that you also pass the same value for all other parameters. We recommend that you use a UUID type of value..
If you don't provide this value, then Amazon Web Services generates a random one for you.
If you retry the operation with the same
ClientToken, but with different parameters, the retry fails with anConflictExceptionerror.Verified Permissions recognizes a
ClientTokenfor eight hours. After eight hours, the next request with the same parameters performs the operation again regardless of the value ofClientToken. -
policy_store_id(PolicyStoreId) –The ID of the policy store in which to create the policy template.
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
To view aliases, use ListPolicyStoreAliases.
-
-
description(Optional[PolicyTemplateDescription], default:None) –Specifies a description for the policy template.
-
statement(PolicyStatement) –Specifies the content that you want to use for the new policy template, written in the Cedar policy language.
-
name(Optional[PolicyTemplateName], default:None) –Specifies a name for the policy template that is unique among all policy templates within the policy store. You can use the name in place of the policy template ID in API operations that reference the policy template. The name must be prefixed with
name/.If you specify a name that is already associated with another policy template in the policy store, you receive a
ConflictExceptionerror.
Raises:
-
AccessDeniedException–You don't have sufficient access to perform this action.
-
InternalServerException–The request failed because of an internal error. Try your request again later
-
ThrottlingException–The request failed because it exceeded a throttling quota.
-
ValidationException–The request failed because one or more input parameters don't satisfy their constraint requirements. The output is provided as a list of fields and a reason for each field that isn't valid.
The possible reasons include the following:
-
UnrecognizedEntityType
The policy includes an entity type that isn't found in the schema.
-
UnrecognizedActionId
The policy includes an action id that isn't found in the schema.
-
InvalidActionApplication
The policy includes an action that, according to the schema, doesn't support the specified principal and resource.
-
UnexpectedType
The policy included an operand that isn't a valid type for the specified operation.
-
IncompatibleTypes
The types of elements included in a
set, or the types of expressions used in anif...then...elseclause aren't compatible in this context. -
MissingAttribute
The policy attempts to access a record or entity attribute that isn't specified in the schema. Test for the existence of the attribute first before attempting to access its value. For more information, see the has (presence of attribute test) operator in the Cedar Policy Language Guide.
-
UnsafeOptionalAttributeAccess
The policy attempts to access a record or entity attribute that is optional and isn't guaranteed to be present. Test for the existence of the attribute first before attempting to access its value. For more information, see the has (presence of attribute test) operator in the Cedar Policy Language Guide.
-
ImpossiblePolicy
Cedar has determined that a policy condition always evaluates to false. If the policy is always false, it can never apply to any query, and so it can never affect an authorization decision.
-
WrongNumberArguments
The policy references an extension type with the wrong number of arguments.
-
FunctionArgumentValidationError
Cedar couldn't parse the argument passed to an extension type. For example, a string that is to be parsed as an IPv4 address can contain only digits and the period character.
-
-
ConflictException–The request failed because another request to modify a resource occurred at the same time.
-
ResourceNotFoundException–The request failed because it references a resource that doesn't exist.
-
ServiceQuotaExceededException–The request failed because it would cause a service quota to be exceeded.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To create a policy template The following example creates a policy template that has a placeholder for the principal.
>>> client.create_policy_template(description='Template for research dept', policy_store_id='C7v5xMplfFH3i3e4Jrzb1a', statement='"AccessVacation"\npermit(\n principal in ?principal,\n action == Action::"view",\n resource == Photo::"VacationPhoto94.jpg"\n)\nwhen {\n principal has department && principal.department == "research"\n};', client_token='a1b2c3d4-e5f6-a1b2-c3d4-TOKEN1111111', name='name/example-policy-template')
Source code in docs_src/capo_verifiedpermissions/_services/verified_permissions.py
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 | |