snyk-labs / pysnyk

A Python client for the Snyk API.
https://snyk.docs.apiary.io/
MIT License
85 stars 116 forks source link

Enhancement: clients can use REST url for all methods #219

Open davidalexandru7013 opened 1 month ago

davidalexandru7013 commented 1 month ago

Description of changes

In this modification, I created the opportunity for users to decide between using v1 api or rest api route in the SnykClient. Previously, only the get method let user to use the rest api. Patch method was created for use cases in which the verb PATCH is necessary, thing that didn't exist previously.

Technical details

Context

These changes were made to enable users use the rest api, because v1 is approaching its end of life. It provides more flexibility to the developers who wants to interact with different instances of Snyk APIs.

How to test

This modification should not impact the existing functionality of the library. Everything should work as intended.

Example Usage

Update an existing project


client = SnykClient(token=api_key)
client.patch(
    f"orgs/org_id/projects/project_id",
    body={
        "data": {
            "attributes": {
                "business_criticality": ["critical", "medium", "low"],
                "tags": [
                    {"key": "keytest1", "value": "valuetest1"},
                    {"key": "keytest2", "value": "valuetest2"},
                ],
                "environment": ["backend", "frontend"],
                "lifecycle": ["development"],
            },
            "id": "project_id",
            "relationships": {},
            "type": "project",
        }
    },
)