Skip to content

Commit

Permalink
Merge branch 'master' into feature/client-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dmuhs committed Mar 21, 2019
2 parents 5bb813f + 82bae73 commit 4f353fe
Show file tree
Hide file tree
Showing 34 changed files with 134 additions and 117 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ ENV/
.mypy_cache/
*.swp
.vscode/
.idea/
3 changes: 1 addition & 2 deletions pythx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
__email__ = "dominik.muhs@consensys.net"
__version__ = "0.1.0"


from pythx.config import config
from pythx.conf import config
from pythx.api.client import Client
from pythx.models.exceptions import (
PythXBaseException,
Expand Down
9 changes: 6 additions & 3 deletions pythx/api/client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
from datetime import datetime, timedelta
from datetime import datetime
from typing import Dict, List

import jwt

from pythx.api.handler import APIHandler
from pythx.config import config
from pythx.middleware.toolname import ClientToolNameMiddleware
from pythx.models import request as reqmodels
from pythx.models import response as respmodels

Expand All @@ -24,7 +24,10 @@ def __init__(
):
self.eth_address = eth_address
self.password = password
self.handler = handler or APIHandler(staging=staging)
self.handler = handler or APIHandler(
middlewares=[ClientToolNameMiddleware()],
staging=staging
)

self.access_token = access_token
self.refresh_token = refresh_token
Expand Down
2 changes: 0 additions & 2 deletions pythx/api/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

from pythx import config
from pythx.middleware.base import BaseMiddleware
from pythx.models import request as reqmodels
from pythx.models import response as respmodels
from pythx.models.exceptions import PythXAPIError


Expand Down
1 change: 0 additions & 1 deletion pythx/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from copy import copy
from distutils import spawn
from os import environ, path
from pprint import pprint
from subprocess import check_output

import click
Expand Down
4 changes: 4 additions & 0 deletions pythx/conf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from pythx.conf.base import PythXConfig


config = PythXConfig()
3 changes: 0 additions & 3 deletions pythx/config/base.py → pythx/conf/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from pythx.models import request as reqmodels


class PythXConfig(dict):
def __init__(self):
self["endpoints"] = {
Expand Down
4 changes: 0 additions & 4 deletions pythx/config/__init__.py

This file was deleted.

4 changes: 2 additions & 2 deletions pythx/middleware/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

class BaseMiddleware(abc.ABC):
@abc.abstractmethod
def process_request(self):
def process_request(self, req):
pass

@abc.abstractmethod
def process_response(self):
def process_response(self, resp):
pass
21 changes: 21 additions & 0 deletions pythx/middleware/toolname.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import logging
from pythx.middleware.base import BaseMiddleware


LOGGER = logging.getLogger("ClientToolNameMiddleware")


class ClientToolNameMiddleware(BaseMiddleware):
def __init__(self, name="pythx"):
LOGGER.debug("Initializing")
self.name = name

def process_request(self, req):
if req["method"] == "POST" and req["url"].endswith("/analyses"):
LOGGER.debug("Adding name %s to request", self.name)
req["payload"]["clientToolName"] = self.name
return req

def process_response(self, resp):
LOGGER.debug("Forwarding the response without any action")
return resp
4 changes: 1 addition & 3 deletions pythx/models/request/analysis_list.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import json
from datetime import datetime
from typing import Any, Dict, List
from typing import Any, Dict

import dateutil.parser

from pythx.models.exceptions import RequestValidationError
from pythx.models.request.base import BaseRequest
from pythx.models.util import dict_delete_none_fields

ANALYSIS_LIST_KEYS = ("offset", "dateFrom", "dateTo")

Expand Down
7 changes: 0 additions & 7 deletions pythx/models/request/analysis_status.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import json
from datetime import datetime
from typing import Any, Dict, List

import dateutil.parser

from pythx.models.exceptions import RequestValidationError
from pythx.models.request.base import BaseRequest
from pythx.models.util import dict_delete_none_fields


class AnalysisStatusRequest(BaseRequest):
Expand Down
6 changes: 1 addition & 5 deletions pythx/models/request/analysis_submission.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import json
import logging
from datetime import datetime
from typing import Any, Dict, List
from typing import Dict, List

import dateutil.parser

from pythx.models.exceptions import RequestValidationError
from pythx.models.request.base import BaseRequest
from pythx.models.util import dict_delete_none_fields, resolve_schema

Expand Down
10 changes: 4 additions & 6 deletions pythx/models/request/auth_login.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import json
from datetime import datetime
from typing import Any, Dict, List
from typing import Dict

import dateutil.parser

from pythx.models.exceptions import RequestValidationError
from pythx.models.request.base import BaseRequest
from pythx.models.util import dict_delete_none_fields, resolve_schema
from pythx.models.util import resolve_schema

AUTH_LOGIN_KEYS = ("ethAddress", "password")


class AuthLoginRequest(BaseRequest):
Expand Down
8 changes: 2 additions & 6 deletions pythx/models/request/auth_logout.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import json
from datetime import datetime
from typing import Any, Dict, List
from typing import Dict

import dateutil.parser

from pythx.models.exceptions import RequestValidationError
from pythx.models.request.base import BaseRequest
from pythx.models.util import dict_delete_none_fields, resolve_schema
from pythx.models.util import resolve_schema


class AuthLogoutRequest(BaseRequest):
Expand Down
8 changes: 2 additions & 6 deletions pythx/models/request/auth_refresh.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import json
from datetime import datetime
from typing import Any, Dict, List
from typing import Dict

import dateutil.parser

from pythx.models.exceptions import RequestValidationError
from pythx.models.request.base import BaseRequest
from pythx.models.util import dict_delete_none_fields, resolve_schema
from pythx.models.util import resolve_schema


class AuthRefreshRequest(BaseRequest):
Expand Down
8 changes: 0 additions & 8 deletions pythx/models/request/detected_issues.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import json
from datetime import datetime
from typing import Any, Dict, List

import dateutil.parser

from pythx.models.exceptions import RequestValidationError
from pythx.models.request.analysis_status import AnalysisStatusRequest
from pythx.models.util import dict_delete_none_fields


class DetectedIssuesRequest(AnalysisStatusRequest):
Expand Down
8 changes: 0 additions & 8 deletions pythx/models/request/oas.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import json
from datetime import datetime
from typing import Any, Dict, List

import dateutil.parser

from pythx.models.exceptions import RequestValidationError
from pythx.models.request.analysis_status import AnalysisStatusRequest
from pythx.models.request.base import BaseRequest
from pythx.models.util import dict_delete_none_fields


class OASRequest(BaseRequest):
Expand Down
9 changes: 0 additions & 9 deletions pythx/models/request/version.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import json
from datetime import datetime
from typing import Any, Dict, List

import dateutil.parser

from pythx.models.exceptions import RequestValidationError
from pythx.models.request.analysis_status import AnalysisStatusRequest
from pythx.models.request.base import BaseRequest
from pythx.models.util import dict_delete_none_fields


class VersionRequest(BaseRequest):
Expand Down
2 changes: 0 additions & 2 deletions pythx/models/response/analysis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json
from enum import Enum

import dateutil.parser
from inflection import underscore

from pythx.models.response.base import BaseResponse
Expand Down
3 changes: 1 addition & 2 deletions pythx/models/response/analysis_list.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import json
from typing import Any, Dict, List
from typing import List

from pythx.models.exceptions import ResponseValidationError
from pythx.models.response.analysis import Analysis
from pythx.models.response.base import BaseResponse
from pythx.models.response.issue import Issue, SourceFormat, SourceType
from pythx.models.util import resolve_schema

INDEX_ERROR_MSG = "Analysis at index {} was not fetched"
Expand Down
4 changes: 1 addition & 3 deletions pythx/models/response/analysis_submission.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from pythx.models.response.analysis import Analysis
import json
from typing import Any, Dict, List

from pythx.models.response.analysis import Analysis
from pythx.models.response.base import BaseResponse
from pythx.models.response.issue import Issue, SourceFormat, SourceType
from pythx.models.util import resolve_schema


Expand Down
4 changes: 1 addition & 3 deletions pythx/models/response/auth_login.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import json
from typing import Any, Dict, List
from typing import Dict

from pythx.models.response.analysis import Analysis
from pythx.models.response.base import BaseResponse
from pythx.models.response.issue import Issue, SourceFormat, SourceType
from pythx.models.util import resolve_schema


Expand Down
6 changes: 1 addition & 5 deletions pythx/models/response/auth_logout.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import json
from typing import Any, Dict, List
from typing import Dict

from pythx.models.exceptions import ResponseValidationError
from pythx.models.response.analysis import Analysis
from pythx.models.response.base import BaseResponse
from pythx.models.response.issue import Issue, SourceFormat, SourceType
from pythx.models.util import resolve_schema


class AuthLogoutResponse(BaseResponse):
Expand Down
4 changes: 1 addition & 3 deletions pythx/models/response/auth_refresh.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import json
from typing import Any, Dict, List
from typing import Dict

from pythx.models.response.analysis import Analysis
from pythx.models.response.base import BaseResponse
from pythx.models.response.issue import Issue, SourceFormat, SourceType
from pythx.models.util import resolve_schema


Expand Down
1 change: 0 additions & 1 deletion pythx/models/response/detected_issues.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
from typing import Any, Dict, List

from pythx.models.response.analysis import Analysis
from pythx.models.response.base import BaseResponse
from pythx.models.response.issue import Issue, SourceFormat, SourceType
from pythx.models.util import resolve_schema
Expand Down
4 changes: 1 addition & 3 deletions pythx/models/response/issue.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import json
from enum import Enum
from typing import Any, Dict, List, Tuple

from inflection import underscore
from typing import Any, Dict, List


class Severity(str, Enum):
Expand Down
4 changes: 1 addition & 3 deletions pythx/models/response/oas.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import json
from typing import Any, Dict, List
from typing import Dict

from pythx.models.response.analysis import Analysis
from pythx.models.response.base import BaseResponse
from pythx.models.response.issue import Issue, SourceFormat, SourceType
from pythx.models.util import resolve_schema


Expand Down
8 changes: 1 addition & 7 deletions pythx/models/response/version.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import json
from os import path
from typing import Any, Dict, List
from typing import Dict

import jsonschema

from pythx.models.exceptions import ResponseValidationError
from pythx.models.response.analysis import Analysis
from pythx.models.response.base import BaseResponse
from pythx.models.response.issue import Issue, SourceFormat, SourceType
from pythx.models.util import resolve_schema


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Click>=6.0
python-dateutil==2.7.5
python-dateutil==2.8.0
inflection==0.3.1
PyJWT==1.7.1
tabulate==0.8.3
Expand Down
14 changes: 7 additions & 7 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
-r requirements.txt

pip==18.1
pip==19.0.3
bumpversion==0.5.3
wheel==0.32.1
wheel==0.33.1
watchdog==0.9.0
coverage==4.5.1
Sphinx==1.8.1
twine==1.12.1
coverage==4.5.3
Sphinx==1.8.5
twine==1.13.0

pytest==3.8.2
pytest==4.3.1
pytest-cov==2.6.1
requests-mock==1.5.2
pytest-runner==4.2
pytest-runner==4.4
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
include_package_data=True,
keywords="pythx",
name="pythx",
packages=find_packages(include=["pythx"]),
packages=find_packages(),
setup_requires=setup_requirements,
test_suite="tests",
tests_require=test_requirements,
Expand Down

0 comments on commit 4f353fe

Please sign in to comment.