From a2f4a4859301f66da262cfb3d96289cfae52db30 Mon Sep 17 00:00:00 2001 From: ankitsharma Date: Wed, 9 Jun 2021 17:33:00 +0530 Subject: [PATCH 1/4] Rest client for Policy --- tools/rest/policy.http | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tools/rest/policy.http diff --git a/tools/rest/policy.http b/tools/rest/policy.http new file mode 100644 index 00000000..febb393a --- /dev/null +++ b/tools/rest/policy.http @@ -0,0 +1,87 @@ +# -------HTTP REST CLIENT ------- +# https://marketplace.visualstudio.com/items?itemName=humao.rest-client + +## This script provides a few samples for calling policy. + + + +# ----------------------- +# OAUTH (Variables) +# ----------------------- +### +@login_base = login.microsoftonline.com/{{TENANT_ID}} +@oauth_token_host = {{login_base}}/oauth2/v2.0/token +@scopes = {{CLIENT_ID}}/.default openid profile offline_access + + + +# ----------------------- +# OAUTH refresh_token +# ----------------------- +### +# @name refresh +POST https://{{oauth_token_host}} HTTP/1.1 +Content-Type: application/x-www-form-urlencoded + +grant_type=refresh_token +&client_id={{CLIENT_ID}} +&client_secret={{CLIENT_SECRET}} +&refresh_token={{INITIAL_TOKEN}} +&scope={{scopes}} + + +# ----------------------- +# API (Variables) +# ----------------------- +### +@access_token = {{refresh.response.body.access_token}} +@ENDPOINT = https://{{OSDU_HOST}} +@POLICY_HOST = {{ENDPOINT}}/api/policy/v1 +@data_partition_id = opendes + +# ----------------------- +# API: Policies +# ----------------------- + +### +# @name getPolicies +GET {{POLICY_HOST}}/policies +Authorization: Bearer {{access_token}} +Accept: application/json +data-partition-id: {{data_partition_id}} + +### +# @name getPolicies - Search +GET {{POLICY_HOST}}/policies/search +Authorization: Bearer {{access_token}} +Accept: application/json +data-partition-id: {{data_partition_id}} + +### +# @name evaluate policy +POST {{POLICY_HOST}}/api/policy/v1/evaluations/query +data-partition-id: {{data_partition_id}} +Authorization: Bearer {{access_token}} +Accept: application/json +{ + "policyId" : "search", + "input": { + "groups" : [ + { + "name": "service.legal.user", + "description": "Datalake Legal users", + "email": "service.legal.user@opendes.contoso.com" + } + ], + "operation" : "view", + "record" : + { + "id" : "123", + "acl": "dummy", + "legal": "123", + "kind": "123.123service.legal.user", + "tags": "123" + } + +} +} \ No newline at end of file -- GitLab From 1d4eba3df37fa60e989bb90d6a2214525f70102e Mon Sep 17 00:00:00 2001 From: ankitsharma Date: Wed, 9 Jun 2021 17:36:17 +0530 Subject: [PATCH 2/4] Corrected url --- tools/rest/policy.http | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/rest/policy.http b/tools/rest/policy.http index febb393a..b7550059 100644 --- a/tools/rest/policy.http +++ b/tools/rest/policy.http @@ -59,10 +59,11 @@ data-partition-id: {{data_partition_id}} ### # @name evaluate policy -POST {{POLICY_HOST}}/api/policy/v1/evaluations/query +POST {{POLICY_HOST}}/evaluations/query data-partition-id: {{data_partition_id}} Authorization: Bearer {{access_token}} Accept: application/json + { "policyId" : "search", "input": { -- GitLab From 726da3f8d6382cc467186359ae559fc386ce1ac4 Mon Sep 17 00:00:00 2001 From: ankitsharma Date: Wed, 9 Jun 2021 19:26:08 +0530 Subject: [PATCH 3/4] Added new policy flow --- tools/rest/policy.http | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tools/rest/policy.http b/tools/rest/policy.http index b7550059..7199e8d1 100644 --- a/tools/rest/policy.http +++ b/tools/rest/policy.http @@ -84,5 +84,41 @@ Accept: application/json "tags": "123" } + } } -} \ No newline at end of file + +### +# @name Create policy +PUT {{POLICY_HOST}}/policies/test +data-partition-id: {{data_partition_id}} +Authorization: Bearer {{access_token}} +Accept: application/json + +package test + +default allow = false + +allow = true { + input.operation == "view" +} + +### +# @name getPolicies - test +GET {{POLICY_HOST}}/policies/test +Authorization: Bearer {{access_token}} +Accept: application/json +data-partition-id: {{data_partition_id}} + +### +# @name Delete policy +DELETE {{POLICY_HOST}}/policies/test +data-partition-id: {{data_partition_id}} +Authorization: Bearer {{access_token}} +Accept: application/json + +### +# @name getPolicies - test deleted +GET {{POLICY_HOST}}/policies/test +Authorization: Bearer {{access_token}} +Accept: application/json +data-partition-id: {{data_partition_id}} -- GitLab From 83e40bead10b2e1a3338e579776e67e705b35bdc Mon Sep 17 00:00:00 2001 From: ankitsharma Date: Wed, 9 Jun 2021 19:33:37 +0530 Subject: [PATCH 4/4] Updated policy name --- tools/rest/policy.http | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tools/rest/policy.http b/tools/rest/policy.http index 7199e8d1..9a4f3bc2 100644 --- a/tools/rest/policy.http +++ b/tools/rest/policy.http @@ -44,21 +44,21 @@ grant_type=refresh_token # ----------------------- ### -# @name getPolicies +# @name Get Policies GET {{POLICY_HOST}}/policies Authorization: Bearer {{access_token}} Accept: application/json data-partition-id: {{data_partition_id}} ### -# @name getPolicies - Search +# @name Get Policy - Search GET {{POLICY_HOST}}/policies/search Authorization: Bearer {{access_token}} Accept: application/json data-partition-id: {{data_partition_id}} ### -# @name evaluate policy +# @name Evaluate policy POST {{POLICY_HOST}}/evaluations/query data-partition-id: {{data_partition_id}} Authorization: Bearer {{access_token}} @@ -83,7 +83,6 @@ Accept: application/json "kind": "123.123service.legal.user", "tags": "123" } - } } @@ -95,15 +94,13 @@ Authorization: Bearer {{access_token}} Accept: application/json package test - default allow = false - allow = true { input.operation == "view" } ### -# @name getPolicies - test +# @name Get Policy - test GET {{POLICY_HOST}}/policies/test Authorization: Bearer {{access_token}} Accept: application/json @@ -117,8 +114,8 @@ Authorization: Bearer {{access_token}} Accept: application/json ### -# @name getPolicies - test deleted +# @name Get Deleted Policy - test GET {{POLICY_HOST}}/policies/test Authorization: Bearer {{access_token}} Accept: application/json -data-partition-id: {{data_partition_id}} +data-partition-id: {{data_partition_id}} \ No newline at end of file -- GitLab