-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathclient.py
More file actions
45 lines (37 loc) · 1.69 KB
/
client.py
File metadata and controls
45 lines (37 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import platform
import weakref
from .core import _init_client, _release_client
from .secrets_api import Secrets
SDK_LANGUAGE = "Python"
SDK_VERSION = "0010001" # v0.1.0
DEFAULT_INTEGRATION_NAME = "Unknown"
DEFAULT_INTEGRATION_VERSION = "Unknown"
DEFAULT_REQUEST_LIBRARY = "net/http"
DEFAULT_OS_VERSION = "0.0.0"
class Client:
"""A client"""
@classmethod
async def authenticate(cls, auth, integration_name, integration_version):
"""authenticate returns an authenticated client or errors if any provided information, including the SA token, is incorrect
`integration_name` represents the name of your application and `integration_version` represents the version of your application."""
self = cls()
self.config = new_default_config(auth=auth, integration_name=integration_name, integration_version=integration_version)
client_id = int(await _init_client(self.config))
self.secrets = Secrets(client_id)
self._finalizer = weakref.finalize(self, _release_client, client_id)
return self
def new_default_config(auth, integration_name, integration_version):
"""Generates a configuration dictionary with the user's parameters"""
client_config_dict = {
"serviceAccountToken": auth,
"programmingLanguage": SDK_LANGUAGE,
"sdkVersion": SDK_VERSION,
"integrationName": integration_name,
"integrationVersion": integration_version,
"requestLibraryName": DEFAULT_REQUEST_LIBRARY,
"requestLibraryVersion": platform.python_version(),
"os": platform.system().lower(),
"osVersion": DEFAULT_OS_VERSION,
"architecture": platform.machine(),
}
return client_config_dict