Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DG-1697: Adding endpoint for linking/unlink policy #3307

Closed
wants to merge 3 commits into from

Conversation

arpit-at
Copy link

@arpit-at arpit-at commented Jul 3, 2024

Change description

Created two new endpoints in the metastore:

  1. Unlink Policies
Endpoint: POST entity/{policy-id}/unlink-business-policy
Body: {"unlinkGuids":["assetId1", "assetId2"]}

2 Link Policies

Endpoint: POST entity/{policy-id}/link-business-policy
Body: {"linkGuids":["assetId1", "assetId2"]}

These endpoints link or unlink policies from a set of asset IDs with minimal operations:

  1. Verify if the request is from a service account.
  2. Loop through all assets.
  3. Load each asset.
  4. Link or unlink the policy.
  5. Increment or decrement the asset policies count.

Type of change

  • Bug fix (fixes an issue)
  • New feature (adds functionality)

Related issues

Checklists

Development

  • Lint rules pass locally
  • Application changes have been tested thoroughly
  • Automated tests covering modified code pass

Security

  • Security impact of change has been considered
  • Code follows company security practices and guidelines

Code review

  • [ x] Pull request has a descriptive title and context useful to a reviewer. Screenshots or screencasts are attached as necessary
  • "Ready for review" label attached and reviewers assigned
  • Changes have been reviewed by at least one other contributor
  • Pull request linked to task tracker where applicable

for (String guid : linkGuids) {
AtlasVertex ev = AtlasGraphUtilsV2.findByGuid(graph, guid);
if (ev != null) {
Set<String> existingValues = ev.getMultiValuedSetProperty("assetPolicyGUIDs", String.class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we already have created these attributes on Asset typeDef assetPolicyGUIDs & assetPoliciesCount?
If not then these will never be written to Cassandra & eventually not sync to ES as well

Either add new attributes on Asset OR in case you will run tests on custom tenant you can update typeDefs directly using API & pause typeDef seeder cron

for (String guid : linkGuids) {
AtlasVertex ev = AtlasGraphUtilsV2.findByGuid(graph, guid);
if (ev != null) {
Set<String> existingValues = ev.getMultiValuedSetProperty("assetPolicyGUIDs", String.class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this only required for writing assetPoliciesCount.
Instead, just fetch current assetPoliciesCount & add 1 & save it

@krsoninikhil
Copy link

Don't have the full context here so feel free to ignore this -- the policy-id in url feels like resource id for entity. Would it be more clear to restructure the url to -- entity/business-policy/{policy-id}/link. Unless policy is also an entity.

@arpit-at arpit-at force-pushed the policyendpointsmaster branch from 0497f0d to 83e7c34 Compare July 13, 2024 06:51
@arpit-at arpit-at force-pushed the policyendpointsmaster branch from 91cc113 to 72b591b Compare July 19, 2024 05:24
@arpit-at arpit-at closed this Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants