Skip to content

Commit

Permalink
Merge pull request #12 from donhui/pylint-0314
Browse files Browse the repository at this point in the history
fix some issues with pylint
  • Loading branch information
donhui committed Mar 14, 2023
2 parents 7def9d8 + f7a1d41 commit 151de9f
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 20 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Pylint
on: [push]
jobs:
Pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.7'
- run: pip install -r requirements-dev.txt
- run: pylint **/*.py
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,28 @@ classifiers = [
'Topic :: Software Development'
]

[project.optional-dependencies]
pylint = [
"pylint"
]

[project.urls]
homepage = "https://github.com/donhui/jfrog-xray-api"
repository = "https://github.com/donhui/jfrog-xray-api.git"
"Bug Tracker" = "https://github.com/donhui/jfrog-xray-api/issues"

[tool.setuptools.dynamic]
version = {file = ["version.txt"]}

[tool.pylint.format]
max-line-length = 120

[tool.pylint.design]
max-args = 10

[tool.pylint."messages control"]
disable = [
"missing-module-docstring",
"missing-class-docstring",
"missing-function-docstring",
]
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
pylint
2 changes: 1 addition & 1 deletion xray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from xray.scanning import XrayScanning


class XrayRestClient(object):
class XrayRestClient:
def __init__(self, *, base_url, username, password):
self.base_url = base_url
self._session = requests.Session()
Expand Down
5 changes: 4 additions & 1 deletion xray/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class PackageType:
from enum import Enum


class PackageType(Enum):
ALPINE = "alpine"
BOWER = "bower"
CHEF = "chef"
Expand Down
2 changes: 0 additions & 2 deletions xray/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def get_component_list_per_watch(self):
Gets a list of components associated with a specific watch
:return:
"""
pass

def get_artifact_dependency_graph(self, artifact_path: str):
"""
Expand Down Expand Up @@ -154,4 +153,3 @@ def export_component_details(self):
TODO
:return:
"""
pass
6 changes: 6 additions & 0 deletions xray/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class EnvNotExists(Exception):
pass


class ArgsException(Exception):
pass
19 changes: 13 additions & 6 deletions xray/issues.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from enum import Enum
from xray.utils.http import RestApiAccessor


class XrayIssueType:
class XrayIssueType(Enum):
SECURITY = 'Security'
VERSIONS = 'Versions'
PERFORMANCE = 'Performance'
OTHER = 'Other'


class XrayIssueSeverity:
class XrayIssueSeverity(Enum):
INFORMATION = 'Information'
LOW = 'Low'
MEDIUM = 'Medium'
Expand All @@ -33,7 +34,7 @@ def create_issue_event(self,
provider="Custom",
issue_type=XrayIssueType.SECURITY,
severity=XrayIssueSeverity.LOW,
cve_list=[]
cve_list=None
):
"""
Allows adding a custom issue
Expand All @@ -49,6 +50,8 @@ def create_issue_event(self,
:param cve_list:
:return:
"""
if cve_list is None:
cve_list = []
url = self.base_url + "/api/v1/events"
json_data = {
"id": issue_id,
Expand Down Expand Up @@ -83,8 +86,8 @@ def update_issue_event(self,
provider="Custom",
issue_type=XrayIssueType.SECURITY,
severity=XrayIssueSeverity.LOW,
cve_list=[],
source_list=[],
cve_list=None,
source_list=None,
):
"""
Allows an issue vendor to update an issue event
Expand All @@ -102,6 +105,10 @@ def update_issue_event(self,
:return:
"""
assert len(issue_id) > 0
if cve_list is None:
cve_list = []
if source_list is None:
source_list = []
url = self.base_url + "/api/v1/events/" + issue_id
json_data = {
"id": issue_id,
Expand Down Expand Up @@ -135,7 +142,7 @@ def get_issue_event(self, issue_id: str, api_version='v1'):
"""
assert len(issue_id) > 0
assert api_version in ['v1', 'v2']
url = self.base_url + "/api/{0}/events/{1}".format(api_version, issue_id)
url = self.base_url + f'/api/{api_version}/events/{issue_id}'
response = self.rest_get(
url
)
Expand Down
5 changes: 3 additions & 2 deletions xray/summary.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from xray.exceptions import ArgsException
from xray.utils.http import RestApiAccessor


Expand All @@ -20,7 +21,7 @@ def get_artifact_summary(self, **kwargs):
json_data['paths'] = kwargs['paths']

if "checksums" not in kwargs and "paths" not in kwargs:
raise Exception("checksums or paths cannot be null.")
raise ArgsException("checksums or paths cannot be null.")

response = self.rest_post(
url,
Expand All @@ -35,7 +36,7 @@ def get_build_summary(self, build_name: str, build_number: str):
:param build_number:
:return:
"""
url = self.base_url + "/api/v1/summary/build?build_name={0}&build_number={1}".format(build_name, build_number)
url = self.base_url + f'/api/v1/summary/build?build_name={build_name}&build_number={build_number}'
response = self.rest_get(
url
)
Expand Down
10 changes: 6 additions & 4 deletions xray/utils/env.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os

from xray.exceptions import EnvNotExists


def get_env(key):
v = os.getenv(key=key)
if v is None:
raise Exception('The environment %s does not exists.' % key)
return v
_value = os.getenv(key=key)
if _value is None:
raise EnvNotExists(f'The environment {key} does not exists.')
return _value
7 changes: 3 additions & 4 deletions xray/utils/http.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
class RestApiAccessor:
"""
Implements operations with REST API
"""

def __init__(self, base_url, session):
self._session = session
self.base_url = base_url

"""
Implements operations with REST API
"""

def rest_get(self,
url,
params=None,
Expand Down

0 comments on commit 151de9f

Please sign in to comment.