@@ -201,14 +201,14 @@ Both entities are now listed under acme-corp.
201201QUERY=' mutation CreateEntity($input: CreateEntityInput!) { createEntity(input: $input) { id } }'
202202
203203PAYLOAD=$( jq -n --arg q " $QUERY " --arg tid " $TENANT_ID " \
204- ' {"query":$q,"variables":{"input":{"tenantId":$tid,"name":"alice","kind":"human"}}}' )
204+ ' {"query":$q,"variables":{"input":{"tenantId":$tid,"name":"alice","kind":"human","attributes":{} }}}' )
205205ALICE_ID=$( curl -s -X POST http://localhost:8080/graphql \
206206 -H " Content-Type: application/json" \
207207 -H " Authorization: Bearer $TOKEN " \
208208 -d " $PAYLOAD " | jq -r ' .data.createEntity.id' )
209209
210210PAYLOAD=$( jq -n --arg q " $QUERY " --arg tid " $TENANT_ID " \
211- ' {"query":$q,"variables":{"input":{"tenantId":$tid,"name":"billing-service","kind":"service"}}}' )
211+ ' {"query":$q,"variables":{"input":{"tenantId":$tid,"name":"billing-service","kind":"service","attributes":{} }}}' )
212212SERVICE_ID=$( curl -s -X POST http://localhost:8080/graphql \
213213 -H " Content-Type: application/json" \
214214 -H " Authorization: Bearer $TOKEN " \
@@ -251,14 +251,24 @@ The permission block appears in the list.
251251<summary ><strong >Using curl instead</strong ></summary >
252252
253253``` bash
254+ # Look up action IDs for read and write on resource objects
255+ AQ=' { actions(objectKind: "resource") { items { id name } } }'
256+ ACTION_IDS=$( curl -s -X POST http://localhost:8080/graphql \
257+ -H " Content-Type: application/json" \
258+ -H " Authorization: Bearer $TOKEN " \
259+ -d " $( jq -n --arg q " $AQ " ' {"query":$q}' ) " \
260+ | jq ' [.data.actions.items[] | select(.name == "read" or .name == "write") | .id]' )
261+
254262QUERY=' mutation CreatePermissionBlock($input: CreatePermissionBlockInput!) { createPermissionBlock(input: $input) { id } }'
255- PAYLOAD=$( jq -n --arg q " $QUERY " --arg rid " $ROLE_ID " \
256- ' {"query":$q,"variables":{"input":{"roleId ":$rid,"objectKind ":"resource ","actions":["read ","write"] ,"effect":"allow"}}}' )
263+ PAYLOAD=$( jq -n --arg q " $QUERY " --arg tid " $TENANT_ID " --argjson aids " $ACTION_IDS " \
264+ ' {"query":$q,"variables":{"input":{"tenantId ":$tid,"scopeMode ":"object_kind ","objectKind":"resource ","actionIds":$aids ,"effect":"allow"}}}' )
257265
258- curl -s -X POST http://localhost:8080/graphql \
266+ BLOCK_ID= $( curl -s -X POST http://localhost:8080/graphql \
259267 -H " Content-Type: application/json" \
260268 -H " Authorization: Bearer $TOKEN " \
261- -d " $PAYLOAD " | jq .
269+ -d " $PAYLOAD " | jq -r ' .data.createPermissionBlock.id' )
270+
271+ echo " Permission block: $BLOCK_ID "
262272```
263273
264274</details >
@@ -295,6 +305,16 @@ ROLE_ID=$(curl -s -X POST http://localhost:8080/graphql \
295305 -H " Content-Type: application/json" \
296306 -H " Authorization: Bearer $TOKEN " \
297307 -d " $PAYLOAD " | jq -r ' .data.createRole.id' )
308+
309+ # Attach the permission block created in the previous step
310+ ATTACH_QUERY=' mutation ReplaceRolePermissionBlocks($roleId: ID!, $permissionBlockIds: [ID!]!) { replaceRolePermissionBlocks(roleId: $roleId, permissionBlockIds: $permissionBlockIds) }'
311+ ATTACH_PAYLOAD=$( jq -n --arg q " $ATTACH_QUERY " --arg rid " $ROLE_ID " --arg bid " $BLOCK_ID " \
312+ ' {"query":$q,"variables":{"roleId":$rid,"permissionBlockIds":[$bid]}}' )
313+
314+ curl -s -X POST http://localhost:8080/graphql \
315+ -H " Content-Type: application/json" \
316+ -H " Authorization: Bearer $TOKEN " \
317+ -d " $ATTACH_PAYLOAD " | jq .
298318```
299319
300320</details >
0 commit comments