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

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

Open
wants to merge 48 commits into
base: master
Choose a base branch
from

Conversation

davidalexandru7013
Copy link

@davidalexandru7013 davidalexandru7013 commented Aug 26, 2024

Description of changes

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

  • Project - Retrieve a single project.
  • Project - Update a single project
  • Project - Delete a project
  • Project - Add a tag to a project
  • Project - Remove a tag from a project
  • Project - Apply attributes to a project
    Right now, update a project, add/remove tag and apply attributes will use the same client method, patch. Because previously you could add/delete an individual tag, now you need to append/filter to the existing tags to keep the same functionality.

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:

  • change the structure of the project class to match the REST API response.
  • add/remove a tag methods are changed to ensure the same functionality as in v1.
  • a guide with changes necessary for customers can be found at the end of README.MD file.

Technical details

  • Project entity match the REST API response schema.
  • Updated old tests.
  • Write more tests for update scenarios.
  • Project manager will use the rest api for migrated endpoints.
  • Updated documentation to work with the new project class.
  • Added example of how to update an existing project and guide about how to migrate from the old project class to the new one.
  • Deprecate the old examples which uses the old issue API, which does not exists anymore.
  • Added the possibility for users to pass query parameters for the ProjectManager class methods.

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")

@davidalexandru7013 davidalexandru7013 changed the title Enhancement: customers can use the rest api for the project entity. Enhancement: customers will use the rest api for the project entity. Aug 26, 2024
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.

1 participant