Skip to content

Commit 1008ffa

Browse files
author
Markus Bong
authored
Merge pull request #15 from devolo/development
Bump version
2 parents f342517 + 258e988 commit 1008ffa

19 files changed

+134
-94
lines changed

.github/workflows/convert_todos_to_issues.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/pythonpackage.yml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,3 @@ jobs:
6363
- name: Test with pytest
6464
run: |
6565
pytest --cov=ssllabs
66-
- name: Preserve coverage
67-
uses: actions/upload-artifact@v2
68-
with:
69-
name: coverage
70-
path: .coverage
71-
72-
# coverage:
73-
# name: Upload coverage
74-
# runs-on: ubuntu-latest
75-
# needs: test
76-
# steps:
77-
# - name: Checkout sources
78-
# uses: actions/checkout@v2
79-
# - name: Set up Python
80-
# uses: actions/setup-python@v2
81-
# with:
82-
# python-version: 3.8
83-
# - name: Download coverage
84-
# uses: actions/download-artifact@v2
85-
# with:
86-
# name: coverage
87-
# - name: Coveralls
88-
# run: |
89-
# python -m pip install --upgrade pip
90-
# pip install wheel coveralls==1.10.0
91-
# export COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_TOKEN }}
92-
# coveralls
93-
# - name: Clean up coverage
94-
# uses: geekyeggo/delete-artifact@v1
95-
# with:
96-
# name: coverage

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
repos:
22
- repo: https://github.com/pre-commit/mirrors-yapf
3-
rev: ''
3+
rev: 'v0.30.0'
44
hooks:
55
- id: yapf
66
- repo: https://github.com/pycqa/isort
7-
rev: ''
7+
rev: '5.7.0'
88
hooks:
99
- id: isort
1010
- repo: https://github.com/pre-commit/pre-commit-hooks
11-
rev: ''
11+
rev: 'v3.4.0'
1212
hooks:
1313
- id: end-of-file-fixer
1414
- id: trailing-whitespace

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,7 @@ async def get_grade():
153153
```
154154

155155
Classes are called like the [API call](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#protocol-calls) without the leading get. The get method will query the API. It will take the parameters like in the documentation and return a dataclass representing the object, the API describes. One exception in the naming: the getEndpointData call is implemented in the Endpoint class to be able to better distinguish it from its EndpointData result object.
156+
157+
## Exceptions
158+
159+
Three types of exceptions might hit you, if the connection to SSL Labs' API is affected: ```httpx.ConnectTimeout``` or ```httpx.ReadTimeout``` appear, if the servers are down, and ```httpx.HTTPStatusError``` appears, if there is a client or server [error response](https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#error-response-status-codes). In this cases, you are asked to wait 15 to 30 minutes before you try again.

docs/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [v0.3.0] - 2021/02/08
8+
9+
### Added
10+
11+
- Query used API version with ssllabs.api.API_VERSION
12+
- Low level methods now can reuse an existing AsyncClient instance
13+
14+
### Fixed
15+
16+
- Fix dataclasses for certain situations
17+
718
## [v0.2.0] - 2021/01/28
819

920
### Added

ssllabs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .ssllabs import Ssllabs
22

33
__license__ = "MIT"
4-
__version__ = "0.2.0"
4+
__version__ = "0.3.0"
55

66
__all__ = ['Ssllabs', "__license__", "__version__"]

ssllabs/api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from ._api import API_VERSION
12
from .analyze import Analyze
23
from .endpoint import Endpoint
34
from .info import Info
45
from .root_certs_raw import RootCertsRaw
56
from .status_codes import StatusCodes
67

7-
__all__ = ["Analyze", "Endpoint", "Info", "RootCertsRaw", "StatusCodes"]
8+
__all__ = ["API_VERSION", "Analyze", "Endpoint", "Info", "RootCertsRaw", "StatusCodes"]

ssllabs/api/_api.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import asyncio
21
import logging
32
from abc import ABC
3+
from typing import KeysView, Optional
44

55
import httpx
66

@@ -11,16 +11,24 @@
1111
class _Api(ABC):
1212
"""Abstract class to communicate with Qualys SSL Labs Assessment APIs."""
1313

14-
def __init__(self):
15-
self.logger = logging.getLogger(f"{self.__class__.__module__}.{self.__class__.__name__}")
16-
self.client = httpx.AsyncClient()
17-
18-
def __del__(self):
19-
loop = asyncio.get_event_loop()
20-
loop.create_task(self.client.aclose())
14+
def __init__(self, client: Optional[httpx.AsyncClient] = None):
15+
self._logger = logging.getLogger(f"{self.__class__.__module__}.{self.__class__.__name__}")
16+
self._client = client
2117

2218
async def _call(self, api_endpoint: str, **kwargs) -> httpx.Response:
2319
"""Invocate API."""
24-
r = await self.client.get(f"{SSLLABS_URL}{api_endpoint}", params=kwargs)
20+
if self._client:
21+
r = await self._client.get(f"{SSLLABS_URL}{api_endpoint}", params=kwargs)
22+
else:
23+
async with httpx.AsyncClient() as client:
24+
r = await client.get(f"{SSLLABS_URL}{api_endpoint}", params=kwargs)
2525
r.raise_for_status()
2626
return r
27+
28+
def _verify_kwargs(self, given: KeysView, known: list):
29+
"""Log warning, if an argument is unknown."""
30+
for arg in given:
31+
if arg not in known:
32+
self._logger.warning(
33+
"Argument '%s' is not known by the SSL Labs API. It will be send, but the results might be unexpected.",
34+
arg)

ssllabs/api/analyze.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ async def get(self, host: str, **kwargs) -> HostData:
3030
:key ignoreMismatch: Set to "on" to proceed with assessments even when the server certificate doesn't match the
3131
assessment hostname. Set to off by default. Please note that this parameter is ignored if a
3232
cached report is returned.
33+
:raises httpx.ConnectTimeout: SSL Labs Servers don't respond.
34+
:raises httpx.HTTPStatusError: A client or server error response occured.
35+
:raises httpx.ReadTimeout: SSL Labs Servers don't respond.
3336
"""
37+
self._verify_kwargs(kwargs.keys(), ["publish", "startNew", "fromCache", "maxAge", "all", "ignoreMismatch"])
3438
r = await self._call("analyze", host=host, **kwargs)
3539
return from_dict(data_class=HostData, data=r.json())

ssllabs/api/endpoint.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ async def get(self, host: str, s: str, **kwargs) -> EndpointData:
1818
:key fromCache: Always deliver cached assessment reports if available; optional, defaults to "off". This parameter is
1919
intended for API consumers that don't want to wait for assessment results. Can't be used at the same
2020
time as the startNew parameter.
21+
:raises httpx.ConnectTimeout: SSL Labs Servers don't respond.
22+
:raises httpx.HTTPStatusError: A client or server error response occured.
23+
:raises httpx.ReadTimeout: SSL Labs Servers don't respond.
2124
"""
25+
self._verify_kwargs(kwargs.keys(), ["fromCache"])
2226
r = await self._call("getEndpointData", host=host, s=s, **kwargs)
2327
return from_dict(data_class=EndpointData, data=r.json())

0 commit comments

Comments
 (0)