lswapi 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lswapi/__init__.py +9 -0
- lswapi/aio/__init__.py +27 -0
- lswapi/aio/client.py +46 -0
- lswapi/aio/middleware.py +20 -0
- lswapi/aio/oauth.py +85 -0
- lswapi/httpie.py +43 -0
- lswapi/requests/__init__.py +21 -0
- lswapi/requests/oauth.py +12 -0
- lswapi/requests/session.py +49 -0
- lswapi-0.0.0.dist-info/LICENSE.txt +201 -0
- lswapi-0.0.0.dist-info/METADATA +114 -0
- lswapi-0.0.0.dist-info/RECORD +15 -0
- lswapi-0.0.0.dist-info/WHEEL +5 -0
- lswapi-0.0.0.dist-info/entry_points.txt +2 -0
- lswapi-0.0.0.dist-info/top_level.txt +1 -0
lswapi/__init__.py
ADDED
lswapi/aio/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from lswapi import __api_base_url__
|
|
2
|
+
from lswapi import __auth_token_url__
|
|
3
|
+
from lswapi.aio.client import LeasewebHttpClient
|
|
4
|
+
from lswapi.aio.middleware import LoggingMiddleware
|
|
5
|
+
from lswapi.aio.oauth import AccessTokenFileStore
|
|
6
|
+
from lswapi.aio.oauth import LeasewebOAuthMiddleware
|
|
7
|
+
from os import environ
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_leaseweb_api(api_key=None, client_id=None, client_secret=None, base_url=None, token_url=None, token_store=None):
|
|
11
|
+
base_url = base_url or environ.get("LSW_BASE_URL", __api_base_url__)
|
|
12
|
+
token_url = token_url or environ.get("LSW_AUTH_URL", __auth_token_url__)
|
|
13
|
+
token_store = token_store or environ.get("LSW_AUTH_TOKEN_STORE")
|
|
14
|
+
api_key = api_key or environ.get("LSW_API_KEY")
|
|
15
|
+
if api_key:
|
|
16
|
+
return LeasewebHttpClient(base_url, middlewares=[LoggingMiddleware(debug=False)], headers={"X-Lsw-Auth": api_key})
|
|
17
|
+
if not client_id or not client_secret:
|
|
18
|
+
raise Exception("No authentication method specified")
|
|
19
|
+
return LeasewebHttpClient(base_url, middlewares=[
|
|
20
|
+
LeasewebOAuthMiddleware(
|
|
21
|
+
client_id,
|
|
22
|
+
client_secret,
|
|
23
|
+
token_url,
|
|
24
|
+
store=AccessTokenFileStore(token_store) if token_store else None,
|
|
25
|
+
),
|
|
26
|
+
LoggingMiddleware(debug=False),
|
|
27
|
+
])
|
lswapi/aio/client.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from aiohttp import ClientSession
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class LeasewebHttpClient:
|
|
5
|
+
def __init__(self, *args, middlewares: list[callable] = [], **kwargs):
|
|
6
|
+
self.middlewares = middlewares
|
|
7
|
+
self.session = ClientSession(*args, **kwargs)
|
|
8
|
+
|
|
9
|
+
async def _run_middlewares(self, method, url, next_func, **kwargs):
|
|
10
|
+
async def middleware_chain(index, method, url, **kwargs):
|
|
11
|
+
if index < len(self.middlewares):
|
|
12
|
+
return await self.middlewares[index](
|
|
13
|
+
method, url, lambda m, u, **k: middleware_chain(index + 1, m, u, **k), **kwargs
|
|
14
|
+
)
|
|
15
|
+
return await next_func(method, url, **kwargs)
|
|
16
|
+
return await middleware_chain(0, method, url, **kwargs)
|
|
17
|
+
|
|
18
|
+
async def _request(self, method, url, **kwargs):
|
|
19
|
+
return await self.session.request(method, url, **kwargs)
|
|
20
|
+
|
|
21
|
+
async def request(self, method, url, **kwargs):
|
|
22
|
+
return await self._run_middlewares(method, url, self._request, **kwargs)
|
|
23
|
+
|
|
24
|
+
async def get(self, url, **kwargs):
|
|
25
|
+
return await self.request("GET", url, **kwargs)
|
|
26
|
+
|
|
27
|
+
async def post(self, url, **kwargs):
|
|
28
|
+
return await self.request("POST", url, **kwargs)
|
|
29
|
+
|
|
30
|
+
async def put(self, url, **kwargs):
|
|
31
|
+
return await self.request("PUT", url, **kwargs)
|
|
32
|
+
|
|
33
|
+
async def patch(self, url, **kwargs):
|
|
34
|
+
return await self.request("PATCH", url, **kwargs)
|
|
35
|
+
|
|
36
|
+
async def delete(self, url, **kwargs):
|
|
37
|
+
return await self.request("DELETE", url, **kwargs)
|
|
38
|
+
|
|
39
|
+
async def close(self):
|
|
40
|
+
await self.session.close()
|
|
41
|
+
|
|
42
|
+
async def __aenter__(self):
|
|
43
|
+
return self
|
|
44
|
+
|
|
45
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
46
|
+
await self.close()
|
lswapi/aio/middleware.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import logging
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class LoggingMiddleware:
|
|
6
|
+
def __init__(self, debug=False) -> None:
|
|
7
|
+
self.debug = debug
|
|
8
|
+
|
|
9
|
+
async def __call__(self, method, url, next_func, **kwargs):
|
|
10
|
+
start = time.monotonic()
|
|
11
|
+
response = await next_func(method, url, **kwargs)
|
|
12
|
+
end = time.monotonic()
|
|
13
|
+
logging.info(f"Request to {response.method} {response.url} took {(end - start):.3f} seconds and resulted in a {response.status} {response.reason}")
|
|
14
|
+
if self.debug:
|
|
15
|
+
for header, value in response.request_info.headers.items():
|
|
16
|
+
logging.debug(f">>> {header}: {value}")
|
|
17
|
+
logging.debug(f"<<< HTTP/{response.version.major}.{response.version.minor} {response.status} {response.reason}")
|
|
18
|
+
for header, value in response.headers.items():
|
|
19
|
+
logging.debug(f"<<< {header}: {value}")
|
|
20
|
+
return response
|
lswapi/aio/oauth.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import aiohttp
|
|
2
|
+
import asyncio
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
from lswapi.aio.client import LeasewebHttpClient
|
|
8
|
+
from lswapi.aio.middleware import LoggingMiddleware
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AccessTokenInMemoryStore:
|
|
12
|
+
def __init__(self):
|
|
13
|
+
self.token = None
|
|
14
|
+
|
|
15
|
+
async def load(self):
|
|
16
|
+
return self.token
|
|
17
|
+
|
|
18
|
+
async def save(self, token):
|
|
19
|
+
self.token = token
|
|
20
|
+
|
|
21
|
+
async def remove(self):
|
|
22
|
+
self.token = None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class AccessTokenFileStore:
|
|
26
|
+
def __init__(self, filepath):
|
|
27
|
+
self.token = None
|
|
28
|
+
self.filepath = filepath
|
|
29
|
+
self.lock = asyncio.Lock()
|
|
30
|
+
|
|
31
|
+
async def load(self):
|
|
32
|
+
async with self.lock:
|
|
33
|
+
if self.token:
|
|
34
|
+
return self.token
|
|
35
|
+
if not os.path.exists(self.filepath):
|
|
36
|
+
return None
|
|
37
|
+
with open(self.filepath, "r") as file:
|
|
38
|
+
try:
|
|
39
|
+
self.token = json.load(file)
|
|
40
|
+
except json.decoder.JSONDecodeError:
|
|
41
|
+
os.remove(self.filepath)
|
|
42
|
+
return self.token
|
|
43
|
+
|
|
44
|
+
async def save(self, token):
|
|
45
|
+
async with self.lock:
|
|
46
|
+
with open(self.filepath, "w") as file:
|
|
47
|
+
json.dump(token, file)
|
|
48
|
+
self.token = token
|
|
49
|
+
|
|
50
|
+
async def remove(self):
|
|
51
|
+
async with self.lock:
|
|
52
|
+
if os.path.exists(self.filepath):
|
|
53
|
+
os.remove(self.filepath)
|
|
54
|
+
self.token = None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class LeasewebOAuthMiddleware:
|
|
58
|
+
def __init__(self, client_id, client_secret, token_url, store=None):
|
|
59
|
+
self.client_id = client_id
|
|
60
|
+
self.client_secret = client_secret
|
|
61
|
+
self.token_url = token_url
|
|
62
|
+
self.store = store or AccessTokenInMemoryStore()
|
|
63
|
+
self.lock = asyncio.Lock()
|
|
64
|
+
|
|
65
|
+
async def __call__(self, method, url, next_func, **kwargs):
|
|
66
|
+
async with self.lock:
|
|
67
|
+
token = await self.store.load()
|
|
68
|
+
if not token or token.get("expires_at") < time.time():
|
|
69
|
+
token = await self.__fetch_access_token()
|
|
70
|
+
await self.store.save(token)
|
|
71
|
+
if "headers" not in kwargs:
|
|
72
|
+
kwargs["headers"] = {}
|
|
73
|
+
kwargs["headers"]["Authorization"] = "{token_type} {access_token}".format(**token)
|
|
74
|
+
return await next_func(method, url, **kwargs)
|
|
75
|
+
|
|
76
|
+
async def __fetch_access_token(self):
|
|
77
|
+
auth = aiohttp.BasicAuth(login=self.client_id, password=self.client_secret)
|
|
78
|
+
async with LeasewebHttpClient(auth=auth, middlewares=[LoggingMiddleware(debug=False)]) as client:
|
|
79
|
+
payload = {"grant_type": "client_credentials"}
|
|
80
|
+
response = await client.post(self.token_url, data=payload)
|
|
81
|
+
assert response.status == 200
|
|
82
|
+
token = await response.json()
|
|
83
|
+
token["issued_at"] = int(time.time())
|
|
84
|
+
token["expires_at"] = token["issued_at"] + token["expires_in"] - 10
|
|
85
|
+
return token
|
lswapi/httpie.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LswApi auth plugin for HTTPie.
|
|
3
|
+
"""
|
|
4
|
+
from httpie.plugins import AuthPlugin
|
|
5
|
+
from json import loads, dumps
|
|
6
|
+
from lswapi import __auth_token_url__
|
|
7
|
+
from lswapi.requests import fetch_access_token
|
|
8
|
+
from os import path
|
|
9
|
+
from time import time
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__token_store__ = path.expanduser("~/.lswapi.token")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class LswApiAuth(object):
|
|
16
|
+
def __init__(self, client_id, client_secret):
|
|
17
|
+
self.client_id = client_id
|
|
18
|
+
self.client_secret = client_secret
|
|
19
|
+
|
|
20
|
+
def __call__(self, r):
|
|
21
|
+
if path.exists(__token_store__):
|
|
22
|
+
with open(__token_store__, "r") as file:
|
|
23
|
+
token = loads(file.read())
|
|
24
|
+
if "expires_at" in token and token["expires_at"] > time():
|
|
25
|
+
r.headers["Authorization"] = "{token_type} {access_token}".format(**token)
|
|
26
|
+
return r
|
|
27
|
+
|
|
28
|
+
token = fetch_access_token(__auth_token_url__, self.client_id, self.client_secret)
|
|
29
|
+
|
|
30
|
+
with open(__token_store__, "w") as file:
|
|
31
|
+
file.write(dumps(token))
|
|
32
|
+
|
|
33
|
+
r.headers["Authorization"] = "{token_type} {access_token}".format(**token)
|
|
34
|
+
return r
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ApiAuthPlugin(AuthPlugin):
|
|
38
|
+
name = "LswApi Oauth"
|
|
39
|
+
auth_type = "lswapi"
|
|
40
|
+
description = "Leaseweb Api Oauth Authentication"
|
|
41
|
+
|
|
42
|
+
def get_auth(self, username, password):
|
|
43
|
+
return LswApiAuth(username, password)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from lswapi import __api_base_url__
|
|
2
|
+
from lswapi import __auth_token_url__
|
|
3
|
+
from lswapi.requests.session import LeasewebSession
|
|
4
|
+
from lswapi.requests.session import LeasewebApiKeyAuth
|
|
5
|
+
from os import environ
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_leaseweb_api(api_key=None, client_id=None, client_secret=None, base_url=None, token_url=None, token_store=None):
|
|
9
|
+
base_url = base_url or environ.get("LSW_BASE_URL", __api_base_url__)
|
|
10
|
+
token_url = token_url or environ.get("LSW_AUTH_URL", __auth_token_url__)
|
|
11
|
+
token_store = token_store or environ.get("LSW_AUTH_TOKEN_STORE", None)
|
|
12
|
+
api_key = api_key or environ.get("LSW_API_KEY")
|
|
13
|
+
if api_key:
|
|
14
|
+
api = LeasewebSession(base_url=base_url)
|
|
15
|
+
api.auth = (LeasewebApiKeyAuth(api_key))
|
|
16
|
+
return api
|
|
17
|
+
client_id = client_id or environ.get("LSW_CLIENT_ID")
|
|
18
|
+
client_secret = client_secret or environ.get("LSW_CLIENT_SECRET")
|
|
19
|
+
if client_id and client_secret:
|
|
20
|
+
return LeasewebSession(base_url=base_url, client_id=client_id, client_secret=client_secret, token_url=token_url, token_store=token_store)
|
|
21
|
+
raise Exception("No authentication method specified")
|
lswapi/requests/oauth.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from requests import post
|
|
2
|
+
from time import time
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def fetch_access_token(token_url, client_id, client_secret):
|
|
6
|
+
response = post(token_url, auth=(client_id, client_secret), data={"grant_type": "client_credentials"})
|
|
7
|
+
if response.status_code != 200:
|
|
8
|
+
raise Exception("Could not obtain an access token")
|
|
9
|
+
token = response.json()
|
|
10
|
+
token["created_at"] = int(time())
|
|
11
|
+
token["expires_at"] = token["created_at"] + token["expires_in"] - 10
|
|
12
|
+
return token
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from json import load, dump
|
|
2
|
+
from lswapi import __api_base_url__
|
|
3
|
+
from lswapi import __auth_token_url__
|
|
4
|
+
from lswapi.requests.oauth import fetch_access_token
|
|
5
|
+
from os import path
|
|
6
|
+
from requests import Session
|
|
7
|
+
from requests.auth import AuthBase
|
|
8
|
+
from time import time
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class LeasewebApiKeyAuth(AuthBase):
|
|
12
|
+
def __init__(self, lsw_auth_key):
|
|
13
|
+
self.lsw_auth_key = lsw_auth_key
|
|
14
|
+
|
|
15
|
+
def __call__(self, r):
|
|
16
|
+
r.headers["X-Lsw-Auth"] = self.lsw_auth_key
|
|
17
|
+
return r
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class LeasewebSession(Session):
|
|
21
|
+
access_token = None
|
|
22
|
+
|
|
23
|
+
def __init__(self, client_id=None, client_secret=None, base_url=None, token_url=None, token_store=None):
|
|
24
|
+
self.base_url = base_url or __api_base_url__
|
|
25
|
+
self.token_url = token_url or __auth_token_url__
|
|
26
|
+
self.token_store = token_store
|
|
27
|
+
self.client_id = client_id
|
|
28
|
+
self.client_secret = client_secret
|
|
29
|
+
super().__init__()
|
|
30
|
+
|
|
31
|
+
def _fetch_access_token(self):
|
|
32
|
+
if not self.access_token and self.token_store:
|
|
33
|
+
if path.exists(self.token_store):
|
|
34
|
+
with open(self.token_store, "r") as file:
|
|
35
|
+
self.access_token = load(file)
|
|
36
|
+
if self.access_token and self.access_token.get("expires_at") > time():
|
|
37
|
+
return self.access_token
|
|
38
|
+
self.access_token = fetch_access_token(self.token_url, self.client_id, self.client_secret)
|
|
39
|
+
if self.token_store:
|
|
40
|
+
with open(self.token_store, "w") as file:
|
|
41
|
+
dump(self.access_token, file)
|
|
42
|
+
return self.access_token
|
|
43
|
+
|
|
44
|
+
def request(self, method, url, data=None, headers={}, **kwargs):
|
|
45
|
+
if self.client_id and self.client_secret:
|
|
46
|
+
headers["Authorization"] = "{token_type} {access_token}".format(**self._fetch_access_token())
|
|
47
|
+
if not url.startswith("http"):
|
|
48
|
+
url = "{}/{}".format(self.base_url, url.lstrip("/"))
|
|
49
|
+
return super().request(method, url, headers=headers, data=data, **kwargs)
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {2015} {Arnoud Vermeer}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: lswapi
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: a python client library for easy leaseweb api access
|
|
5
|
+
Author-email: Nico Di Rocco <n.dirocco@global.leaseweb.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, http://developer.leaseweb.com
|
|
8
|
+
Project-URL: Issues, https://github.com/nrocco/lswapi
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
11
|
+
Classifier: Operating System :: Unix
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: Utilities
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE.txt
|
|
23
|
+
Provides-Extra: develop
|
|
24
|
+
Requires-Dist: flake8; extra == "develop"
|
|
25
|
+
Requires-Dist: pytest; extra == "develop"
|
|
26
|
+
Requires-Dist: pytest-cov; extra == "develop"
|
|
27
|
+
Requires-Dist: requests-mock; extra == "develop"
|
|
28
|
+
Requires-Dist: twine; extra == "develop"
|
|
29
|
+
Provides-Extra: httpie
|
|
30
|
+
Requires-Dist: httpie; extra == "httpie"
|
|
31
|
+
Provides-Extra: requests
|
|
32
|
+
Requires-Dist: requests; extra == "requests"
|
|
33
|
+
Provides-Extra: aio
|
|
34
|
+
Requires-Dist: aiodns; extra == "aio"
|
|
35
|
+
Requires-Dist: aiohttp; extra == "aio"
|
|
36
|
+
|
|
37
|
+
# lswapi (beta)
|
|
38
|
+
|
|
39
|
+
[](https://github.com/nrocco/lswapi/actions)
|
|
40
|
+
|
|
41
|
+
Python module to talk to Leaseweb's API.
|
|
42
|
+
|
|
43
|
+
For more information refer to the documentation available at
|
|
44
|
+
[http://developer.leaseweb.com]
|
|
45
|
+
|
|
46
|
+
This module contains two api clients:
|
|
47
|
+
|
|
48
|
+
1. One is based on the `requests` module.
|
|
49
|
+
2. The second one is based on the `aiohttp` module for asyncio support.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
Install the module using pip. This will not install `requests` or `aiohttp`.
|
|
55
|
+
|
|
56
|
+
pip install lswapi
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
You can install optional depencies, such as `aiohttp`:
|
|
60
|
+
|
|
61
|
+
pip install 'lswapi[aio]'
|
|
62
|
+
|
|
63
|
+
Or if you prefer to use `requests`:
|
|
64
|
+
|
|
65
|
+
pip install 'lswapi[requests]'
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Using requests
|
|
72
|
+
|
|
73
|
+
The `lswapi.requests.get_leaseweb_api` function creates an instance of the Leaseweb Api
|
|
74
|
+
object with the `X-Lsw-Auth` key. You can provide the api key as an argument
|
|
75
|
+
to `get_leaseweb_api`
|
|
76
|
+
|
|
77
|
+
$ python
|
|
78
|
+
>>> from lswapi.requests import get_leaseweb_api
|
|
79
|
+
>>> client = get_leaseweb_api(api_key="xxxx-xxx-xxxxxx")
|
|
80
|
+
>>> response = client.get("/bareMetals/v2/servers")
|
|
81
|
+
>>> servers = response.json()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
or get `LSW_API_KEY` from an environment variable:
|
|
85
|
+
|
|
86
|
+
$ LSW_API_KEY=xxxx-xxxx-xxxxx python
|
|
87
|
+
>>> from lswapi.requests import get_leaseweb_api
|
|
88
|
+
>>> client = get_leaseweb_api()
|
|
89
|
+
>>> response = client.get("/bareMetals/v2/servers")
|
|
90
|
+
>>> servers = response.json()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Using aiohttp
|
|
94
|
+
|
|
95
|
+
The `lswapi.aio.get_leaseweb_api` function creates an instance of the Leaseweb Api
|
|
96
|
+
object with the `X-Lsw-Auth` key. You can provide the api key as an argument
|
|
97
|
+
to `get_leaseweb_api` or via the environment variable `LSW_API_KEY`:
|
|
98
|
+
|
|
99
|
+
$ python -m asyncio
|
|
100
|
+
>>> from lswapi.aio import get_leaseweb_api
|
|
101
|
+
>>> client = get_leaseweb_api(api_key="xxxx-xxx-xxxxxx")
|
|
102
|
+
>>> response = await client.get("/bareMetals/v2/servers")
|
|
103
|
+
>>> servers = await response.json()
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
Contribute
|
|
107
|
+
----------
|
|
108
|
+
|
|
109
|
+
1. Fork it
|
|
110
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
111
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
112
|
+
4. Make sure that tests pass (`make test`)
|
|
113
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
|
114
|
+
6. Create new Pull Request
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
lswapi/__init__.py,sha256=o57b34nv4IxKyOgL4iDrRlfk7ds83-YLHwn5lLfNHCs,248
|
|
2
|
+
lswapi/httpie.py,sha256=SZYUwjTgQv5eoVz6iFm0mYZxXi7AT4CrPjaeoiJY27U,1308
|
|
3
|
+
lswapi/aio/__init__.py,sha256=OIeKBQ-XzLV7X_Gber2kIczxafahMx8btYTFlDjy35Q,1235
|
|
4
|
+
lswapi/aio/client.py,sha256=hmgfdKTeSCyZ2DWIjqBQZnu0ARBjxKstOvTcHcc5ut8,1661
|
|
5
|
+
lswapi/aio/middleware.py,sha256=7rv6h3AKmDvX0qY802kZX8_jKdg1YC3qpvGaoygNwbY,884
|
|
6
|
+
lswapi/aio/oauth.py,sha256=0X8vv90f8sCeDbmV63nBudVs90Uu8JHEILi-P_OFrf0,2817
|
|
7
|
+
lswapi/requests/__init__.py,sha256=904pTa4HDM12Y2a_e030nb4TJ4J_YYigb0UIJizDE1E,1105
|
|
8
|
+
lswapi/requests/oauth.py,sha256=_yaFrGnltf8oUOODwr3I-53PFt4Zi2BYujzIYAZdaa8,470
|
|
9
|
+
lswapi/requests/session.py,sha256=1l4fbxsXW9PEo-8wIzLlGmB7bTjMfPdr1hwW6wfMZcw,1932
|
|
10
|
+
lswapi-0.0.0.dist-info/LICENSE.txt,sha256=qZ_R2xwQRrWRCMKOYIENQg6Ut6OrTbUbPRYjIXxQ2Cs,11348
|
|
11
|
+
lswapi-0.0.0.dist-info/METADATA,sha256=zoZKgpcLdfyPjPZ2Wq4s9u9nppnrQ8uumhD1eA0XjYU,3645
|
|
12
|
+
lswapi-0.0.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
13
|
+
lswapi-0.0.0.dist-info/entry_points.txt,sha256=eeeNKrb1LeViGVEkN5E6nXNvQ978Cnvq-y7-04sZ8yE,69
|
|
14
|
+
lswapi-0.0.0.dist-info/top_level.txt,sha256=ORBjQqXOwVLbkUacU49uJ5IhbC64-xsz7Ut8cuOhXzc,7
|
|
15
|
+
lswapi-0.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lswapi
|