Assign Policy
Sprint 3
Assign a policy to resources (data sources, datasets, queries, roles, users, workspaces).
Endpoint
POST /api/v1/policies/{policy_id}/assignments
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <access_token> |
Content-Type | Yes | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
policy_id | integer | Yes | Policy ID |
Request Body
{
"data_source_id": 1,
"role_id": 2,
"user_id": 5,
"is_active": true,
"metadata": {}
}
Parameters
At least one target resource must be specified.
| Field | Type | Required | Description |
|---|---|---|---|
data_source_id | integer | No | Data source ID |
dataset_id | integer | No | Dataset ID |
query_id | integer | No | Query ID |
role_id | integer | No | Role ID |
user_id | integer | No | User ID |
workspace_id | integer | No | Workspace ID |
is_active | boolean | No | Active status (default: true) |
metadata | object | No | Additional metadata |
Response
Success (201)
{
"success": true,
"data": {
"id": 1,
"policy_id": 1,
"data_source_id": 1,
"role_id": 2,
"role_name": "Analyst",
"user_id": 5,
"is_active": true,
"applied_at": "2024-12-01T09:00:00Z",
"applied_by_user_id": 1,
"metadata": {}
},
"message": "Policy assigned successfully"
}
Error Codes
| Status | Code | Description |
|---|---|---|
| 400 | BAD_REQUEST | Invalid request data - at least one target resource must be specified |
| 401 | UNAUTHORIZED | Invalid or missing authentication token |
| 500 | INTERNAL_SERVER_ERROR | Internal server error |
Validations
- At least one target resource (data_source_id, dataset_id, query_id, role_id, user_id, or workspace_id) must be specified
Features
- Assign to multiple resource types
- Organization-scoped access control
- Tracks who applied the assignment
Example
curl -X POST "https://api.rivergen.com/api/v1/policies/1/assignments" \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"data_source_id": 1,
"role_id": 2
}'
Related Endpoints
- Get Policy - View policy assignments
- Create Policy - Create policy with assignments