Skip to content

Commit

Permalink
Adjust linting (#110)
Browse files Browse the repository at this point in the history
* Adjust linting and black config

* Adjust GH action for linting
  • Loading branch information
Mark Beacom authored Mar 24, 2020
1 parent 480c4dd commit 96389f1
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 405 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ['3.7']
python-version: ['3.8']
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -34,4 +34,4 @@ jobs:
- name: Lint with Black
run: |
black --version
black --target-version py37 --check .
black --check .
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ push: ## Push the Docker image to the Docker Hub repository.
docker: build build_py38 ## Build and publish Docker images.

lint: isort ## Lint the CloudEndure project with Black.
@poetry run black --target-version py37 .
@poetry run black .

update_prereqs: ## Update the local development pre-requisite packages.
@pip install --upgrade wheel setuptools pip
Expand Down
38 changes: 9 additions & 29 deletions cloudendure/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,16 @@ def login(self, username: str = "", password: str = "", token: str = "") -> bool
return False

# Attempt to login to the CloudEndure API via a POST request.
response: requests.Response = self.api_call(
"login", "post", data=json.dumps(_auth)
)
response: requests.Response = self.api_call("login", "post", data=json.dumps(_auth))

# Check whether or not the request was successful.
if response.status_code not in [200, 307]:
if response.status_code == 401:
print(
"\nBad CloudEndure Credentials! Check your username/password and try again!\n"
)
print("\nBad CloudEndure Credentials! Check your username/password and try again!\n")
elif response.status_code == 402:
print(
"\nNo CloudEndure License! Please configure your account and try again!\n"
)
print("\nNo CloudEndure License! Please configure your account and try again!\n")
elif response.status_code == 429:
print(
"\nCloudEndure authentication failure limit reached! Please try again later!\n"
)
print("\nCloudEndure authentication failure limit reached! Please try again later!\n")
return False

# Grab the XSRF token received from the response, as stored in cookies.
Expand All @@ -155,11 +147,7 @@ def login(self, username: str = "", password: str = "", token: str = "") -> bool
return True

@staticmethod
def get_endpoint(
path: str,
api_version: str = "latest",
host: str = "https://console.cloudendure.com",
) -> str:
def get_endpoint(path: str, api_version: str = "latest", host: str = "https://console.cloudendure.com",) -> str:
"""Build the endpoint path.
Returns:
Expand All @@ -168,9 +156,7 @@ def get_endpoint(
"""
return f"{host}/api/{api_version}/{path}"

def api_call(
self, path: str, method: str = "get", data: Dict[str, Any] = None
) -> Response:
def api_call(self, path: str, method: str = "get", data: Dict[str, Any] = None) -> Response:
"""Handle CloudEndure API calls based on the defined parameters.
Args:
Expand All @@ -194,9 +180,7 @@ def api_call(
return Response()

if method not in ["get", "delete"] and not data:
print(
"Paramater mismatch! If calling anything other than get or delete provide data!"
)
print("Paramater mismatch! If calling anything other than get or delete provide data!")
return Response()

# Attempt to call the CloudEndure API.
Expand Down Expand Up @@ -238,17 +222,13 @@ def get_projects(self, current_project: str = "") -> List[Any]:
self.projects: List[Any] = projects

if current_project:
return list(
filter(lambda project: project["name"] == current_project, projects)
)
return list(filter(lambda project: project["name"] == current_project, projects))

return projects

@classmethod
def docs(self) -> str:
"""Open the CloudEndure API documentation page."""
docs_url: str = os.environ.get(
"CLOUDENDURE_API_DOCS", "https://console.cloudendure.com/api_doc/apis.html"
)
docs_url: str = os.environ.get("CLOUDENDURE_API_DOCS", "https://console.cloudendure.com/api_doc/apis.html")
open_new_tab(docs_url)
return docs_url
Loading

0 comments on commit 96389f1

Please sign in to comment.