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

api: adds CRUD operations for policy labels #54

Merged
merged 7 commits into from
Dec 23, 2024

Conversation

ashwiniag
Copy link
Member

@ashwiniag ashwiniag commented Dec 22, 2024

closes #52

Introduces

As follows

Action Method Endpoint Description
Create POST /policies/{policy_id}/labels Add a new label to a policy.
Read (List) GET /policies/{policy_id}/labels List all labels for a specific policy.
Read (Multiple keys) GET /policies/{policy_id}/labels?key={key1}&key={key2} Returns labels matching the provided keys for the specified policy_id
Read (Detail) GET /policies/{policy_id}/labels/{key} Returns labels matching the provided single key for the specified policy_id
Update PUT /policies/{policy_id}/labels/{key} Update a specific label by key.
Delete DELETE /policies/{policy_id}/labels/{key} Delete a specific label by key.

cURL

curl -X POST \
-H "Authorization: Bearer letsdoit" \
-H "Content-Type: application/json" \
-d '{
  "key": "newkey",
  "value": "new_value"
}' \
http://localhost:8000/api/v1/policies/2fe7c0e8-e042-4e35-bb7f-1b0c20f40d59/labels

curl -X GET \
-H "Authorization: Bearer letsdoit" \
-H "Content-Type: application/json" \
http://localhost:8000/api/v1/policies/2fe7c0e8-e042-4e35-bb7f-1b0c20f40d59/labels


curl -X GET \
-H "Authorization: Bearer letsdoit" \
-H "Content-Type: application/json" \
http://localhost:8000/api/v1/policies/2fe7c0e8-e042-4e35-bb7f-1b0c20f40d59/labels?key=env&key=lts_version

curl -X GET \
-H "Authorization: Bearer letsdoit" \
-H "Content-Type: application/json" \
http://localhost:8000/api/v1/policies/2fe7c0e8-e042-4e35-bb7f-1b0c20f40d59/labels/lts_version

curl -X PUT \
-H "Authorization: Bearer letsdoit" \
-H "Content-Type: application/json" \
-d '{
  "key": "newkey",
  "value": "updated_value"
}' \
http://localhost:8000/api/v1/policies/2fe7c0e8-e042-4e35-bb7f-1b0c20f40d59/labels

curl -X PUT \
-H "Authorization: Bearer letsdoit" \
-H "Content-Type: application/json" \
-d '{
  "labels": [
    {"key": "lts_version", "value": "v1.0"},
    {"key": "team", "value": "gokakashi"}
  ]
}' \
http://localhost:8000/api/v1/policies/2fe7c0e8-e042-4e35-bb7f-1b0c20f40d59/labels

curl -X DELETE \
-H "Authorization: Bearer letsdoit" \
-H "Content-Type: application/json" \
-d '{
  "value": "v1.0"
}' \
http://localhost:8000/api/v1/policies/2fe7c0e8-e042-4e35-bb7f-1b0c20f40d59/labels/lts_version

POST /policies/{policy_id}/labels

Test Case Description Error Handling
Valid Input Ensure a new label is created successfully for a policy. ✅ Response contains key and value of the created label. ✅
Missing Required Fields Verify error when policy_id, key, or value is not provided. ✅ Returns 400 Bad Request. ✅
Duplicate Key for Same Policy ID Verify error when the same key already exists for the policy ID. ✅ Returns 409 Conflict. ✅

GET

Test Case Description Error Handling
List Valid Policy Labels Retrieve all labels for a policy ID. ✅ Returns a list of all labels with key and value. ✅
No Labels Found Verify behavior when no labels are associated with the policy ID. ✅ Returns an empty list. ✅
Get Specific Label Fetch a specific label by key for a policy ID. ✅ Response contains the key and value. ✅
Non-Existent Label or Policy ID Verify error when attempting to fetch a non-existent label or policy ID. ✅ Returns 404 Not Found. ✅

PUT

Test Case Description Error Handling
Update a Single Label Update a specific label's value for a given policy ID. ✅ Response contains the updated key and value. ✅
Replace All Labels Replace all labels for a policy ID with a new set of labels. ✅ Deletes existing labels, inserts new ones, and ensures success response. ✅
Invalid Input for Update Verify error when invalid policy ID, key, or value is provided. Returns 400 Bad Request. ✅

DELETE

Test Case Description Error Handling
Delete Existing Label Delete an existing label by key and value. ✅ Response indicates successful deletion. ✅
Delete Non-Existent Label Verify error when attempting to delete a non-existent label or policy ID. ✅ Returns 404 Not Found. ✅
Invalid Input for Delete Verify error when policy ID, key, or value is invalid or empty. 🔺 To be done later Returns 400 Bad Request. ✅

@ashwiniag ashwiniag changed the base branch from main to api-policies December 22, 2024 19:12
@ashwiniag ashwiniag requested a review from scriptnull December 22, 2024 19:27
@ashwiniag ashwiniag merged commit f3b7f34 into api-policies Dec 23, 2024
1 check passed
ashwiniag added a commit that referenced this pull request Dec 23, 2024
* adds schema for policies and policylabels and CRUD operations for policies

* improves the uuid logic in integrations

* adds api routers for policies

* adds policy label schema

* fix lints

* adds test cases

* adds test cases

* api: adds CRUD operations for policy labels (#54)

* adds CRUD operations for policylabels and logic dependent with policies

* adds updated schema

* fix lints

* fix lints

* fix lints

* fix condtion throw an error if label already exists and return the object as response

* adds test cases

* resolve conflicts
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.

api: crud operations for PolicyLabels
1 participant