snyk-labs / pysnyk

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

Enhancement: customers will use the rest api for the project entity. #220

Open davidalexandru7013 opened 2 weeks ago

davidalexandru7013 commented 2 weeks ago

Description of changes

In this modification, customers will use the rest api for requests regarding the project entity. There requests are:

Breaking changes

Because the old API schema does not match the REST API schema, the project entity needs to be changed and some operations such as:

Technical details

Context

These changes were made to enable customers use the REST API, because v1 is approaching its end of life and to benefit of REST API's advanteges, such as filtering, caching & pagination. It provides more flexibility to the developers who wants to interact with different instances of Snyk APIs.

How to test

The app can be tested using the examples provided below.

Example usage

Update an existing project:

client: SnykClient = SnykClient(token)
client.organizations.get(org_id).projects.update(project_id, tags=[{"key":"tag key", "value":"tag value"}], environment=[], business_criticality=["critical","low","medium"], lifecycle=["development","production"], test_frequency="daily", owner_id=owner_id)

Filter the projects using query params:

client: SnykClient = SnykClient(token)
client.projects.filter(tags=[{"key": "key1", "value": "value1"}], environment=["backend", "frontend"])

Filter using get all method:

params = {"tags": [{"key": "key tag", "value": "value1"}], "environment": ["frontend", "backend"]}
client.projects.all(params=params)

Add a new tag to a project:

proj = client.projects.get(project_id)
proj.tags.add("added_tag_key", "added_tag_value")

Remove an existing tag from a project:

proj = client.projects.get(project_id)
proj.tags.delete("added_tag_key", "added_tag_value")