Skip to content

Commit

Permalink
🎉 Implement Ruff (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-sommer authored Nov 25, 2024
1 parent 916e210 commit ed64ba1
Show file tree
Hide file tree
Showing 30 changed files with 657 additions and 618 deletions.
22 changes: 0 additions & 22 deletions .flake8

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/flake8.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Ruff Linter

on: [push, pull_request]

jobs:
ruff-linting:
runs-on: ubuntu-latest
name: Ruff Lint
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Ruff Linter
run: pip install -r requirements-lint.txt

- name: Run Ruff Linter
run: ruff check --output-format=github .
30 changes: 15 additions & 15 deletions apicomponents/acl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class ACL(object):
class ACL:

def put_acl(self, team, project):
"""[Adds an ACL mapping]
"""
[Adds an ACL mapping]
Args:
team ([string]): [name of the team]
Expand All @@ -13,28 +14,28 @@ def put_acl(self, team, project):

if response.status_code == 200:
return response.status_code
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
elif response.status_code == 404:
if response.status_code == 404:
return (f"The UUID of the team or project could not be found, {response.status_code}")
elif response.status_code == 409:
if response.status_code == 409:
return (f"A mapping with the same team and project already exists, {response.status_code}")
else:
return ((response.content).decode("UTF-8"),
response.status_code)
return ((response.content).decode("UTF-8"),
response.status_code)

def get_acl(self, uuid, excludeInactive=False):
"""[Returns the projects assigned to the specified team]
"""
[Returns the projects assigned to the specified team]
Args:
uuid ([string]): [The UUID of the team to retrieve mappings for]
"""
response = self.session.get(self.apicall + f"/v1/acl/team/{uuid}?excludeInactive={excludeInactive}")
if response.status_code == 200:
return response.json()
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
elif response.status_code == 404:
if response.status_code == 404:
return (f"The UUID of the team could not be found, {response.status_code}")

def delete_acl(self, teamUuid, projectUuid):
Expand All @@ -49,9 +50,8 @@ def delete_acl(self, teamUuid, projectUuid):
self.apicall + f"/v1/acl/mapping/team/{teamUuid}/project/{projectUuid}")
if response.status_code == 200:
return ("successful operation")
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
elif response.status_code == 404:
if response.status_code == 404:
return (f"The UUID of the team or project could not be found, {response.status_code}")
else:
return ((response.content).decode("UTF-8"), response.status_code)
return ((response.content).decode("UTF-8"), response.status_code)
21 changes: 11 additions & 10 deletions apicomponents/analysis.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import json


class Analysis(object):
class Analysis:

def get_analysis(self, project, component, vulnerability):
"""Retrieves an analysis trail
"""
Retrieves an analysis trail
Args:
project (string): The UUID of the project
component (string): The UUID of the component
vulnerability (string): The UUID of the vulnerability
Returns:
json: """
json:
"""
response = self.session.get(self.apicall + "/v1/analysis/", params={"project": project, "component": component, "vulnerability": vulnerability})
if response.status_code == 200:
return response.json()
else:
return (f"{(response.content).decode('utf-8')}, {response.status_code}")
return (f"{(response.content).decode('utf-8')}, {response.status_code}")

def record_analysis(self, project, component, vulnerability, suppressed=False):
"""Retrieves an analysis trail
"""
Retrieves an analysis trail
Args:
project (string): The UUID of the project
Expand All @@ -39,10 +41,9 @@ def record_analysis(self, project, component, vulnerability, suppressed=False):
}
],
"isSuppressed": true
} """

}
"""
response = self.session.put(self.apicall + "/v1/analysis/", data=json.dump({"project": project, "component": component, "vulnerability": vulnerability, "suppressed": suppressed}))
if response.status_code == 200:
return response.json()
else:
return (f"{(response.content).decode('utf-8')}, {response.status_code}")
return (f"{(response.content).decode('utf-8')}, {response.status_code}")
26 changes: 13 additions & 13 deletions apicomponents/badge.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class Badge(object):
class Badge:

def get_badgeByname(self, name, version):
# TODO : follow up on response of this functionality
"""Returns current metrics for a specific project
"""
Returns current metrics for a specific project
Args:
name (string): The name of the project to query on
Expand All @@ -15,18 +16,18 @@ def get_badgeByname(self, name, version):
self.apicall + f"/v1/badge/vulns/project/{name}/{version}")
if response.status_code == 200:
return response.content
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
elif response.status_code == 404:
if response.status_code == 404:
return (f"The project could not be found, {response.status_code}")
elif response.status_code == 204:
if response.status_code == 204:
return (f"Badge support is disabled. No content will be returned, {response.status_code}")
else:
return ((response.content).decode("utf-8"), response.status_code)
return ((response.content).decode("utf-8"), response.status_code)

def get_badgeByuuid(self, uuid):
# TODO : follow up on response of this functionality
"""Returns current metrics for a specific project
"""
Returns current metrics for a specific project
Args:
uuid: The uuid of the project.
Expand All @@ -38,11 +39,10 @@ def get_badgeByuuid(self, uuid):
self.apicall + f"/v1/badge/vulns/project/{uuid}")
if response.status_code == 200:
return response.content
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
elif response.status_code == 404:
if response.status_code == 404:
return (f"The project could not be found, {response.status_code}")
elif response.status_code == 204:
if response.status_code == 204:
return (f"Badge support is disabled. No content will be returned, {response.status_code}")
else:
return ((response.content).decode("utf-8"), response.status_code)
return ((response.content).decode("utf-8"), response.status_code)
70 changes: 37 additions & 33 deletions apicomponents/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,71 @@
import json


class Bom(object):
class Bom:
def get_bom_token(self, uuid):
""" Determines if there are any tasks associated with the token that are being processed, or in the queue to be processed.
"""
Determines if there are any tasks associated with the token that are being processed, or in the queue to be processed.
This endpoint is intended to be used in conjunction with uploading a supported BOM document. Upon upload, a token will be returned. The token can then be queried using this endpoint to determine if any tasks (such as vulnerability analysis) is being performed on the BOM. A value of true indicates processing is occurring. A value of false indicates that no processing is occurring for the specified token. However, a value of false also does not confirm the token is valid, only that no processing is associated with the specified token.
Args:
uuid (string): The UUID of the token to query """
uuid (string): The UUID of the token to query
"""
response = self.session.get(self.apicall + f"/v1/bom/token/{uuid}")
if response.status_code == 200:
return response.json()
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
else:
return response.status_code
return response.status_code

def get_bom_project(self, uuid, format="json"):
"""Returns dependency metadata for a project in CycloneDX format
"""
Returns dependency metadata for a project in CycloneDX format
Args:
uuid (string): The UUID of the project to export
format (str, optional): . Defaults to "json". However by default API is xml
Returns:
xml or json: returns dependency metadata for a project in CycloneDX format in xml or json """
xml or json: returns dependency metadata for a project in CycloneDX format in xml or json
"""
response = self.session.get(self.apicall + f"/v1/bom/cyclonedx/project/{uuid}", params={"format": format})
if response.status_code == 200:
return response.json()
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
elif response.status_code == 403:
if response.status_code == 403:
return (f"Access to the specified project is forbidden, {response.status_code}")
elif response.status_code == 404:
if response.status_code == 404:
return (f"Project not found, {response.status_code}")
else:
return ((response.content).decode("utf-8"), response.status_code)
return ((response.content).decode("utf-8"), response.status_code)

def get_bom_component(self, uuid, format="json"):
"""Returns dependency metadata for a component in CycloneDX format
"""
Returns dependency metadata for a component in CycloneDX format
Args:
uuid (string): The UUID of the component to export
format (str, optional): . Defaults to "json". However by default API is xml
Returns:
xml or json: returns dependency metadata for a component in CycloneDX format in xml or json """
xml or json: returns dependency metadata for a component in CycloneDX format in xml or json
"""
response = self.session.get(self.apicall + f"/v1/bom/cyclonedx/component/{uuid}", params={"format": format})
if response.status_code == 200:
return response.json()
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
elif response.status_code == 403:
if response.status_code == 403:
return (f"Access to the specified component is forbidden, {response.status_code}")
elif response.status_code == 404:
if response.status_code == 404:
return (f"Component not found, {response.status_code}")
else:
return ((response.content).decode("utf-8"), response.status_code)
return ((response.content).decode("utf-8"), response.status_code)

def post_bom(self, project, projectName, projectVersion, body, autoCreate=True):
# TODO: refactor for formdata
"""Upload a supported bill of material format document. Expects CycloneDX along and a valid project UUID. If a UUID is not specified then the projectName and projectVersion must be specified. Optionally, if autoCreate is specified and ‘true’ and the project does not exist, the project will be created. In this scenario, the principal making the request will additionally need the PORTFOLIO_MANAGEMENT or PROJECT_CREATION_UPLOAD permission.
"""
Upload a supported bill of material format document. Expects CycloneDX along and a valid project UUID. If a UUID is not specified then the projectName and projectVersion must be specified. Optionally, if autoCreate is specified and ‘true’ and the project does not exist, the project will be created. In this scenario, the principal making the request will additionally need the PORTFOLIO_MANAGEMENT or PROJECT_CREATION_UPLOAD permission.
Args:
project (string[formData]): project
Expand All @@ -72,7 +76,8 @@ def post_bom(self, project, projectName, projectVersion, body, autoCreate=True):
autoCreate (bool, optional): create project if it does not exist", response". Defaults to True.
Returns:
response status code """
response status code
"""
data = dict()
data["project"] = project
data["projectName"] = projectName
Expand All @@ -82,17 +87,17 @@ def post_bom(self, project, projectName, projectVersion, body, autoCreate=True):
response = self.session.post(self.apicall + "/v1/bom", files=body)
if response.status_code == 200:
return ("successful operation")
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
elif response.status_code == 403:
if response.status_code == 403:
return (f"Access to the specified project is forbidden, {response.status_code}")
elif response.status_code == 404:
if response.status_code == 404:
return (f"Project not found, {response.status_code}")
else:
return ((response.content).decode("utf-8"), response.status_code)
return ((response.content).decode("utf-8"), response.status_code)

def put_bom(self, project, body):
"""Upload a supported bill of material format document. Expects CycloneDX along and a valid project UUID. If a UUID is not specified then the projectName and projectVersion must be specified. Optionally, if autoCreate is specified and ‘true’ and the project does not exist, the project will be created. In this scenario, the principal making the request will additionally need the PORTFOLIO_MANAGEMENT or PROJECT_CREATION_UPLOAD permission.
"""
Upload a supported bill of material format document. Expects CycloneDX along and a valid project UUID. If a UUID is not specified then the projectName and projectVersion must be specified. Optionally, if autoCreate is specified and ‘true’ and the project does not exist, the project will be created. In this scenario, the principal making the request will additionally need the PORTFOLIO_MANAGEMENT or PROJECT_CREATION_UPLOAD permission.
Args:
project (string): The UUID of the project
Expand All @@ -110,11 +115,10 @@ def put_bom(self, project, body):
self.apicall + "/v1/bom", data=json.dumps(data))
if response.status_code == 200:
return ("successful operation")
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
elif response.status_code == 403:
if response.status_code == 403:
return (f"Access to the specified project is forbidden, {response.status_code}")
elif response.status_code == 404:
if response.status_code == 404:
return (f"Project not found, {response.status_code}")
else:
return ((response.content).decode("utf-8"), response.status_code)
return ((response.content).decode("utf-8"), response.status_code)
7 changes: 3 additions & 4 deletions apicomponents/calculator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Calculator(object):
class Calculator:

def get_calculator(self, cvss):
"""
Expand All @@ -10,7 +10,6 @@ def get_calculator(self, cvss):
response = self.session.get(self.apicall + "/v1/calculator/cvss", params={"vector": cvss})
if response.status_code == 200:
return response.json()
elif response.status_code == 401:
if response.status_code == 401:
return (f"Unauthorized, {response.status_code}")
else:
return ((response.content).decode("UTF-8"), response.status_code)
return ((response.content).decode("UTF-8"), response.status_code)
Loading

0 comments on commit ed64ba1

Please sign in to comment.