To start building up a query specifically for purposes, you can use the select() convenience method on Purpose itself.
The search will only run when you call the stream() method, which will then lazily-load each page of results into a stream.
(Optional) You can do any other operations you might do on a stream, such as filtering the results to ensure they are of a certain type.
This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.
List purposes
1 2 3 4 5 6 7 8 91011121314
frompyatlan.client.atlanimportAtlanClientfrompyatlan.model.assetsimportPurposefrompyatlan.model.fluent_searchimportCompoundQuery,FluentSearchclient=AtlanClient()search_request=(FluentSearch()# (1).where(CompoundQuery.active_assets()).where(CompoundQuery.asset_type(Purpose))# (2)).to_request()# (3)results=client.asset.search(search_request)# (4)forassetinresults:# (5)ifisinstance(asset,Purpose):# Do something with the Purpose
Begin building up a query combining multiple conditions.
Ensure that we include only objects of type Purpose.
Build this query into a new search request.
Run the search.
Page through the results (each asset in the results will be a purpose).
The findByName() method handles searching for the purpose based on its name, which could therefore return more than one result. You can also (optionally) provide a second parameter with a list of attributes to retrieve for each purpose.
The asset.find_purposes_by_name() method handles searching for the purpose based on its name, which could therefore return more than one result.
Retrieve a purpose
1
vallist=Purpose.findByName("Known Issues")// (1)
The findByName() method handles searching for the purpose based on its name, which could therefore return more than one result. You can also (optionally) provide a second parameter with a list of attributes to retrieve for each purpose.
You must provide the qualifiedName of the purpose.
You must provide the name of the purpose.
You must provide whether the purpose should be active (enabled) or deactivated after the update. Setting this to false will deactivate the purpose, while setting it to true will activate the purpose.
To then apply that activation / deactivation to the purpose in Atlan, call the save() method against the object you've built.
You must provide the qualified_name of the purpose.
You must provide the name of the purpose.
You must provide whether the purpose should be active (enabled) or deactivated after the update. Setting this to False will deactivate the purpose, while setting it to True will activate the purpose.
To then apply that activation / deactivation to the purpose in Atlan, call the save() method with the object you've built.
You must provide the qualifiedName of the purpose.
You must provide the name of the purpose.
You must provide whether the purpose should be active (enabled) or deactivated after the update. Setting this to false will deactivate the purpose, while setting it to true will activate the purpose.
To then apply that activation / deactivation to the purpose in Atlan, call the save() method against the object you've built.
For each embedded object, use the exact type name Purpose.
You must provide the qualifiedName of the purpose.
You must provide the name of the purpose.
You must provide whether the purpose should be active (enabled) or deactivated after the update. Setting this to false will deactivate the purpose, while setting it to true will activate the purpose.
Be careful to only add policies one-by-one to a purpose. While the SDKs will allow you to add them in bulk, currently this results in a purpose where only the final policy in the batch is active at the end of the operation.
Use the createMetadataPolicy() method to start building a metadata policy with the minimal required information.
You must give the policy a name.
You must provide the GUID of the purpose to attach this policy to.
Specify the type of policy (granting or denying the actions specified next).
Specify the set of permissions you want to allow (or deny) in this policy.
To include all permissions
If you want to include all permissions, you can simply use Arrays.asList(PurposeMetadataAction.values()).
(Optional) Specify the internal names of groups you want the policy to apply to. At least this or the list of users, or all users must be provided.
(Optional) Specify the usernames of users you want the policy to apply to. At least this or the list of groups, or all users must be provided.
(Optional) Apply this policy to all users. If this is set to true it will override the previous two parameters, or if false one of the previous two parameters (users or groups) must be specified.
To then add the policy to the purpose in Atlan, call the save() method against the policy object you've built.
Use the create_metadata_policy() method to start building a metadata policy with the minimal required information.
You must give the policy a name.
You must provide the GUID of the purpose to attach this policy to.
Specify the type of policy (granting or denying the actions specified next).
Specify the set of permissions you want to allow (or deny) in this policy.
Specify either the internal names of groups, the usernames of users, or this all_users option to control who you want the policy to apply to. At least one of these must be provided.
To then add the policy to the purpose in Atlan, call the save() method with the policy object you've built.
Use the createMetadataPolicy() method to start building a metadata policy with the minimal required information.
You must give the policy a name.
You must provide the GUID of the purpose to attach this policy to.
Specify the type of policy (granting or denying the actions specified next).
Specify the set of permissions you want to allow (or deny) in this policy.
To include all permissions
If you want to include all permissions, you can simply use PurposeMetadataAction.values().toList().
(Optional) Specify the internal names of groups you want the policy to apply to. At least this or the list of users, or all users must be provided.
(Optional) Specify the usernames of users you want the policy to apply to. At least this or the list of groups, or all users must be provided.
(Optional) Apply this policy to all users. If this is set to true it will override the previous two parameters, or if false one of the previous two parameters (users or groups) must be specified.
To then add the policy to the purpose in Atlan, call the save() method against the policy object you've built.
For each embedded object, use the exact type name AuthPolicy.
You must use a policy subcategory of metadata.
You must use a policy category of purpose.
Specify the type of policy (granting or denying the actions specified next).
You must use a policy service name of atlas_tag.
You must give the policy a name.
You must give the policy itself a qualifiedName, although this will be overwritten by a generated value by the back-end.
Specify the set of permissions you want to allow (or deny) in this policy.
To review available permissions
To review the available permissions, see the SDKs — for example, the PurposeMetadataAction enum in the Java SDK.
Use an embedded accessControl object to define the purpose to attach this policy to.
The embedded type name of the accessControl object must be exactly Purpose.
You must provide the GUID of the purpose to attach this policy to.
You must set the policy resource category to TAG.
You must specify at least one username in a policyUsers array or one internal group name in a policyGroups array. The special group public covers all users.
Use the createDataPolicy() method to start building a data policy with the minimal required information.
You must give the policy a name.
You must provide the GUID of the purpose to attach this policy to.
Specify the type of policy (granting, denying or masking the data of assets with the tags in the purpose).
(Optional) Specify the names of internal groups you want the policy to apply to. At least this or the list of users, or all users must be provided.
(Optional) Specify the usernames of users you want the policy to apply to. At least this or the list of groups, or all users must be provided.
(Optional) Apply this policy to all users. If this is set to true it will override the previous two parameters, or if false one of the previous two parameters (users or groups) must be specified.
If you set the policy type to DATA_MASK, you also need to chain on the type of masking you want to apply.
To then add the policy to the purpose in Atlan, call the save() method against the policy object you've built.
Add data policy to purpose
1 2 3 4 5 6 7 8 910111213
frompyatlan.client.atlanimportAtlanClientfrompyatlan.model.assetsimportPurposefrompyatlan.model.enumsimportAuthPolicyType,DataMaskingTypeclient=AtlanClient()data=Purpose.create_data_policy(# (1)name="Mask the data",# (2)purpose_id="3886a92c-2510-40ea-a14d-803d7ac1616b",# (3)policy_type=AuthPolicyType.DATA_MASK,# (4)all_users=True,# (5))data.policy_mask_type=DataMaskingType.HASH# (6)response=client.asset.save(data)# (7)
Use the create_data_policy() method to start building a data policy with the minimal required information.
You must give the policy a name.
You must provide the GUID of the purpose to attach this policy to.
Specify the type of policy (granting, denying or masking the data of assets with the tags in the purpose).
Specify either the names of internal groups, the usernames of users, or this all_users option to control who you want the policy to apply to. At least one of these must be provided.
If you set the policy type to DATAMASK, you also need to set the type of masking you want to apply.
To then add the policy to the purpose in Atlan, call the save() method with the policy object you've built.
Use the createDataPolicy() method to start building a data policy with the minimal required information.
You must give the policy a name.
You must provide the GUID of the purpose to attach this policy to.
Specify the type of policy (granting, denying or masking the data of assets with the tags in the purpose).
(Optional) Specify the names of internal groups you want the policy to apply to. At least this or the list of users, or all users must be provided.
(Optional) Specify the usernames of users you want the policy to apply to. At least this or the list of groups, or all users must be provided.
(Optional) Apply this policy to all users. If this is set to true it will override the previous two parameters, or if false one of the previous two parameters (users or groups) must be specified.
If you set the policy type to DATA_MASK, you also need to chain on the type of masking you want to apply.
To then add the policy to the purpose in Atlan, call the save() method against the policy object you've built.
{"entities":[// (1){"typeName":"AuthPolicy",// (2)"attributes":{"policySubCategory":"data",// (3)"policyCategory":"purpose",// (4)"policyType":"dataMask",// (5)"policyMaskType":"MASK_HASH",// (6)"policyServiceName":"atlas_tag",// (7)"name":"Mask the data",// (8)"qualifiedName":"Mask the data",// (9)"policyActions":["select"// (10)],"accessControl":{// (11)"typeName":"Purpose",// (12)"guid":"3886a92c-2510-40ea-a14d-803d7ac1616b"// (13)},"policyResourceCategory":"TAG",// (14)"policyGroups":["public"// (15)]}}]}
Wrap all updates in an entities array.
For each embedded object, use the exact type name AuthPolicy.
You must use a policy subcategory of metadata.
You must use a policy category of purpose.
Specify the type of policy (granting, denying or masking the data of assets with the tags in the purpose).
If you set the policy type to dataMask, you also need to set the type of masking you want to apply.
To review available masking options
To review the available masking options, see the SDKs — for example, the DataMaskingType enum in the Java SDK.
You must use a policy service name of atlas_tag.
You must give the policy a name.
You must give the policy itself a qualifiedName, although this will be overwritten by a generated value by the back-end.
Specify the set of permissions you want to allow (or deny) in this policy. A data policy for a purpose can only allow or deny select permissions.
Use an embedded accessControl object to define the purpose to attach this policy to.
The embedded type name of the accessControl object must be exactly Purpose.
You must provide the GUID of the purpose to attach this policy to.
You must set the policy resource category to TAG.
You must specify at least one username in a policyUsers array or one internal group name in a policyGroups array. The special group public covers all users.
Purpose.select()// (1).where(Purpose.NAME.eq("Known Issues"))// (2).includeOnResults(Purpose.POLICIES)// (3).includeOnRelations(AuthPolicy.NAME)// (4).includeOnRelations(AuthPolicy.POLICY_TYPE).includeOnRelations(AuthPolicy.POLICY_ACTIONS).includeOnRelations(AuthPolicy.POLICY_USERS).includeOnRelations(AuthPolicy.POLICY_GROUPS).stream()// (5).filter(a->ainstanceofPurpose).forEach(p->{// (6)Set<IAuthPolicy>policies=((Purpose)p).getPolicies();for(IAuthPolicypolicy:policies){// Do something with each policy}});
Start by selecting a purpose, here using a FluentSearch-based approach.
You can select the purpose by whatever you like, in this example we are selecting based on its name.
Include the policies for the purpose as part of the search results.
Include all the attributes you want about each policy on the relations of the search results. Here we are including the name, type, actions and users controlled by each policy.
You can then directly stream the results of the search.
For each result of the search (itself a Purpose), you can then retrieve its policies and iterate through them.
List all policies in a purpose
1 2 3 4 5 6 7 8 910111213141516171819202122
fromtypingimportcastfrompyatlan.client.atlanimportAtlanClientfrompyatlan.model.assetsimportAuthPolicy,Purposefrompyatlan.model.fluent_searchimportFluentSearchclient=AtlanClient()request=(FluentSearch().where(FluentSearch.asset_type(Purpose))# (1).where(Purpose.NAME.eq("Known Issues"))# (2).include_on_results(Purpose.POLICIES)# (3).include_on_relations(AuthPolicy.POLICY_TYPE)# (4).include_on_relations(AuthPolicy.POLICY_ACTIONS).include_on_relations(AuthPolicy.POLICY_USERS).include_on_relations(AuthPolicy.POLICY_GROUPS)).to_request()# (5)response=client.asset.search(request)# (6)forpinresponse:# (7)policies=cast(Purpose,p).policiesforpolicyinpolicies:# Do something with each policy
Start by selecting a purpose, here using a FluentSearch-based approach.
You can select the purpose by whatever you like, in this example we are selecting based on its name.
Include the policies for the purpose as part of the search results.
Include all the attributes you want about each policy on the relations of the search results. Here we are including the name, type, actions and users controlled by each policy.
You can then translate the FluentSearch into a search request.
Run a search using the search request.
For each result of the search (itself a Purpose), you can then retrieve its policies and iterate through them.
List all policies in a purpose
1 2 3 4 5 6 7 8 910111213141516
Purpose.select()// (1).where(Purpose.NAME.eq("Known Issues"))// (2).includeOnResults(Purpose.POLICIES)// (3).includeOnRelations(AuthPolicy.NAME)// (4).includeOnRelations(AuthPolicy.POLICY_TYPE).includeOnRelations(AuthPolicy.POLICY_ACTIONS).includeOnRelations(AuthPolicy.POLICY_USERS).includeOnRelations(AuthPolicy.POLICY_GROUPS).stream()// (5).filter{itisPurpose}.forEach{// (6)valpolicies=(itasPurpose).policiesfor(policyinpolicies){// Do something with each policy}}
Start by selecting a purpose, here using a FluentSearch-based approach.
You can select the purpose by whatever you like, in this example we are selecting based on its name.
Include the policies for the purpose as part of the search results.
Include all the attributes you want about each policy on the relations of the search results. Here we are including the name, type, actions and users controlled by each policy.
You can then directly stream the results of the search.
For each result of the search (itself a Purpose), you can then retrieve its policies and iterate through them.
You can select the purpose by whatever you like, in this example we are selecting based on its name.
Include the policies for the purpose as part of the search results.
Include all the attributes you want about each policy on the relations of the search results. Here we are including the name, type, actions and users controlled by each policy.