Skip to main content

Manage Resources

A resource in Shield looks like

{
"resource": {
"id": "5723e961-7259-48b3-b721-292868d652d7",
"name": "test-random-name",
"project": {
"id": "1b89026b-6713-4327-9d7e-ed03345da288",
"name": "",
"slug": "",
"orgId": "",
"metadata": null,
"createdAt": null,
"updatedAt": null
},
"organization": {
"id": "4eb3c3b4-962b-4b45-b55b-4c07d3810ca8",
"name": "",
"slug": "",
"metadata": null,
"createdAt": null,
"updatedAt": null
},
"namespace": {
"id": "entropy/firehose",
"name": "",
"createdAt": null,
"updatedAt": null
},
"createdAt": "2022-12-13T11:59:23.964065Z",
"updatedAt": "2022-12-13T11:59:23.964065Z",
"user": {
"id": "2fd7f306-61db-4198-9623-6f5f1809df11",
"name": "",
"slug": "",
"email": "",
"metadata": null,
"createdAt": null,
"updatedAt": null
},
"urn": "r/entropy/firehose/test-random-name"
}
}

API Interface

Create resources

There are two ways to create a resource in the shield,

API Interface

$ curl --location --request POST 'http://localhost:8000/admin/v1beta1/resources'
--header 'Content-Type: application/json'
--header 'Accept: application/json'
--header 'X-Shield-Email: admin@gotocompany.com'
--data-raw '{
"name": "test-resource-beta",
"projectId": "1b89026b-6713-4327-9d7e-ed03345da288",
"namespaceId": "entropy/firehose",
"relations": [
{
"subject": "user:john.doe@gotocompany.com",
"roleName": "owner"
}
]
}'

Proxy Hook

Users can add hooks to rules set to create a resource. The hook will be called after the proxy request is completed. Hooks can read query, header, params, payload, and response to get the values for Resource.

- name: test-res
path: /test-res
target: "http://127.0.0.1:3000/"
methods: ["POST"]
frontends:
- name: create test-res
path: "/test-res"
method: "POST"
hooks:
- name: authz
config:
attributes:
project:
key: project
type: json_payload
organization:
key: organization
type: json_payload
team:
key: team
type: json_payload
resource:
key: urns.#.id
type: json_payload

List resources

$ curl --location --request GET 'http://localhost:8000/admin/v1beta1/resources'
--header 'Accept: application/json'

Get resources

$ curl -curl --location --request GET 'http://localhost:8000/admin/v1beta1/resources/28105b9a-1717-47cf-a5d9-49249b6638df'
--header 'Accept: application/json'

Update resource

$ curl --location --request PUT 'http://localhost:8000/admin/v1beta1/resources/a9f784cf-0f29-486f-92d0-51300295f7e8'
--header 'Content-Type: application/json'
--header 'Accept: application/json'
--data-raw '{
"name": "test-resource-beta1",
"projectId": "1b89026b-6713-4327-9d7e-ed03345da288",
"namespaceId": "entropy/firehose"
}'