scalekit-sdk-python 1.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.
- buf/__init__.py +0 -0
- buf/validate/__init__.py +0 -0
- buf/validate/expression_pb2.py +31 -0
- buf/validate/expression_pb2.pyi +34 -0
- buf/validate/expression_pb2_grpc.py +4 -0
- buf/validate/priv/__init__.py +0 -0
- buf/validate/priv/private_pb2.py +30 -0
- buf/validate/priv/private_pb2.pyi +25 -0
- buf/validate/priv/private_pb2_grpc.py +4 -0
- buf/validate/validate_pb2.py +402 -0
- buf/validate/validate_pb2.pyi +503 -0
- buf/validate/validate_pb2_grpc.py +4 -0
- scalekit/__init__.py +4 -0
- scalekit/client.py +143 -0
- scalekit/common/__init__.py +0 -0
- scalekit/common/scalekit.py +49 -0
- scalekit/common/user.py +75 -0
- scalekit/connection.py +103 -0
- scalekit/constants/__init__.py +0 -0
- scalekit/constants/user.py +21 -0
- scalekit/core.py +169 -0
- scalekit/domain.py +73 -0
- scalekit/organization.py +181 -0
- scalekit/v1/__init__.py +0 -0
- scalekit/v1/clients/__init__.py +0 -0
- scalekit/v1/clients/clients_pb2.py +103 -0
- scalekit/v1/clients/clients_pb2.pyi +156 -0
- scalekit/v1/clients/clients_pb2_grpc.py +232 -0
- scalekit/v1/commons/__init__.py +0 -0
- scalekit/v1/commons/commons_pb2.py +36 -0
- scalekit/v1/commons/commons_pb2.pyi +30 -0
- scalekit/v1/commons/commons_pb2_grpc.py +4 -0
- scalekit/v1/connections/__init__.py +0 -0
- scalekit/v1/connections/connections_pb2.py +355 -0
- scalekit/v1/connections/connections_pb2.pyi +526 -0
- scalekit/v1/connections/connections_pb2_grpc.py +265 -0
- scalekit/v1/domains/__init__.py +0 -0
- scalekit/v1/domains/domains_pb2.py +92 -0
- scalekit/v1/domains/domains_pb2.pyi +153 -0
- scalekit/v1/domains/domains_pb2_grpc.py +199 -0
- scalekit/v1/environments/__init__.py +0 -0
- scalekit/v1/environments/environments_pb2.py +171 -0
- scalekit/v1/environments/environments_pb2.pyi +241 -0
- scalekit/v1/environments/environments_pb2_grpc.py +463 -0
- scalekit/v1/errdetails/__init__.py +0 -0
- scalekit/v1/errdetails/errdetails_pb2.py +44 -0
- scalekit/v1/errdetails/errdetails_pb2.pyi +89 -0
- scalekit/v1/errdetails/errdetails_pb2_grpc.py +4 -0
- scalekit/v1/events/__init__.py +0 -0
- scalekit/v1/events/events_pb2.py +39 -0
- scalekit/v1/events/events_pb2.pyi +62 -0
- scalekit/v1/events/events_pb2_grpc.py +4 -0
- scalekit/v1/members/__init__.py +0 -0
- scalekit/v1/members/members_pb2.py +105 -0
- scalekit/v1/members/members_pb2.pyi +142 -0
- scalekit/v1/members/members_pb2_grpc.py +271 -0
- scalekit/v1/options/__init__.py +0 -0
- scalekit/v1/options/options_pb2.py +30 -0
- scalekit/v1/options/options_pb2.pyi +44 -0
- scalekit/v1/options/options_pb2_grpc.py +4 -0
- scalekit/v1/organizations/__init__.py +0 -0
- scalekit/v1/organizations/organizations_pb2.py +168 -0
- scalekit/v1/organizations/organizations_pb2.pyi +190 -0
- scalekit/v1/organizations/organizations_pb2_grpc.py +301 -0
- scalekit/v1/users/__init__.py +0 -0
- scalekit/v1/users/users_pb2.py +97 -0
- scalekit/v1/users/users_pb2.pyi +136 -0
- scalekit/v1/users/users_pb2_grpc.py +199 -0
- scalekit/v1/workspaces/__init__.py +0 -0
- scalekit/v1/workspaces/workspaces_pb2.py +90 -0
- scalekit/v1/workspaces/workspaces_pb2.pyi +102 -0
- scalekit/v1/workspaces/workspaces_pb2_grpc.py +198 -0
- scalekit_sdk_python-1.0.0.dist-info/LICENSE +21 -0
- scalekit_sdk_python-1.0.0.dist-info/METADATA +67 -0
- scalekit_sdk_python-1.0.0.dist-info/RECORD +77 -0
- scalekit_sdk_python-1.0.0.dist-info/WHEEL +5 -0
- scalekit_sdk_python-1.0.0.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class GrantType(Enum):
|
|
6
|
+
"""Enum class definition for Grant Types"""
|
|
7
|
+
|
|
8
|
+
AuthorizationCode = "authorization_code"
|
|
9
|
+
RefreshToken = "refresh_token"
|
|
10
|
+
ClientCredentials = "client_credentials"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AuthorizationUrlOptions:
|
|
14
|
+
"""Class definition for Authorization URL params"""
|
|
15
|
+
|
|
16
|
+
def __init__(self):
|
|
17
|
+
""" """
|
|
18
|
+
self.connection_id: Optional[str] = None
|
|
19
|
+
self.organization_id: Optional[str] = None
|
|
20
|
+
self.scopes: Optional[str] = None
|
|
21
|
+
self.state: Optional[str] = None
|
|
22
|
+
self.nonce: Optional[str] = None
|
|
23
|
+
self.domain_hint: Optional[str] = None
|
|
24
|
+
self.login_hint: Optional[str] = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class CodeAuthenticationOptions:
|
|
28
|
+
"""Class definition for Code Authentication URL params"""
|
|
29
|
+
|
|
30
|
+
def __init__(self):
|
|
31
|
+
""" """
|
|
32
|
+
self.code_verifier: Optional[str] = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class RefreshTokenAuthenticationOptions:
|
|
36
|
+
"""Class definition for Refresh Authentication option params"""
|
|
37
|
+
|
|
38
|
+
def __init__(self):
|
|
39
|
+
""" """
|
|
40
|
+
self.code: Optional[str] = None
|
|
41
|
+
self.redirect_uri: Optional[str] = None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class AuthenticationOptions:
|
|
45
|
+
"""Class definition for Authentication option params"""
|
|
46
|
+
|
|
47
|
+
def __init__(self):
|
|
48
|
+
""" """
|
|
49
|
+
self.refresh_token: Optional[str] = None
|
scalekit/common/user.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class User:
|
|
5
|
+
def __init__(self):
|
|
6
|
+
"""Class definition for user params"""
|
|
7
|
+
self.id: str
|
|
8
|
+
self.username: Optional[str] = None
|
|
9
|
+
self.name: Optional[str] = None
|
|
10
|
+
self.given_name: Optional[str] = None
|
|
11
|
+
self.family_name: Optional[str] = None
|
|
12
|
+
self.email: str
|
|
13
|
+
self.email_verified = bool
|
|
14
|
+
self.phone_number: Optional[str] = None
|
|
15
|
+
self.phone_number_verified = bool | None
|
|
16
|
+
self.profile: Optional[str] = None
|
|
17
|
+
self.picture: Optional[str] = None
|
|
18
|
+
self.gender: Optional[str] = None
|
|
19
|
+
self.birth_date: Optional[str] = None
|
|
20
|
+
self.zone_info: Optional[str] = None
|
|
21
|
+
self.locale: Optional[str] = None
|
|
22
|
+
self.updated_at: Optional[str] = None
|
|
23
|
+
self.identities = Identity()
|
|
24
|
+
self.metadata: Optional[str] = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Identity:
|
|
28
|
+
"""Class definition for identity params"""
|
|
29
|
+
|
|
30
|
+
def __init__(self):
|
|
31
|
+
""" """
|
|
32
|
+
self.connection_id = str
|
|
33
|
+
self.organization_id = str
|
|
34
|
+
self.connection_type = str
|
|
35
|
+
self.provider_name = str
|
|
36
|
+
self.social = bool
|
|
37
|
+
self.provider_raw_attributes = str
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class IdTokenClaimIdentity:
|
|
41
|
+
"""Class definition for ID token claim identity params"""
|
|
42
|
+
|
|
43
|
+
def __init__(self):
|
|
44
|
+
""" """
|
|
45
|
+
self.connection_id = str
|
|
46
|
+
self.organization_id = str
|
|
47
|
+
self.connection_type = str
|
|
48
|
+
self.provider_name = str
|
|
49
|
+
self.social = bool
|
|
50
|
+
self.provider_raw_attributes = str
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class IdTokenClaim:
|
|
54
|
+
""" """
|
|
55
|
+
|
|
56
|
+
def __init__(self):
|
|
57
|
+
"""Class definition for ID token claim params"""
|
|
58
|
+
self.sub = str
|
|
59
|
+
self.name = str
|
|
60
|
+
self.preferred_username: Optional[str] = None
|
|
61
|
+
self.given_name = str
|
|
62
|
+
self.family_name: Optional[str] = None
|
|
63
|
+
self.email = str
|
|
64
|
+
self.email_verified = bool
|
|
65
|
+
self.phone_number: Optional[str] = None
|
|
66
|
+
self.phone_number_verified = bool | None
|
|
67
|
+
self.profile: Optional[str] = None
|
|
68
|
+
self.picture: Optional[str] = None
|
|
69
|
+
self.gender: Optional[str] = None
|
|
70
|
+
self.birth_date: Optional[str] = None
|
|
71
|
+
self.zone_info: Optional[str] = None
|
|
72
|
+
self.locale: Optional[str] = None
|
|
73
|
+
self.updated_at: Optional[str] = None
|
|
74
|
+
self.identities: IdTokenClaimIdentity = None
|
|
75
|
+
self.metadata: Optional[str] = None
|
scalekit/connection.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
from scalekit.core import CoreClient
|
|
2
|
+
from scalekit.v1.connections.connections_pb2 import *
|
|
3
|
+
from scalekit.v1.connections.connections_pb2_grpc import ConnectionServiceStub
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ConnectionClient:
|
|
7
|
+
"""Class definition for Connection Client"""
|
|
8
|
+
|
|
9
|
+
def __init__(self, core_client: CoreClient):
|
|
10
|
+
"""
|
|
11
|
+
Initializer for connection client
|
|
12
|
+
|
|
13
|
+
:param core_client : CoreClient Object
|
|
14
|
+
:type : ``` obj ```
|
|
15
|
+
:returns
|
|
16
|
+
None
|
|
17
|
+
"""
|
|
18
|
+
self.core_client = core_client
|
|
19
|
+
self.connection_service = ConnectionServiceStub(
|
|
20
|
+
self.core_client.grpc_secure_channel
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
def get_connection(
|
|
24
|
+
self, organization_id: str, conn_id: str
|
|
25
|
+
) -> GetConnectionResponse:
|
|
26
|
+
"""
|
|
27
|
+
Method to get connection object
|
|
28
|
+
|
|
29
|
+
:param organization_id : Client organization id to get connection
|
|
30
|
+
:type : ``` str ```
|
|
31
|
+
:param conn_id : Client connection id to get connection
|
|
32
|
+
:type : ``` str ```
|
|
33
|
+
:returns
|
|
34
|
+
Connection Response
|
|
35
|
+
"""
|
|
36
|
+
return self.core_client.grpc_exec(
|
|
37
|
+
self.connection_service.GetConnection.with_call,
|
|
38
|
+
GetConnectionRequest(organization_id=organization_id, id=conn_id),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def list_connections_by_domain(self, domain: str) -> ListConnectionsResponse:
|
|
42
|
+
"""
|
|
43
|
+
Method to get connection object by domain
|
|
44
|
+
|
|
45
|
+
:param domain : Client domain id to get connection
|
|
46
|
+
:type : ``` str ```
|
|
47
|
+
:returns
|
|
48
|
+
List Connections Response
|
|
49
|
+
"""
|
|
50
|
+
return self.core_client.grpc_exec(
|
|
51
|
+
self.connection_service.ListConnections.with_call,
|
|
52
|
+
ListConnectionsRequest(domain=domain),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def list_connections(self, organization_id: str) -> ListConnectionsResponse:
|
|
56
|
+
"""
|
|
57
|
+
Method to list connections
|
|
58
|
+
|
|
59
|
+
:param organization_id : Client organization id to get connection
|
|
60
|
+
:type : ``` str ```
|
|
61
|
+
:returns:
|
|
62
|
+
List Connections Response
|
|
63
|
+
"""
|
|
64
|
+
return self.core_client.grpc_exec(
|
|
65
|
+
self.connection_service.ListConnections.with_call,
|
|
66
|
+
ListConnectionsRequest(organization_id=organization_id),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def enable_connection(
|
|
70
|
+
self, organization_id: str, conn_id: str
|
|
71
|
+
) -> ToggleConnectionResponse:
|
|
72
|
+
"""
|
|
73
|
+
Method to enable connection
|
|
74
|
+
|
|
75
|
+
:param organization_id : Client organization id to enable connection
|
|
76
|
+
:type : ``` str ```
|
|
77
|
+
:param conn_id : Client connection id to enable connection
|
|
78
|
+
:type : ``` str ```
|
|
79
|
+
:returns
|
|
80
|
+
Enable Connection Response
|
|
81
|
+
"""
|
|
82
|
+
return self.core_client.grpc_exec(
|
|
83
|
+
self.connection_service.EnableConnection.with_call,
|
|
84
|
+
ToggleConnectionRequest(organization_id=organization_id, id=conn_id),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def disable_connection(
|
|
88
|
+
self, organization_id: str, conn_id: str
|
|
89
|
+
) -> ToggleConnectionResponse:
|
|
90
|
+
"""
|
|
91
|
+
Method to disable connection
|
|
92
|
+
|
|
93
|
+
:param organization_id : Client organization id to disable connection
|
|
94
|
+
:type : ``` str ```
|
|
95
|
+
:param conn_id : Client connection id to disable connection
|
|
96
|
+
:type : ``` str ```
|
|
97
|
+
:returns
|
|
98
|
+
Disable Connection Response
|
|
99
|
+
"""
|
|
100
|
+
return self.core_client.grpc_exec(
|
|
101
|
+
self.connection_service.DisableConnection.with_call,
|
|
102
|
+
ToggleConnectionRequest(organization_id=organization_id, id=conn_id),
|
|
103
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
id_token_claim_to_user_map = {
|
|
3
|
+
"sub": "id",
|
|
4
|
+
"name": "name",
|
|
5
|
+
"preferred_username": "username",
|
|
6
|
+
"given_name": "givenName",
|
|
7
|
+
"family_name": "familyName",
|
|
8
|
+
"email": "email",
|
|
9
|
+
"email_verified": "emailVerified",
|
|
10
|
+
"phone_number": "phoneNumber",
|
|
11
|
+
"phone_number_verified": "phoneNumberVerified",
|
|
12
|
+
"profile": 'profile',
|
|
13
|
+
"picture": "picture",
|
|
14
|
+
"gender": "gender",
|
|
15
|
+
"birthdate": "birthDate",
|
|
16
|
+
"zoneinfo": "zoneInfo",
|
|
17
|
+
"locale": "locale",
|
|
18
|
+
"updated_at": "updatedAt",
|
|
19
|
+
"identities": "identities",
|
|
20
|
+
"metadata": "metadata"
|
|
21
|
+
}
|
scalekit/core.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
from typing import TypeVar, Optional, Protocol
|
|
2
|
+
|
|
3
|
+
import grpc
|
|
4
|
+
import jwt
|
|
5
|
+
import json
|
|
6
|
+
import requests
|
|
7
|
+
import platform
|
|
8
|
+
from urllib.parse import urlparse
|
|
9
|
+
from grpc_status import rpc_status
|
|
10
|
+
from scalekit.common.scalekit import GrantType
|
|
11
|
+
from scalekit.v1.errdetails.errdetails_pb2 import ErrorInfo
|
|
12
|
+
|
|
13
|
+
TRequest = TypeVar("TRequest")
|
|
14
|
+
TResponse = TypeVar("TResponse")
|
|
15
|
+
TMetadata = TypeVar("TMetadata")
|
|
16
|
+
|
|
17
|
+
TOKEN_ENDPOINT = "/oauth/token"
|
|
18
|
+
JWKS_ENDPOINT = "/keys"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class WithCall(Protocol):
|
|
22
|
+
def __call__(self, request: TRequest, metadata: TMetadata) -> TResponse: ...
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CoreClient:
|
|
26
|
+
"""Class definition for Core Client"""
|
|
27
|
+
|
|
28
|
+
sdk_version = "Scalekit-Python/0.1"
|
|
29
|
+
api_version = "20240430"
|
|
30
|
+
user_agent = f"{sdk_version} Python/{platform.python_version()} ({platform.system()}; {platform.architecture()}"
|
|
31
|
+
|
|
32
|
+
def __init__(self, env_url, client_id, client_secret):
|
|
33
|
+
"""
|
|
34
|
+
Initializer for Core client
|
|
35
|
+
|
|
36
|
+
:param env_url : Environment URL
|
|
37
|
+
:type : ``` str ```
|
|
38
|
+
:param client_id : Client ID
|
|
39
|
+
:type : ``` str ```
|
|
40
|
+
:param client_secret : Client Secret
|
|
41
|
+
:type : ``` str ```
|
|
42
|
+
:returns
|
|
43
|
+
None
|
|
44
|
+
"""
|
|
45
|
+
parsed_url = urlparse(env_url)
|
|
46
|
+
self.host = parsed_url.netloc
|
|
47
|
+
self.env_url = env_url
|
|
48
|
+
self.client_id = client_id
|
|
49
|
+
self.client_secret = client_secret
|
|
50
|
+
self.keys = {}
|
|
51
|
+
self.access_token = None
|
|
52
|
+
self.grpc_secure_channel = None
|
|
53
|
+
self.__authenticate_client()
|
|
54
|
+
self.__grpc_secure_channel()
|
|
55
|
+
|
|
56
|
+
def __grpc_secure_channel(self):
|
|
57
|
+
"""
|
|
58
|
+
Method to authenticate grpc and create secure grpc channel
|
|
59
|
+
:params
|
|
60
|
+
None
|
|
61
|
+
:returns
|
|
62
|
+
None
|
|
63
|
+
"""
|
|
64
|
+
channel_credentials = grpc.ssl_channel_credentials()
|
|
65
|
+
call_credentials = grpc.access_token_call_credentials(self.access_token)
|
|
66
|
+
composite_credentials = grpc.composite_channel_credentials(
|
|
67
|
+
channel_credentials,
|
|
68
|
+
call_credentials,
|
|
69
|
+
)
|
|
70
|
+
self.grpc_secure_channel = grpc.secure_channel(self.host, composite_credentials)
|
|
71
|
+
|
|
72
|
+
def __authenticate_client(self):
|
|
73
|
+
"""
|
|
74
|
+
Method to authenticate client and return access token
|
|
75
|
+
|
|
76
|
+
:returns
|
|
77
|
+
access_token
|
|
78
|
+
"""
|
|
79
|
+
params = {
|
|
80
|
+
"grant_type": GrantType.ClientCredentials.value,
|
|
81
|
+
"client_id": self.client_id,
|
|
82
|
+
"client_secret": self.client_secret,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
response = self.authenticate(data=json.dumps(params))
|
|
86
|
+
response = json.loads(response.content)
|
|
87
|
+
self.access_token = response["access_token"]
|
|
88
|
+
|
|
89
|
+
def authenticate(self, data: str):
|
|
90
|
+
"""
|
|
91
|
+
Method to execute post request for authentication with given user params
|
|
92
|
+
|
|
93
|
+
:param data : params for authentication request
|
|
94
|
+
:type : ``` str ```
|
|
95
|
+
"""
|
|
96
|
+
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
|
97
|
+
response = requests.post(
|
|
98
|
+
self.env_url + TOKEN_ENDPOINT,
|
|
99
|
+
headers=self.get_headers(headers=headers),
|
|
100
|
+
data=json.loads(data),
|
|
101
|
+
verify=True,
|
|
102
|
+
)
|
|
103
|
+
return response
|
|
104
|
+
|
|
105
|
+
def get_jwks(self):
|
|
106
|
+
"""Method to get JWT Keys"""
|
|
107
|
+
if self.keys and len(self.keys) > 0:
|
|
108
|
+
return
|
|
109
|
+
response = requests.get(
|
|
110
|
+
self.env_url + JWKS_ENDPOINT, headers=self.get_headers()
|
|
111
|
+
)
|
|
112
|
+
response = json.loads(response.content)
|
|
113
|
+
keys = response["keys"]
|
|
114
|
+
|
|
115
|
+
for key in keys:
|
|
116
|
+
kid = key["kid"]
|
|
117
|
+
self.keys[kid] = jwt.algorithms.RSAAlgorithm.from_jwk(json.dumps(key))
|
|
118
|
+
|
|
119
|
+
def grpc_exec(
|
|
120
|
+
self,
|
|
121
|
+
func: WithCall,
|
|
122
|
+
data: TRequest,
|
|
123
|
+
retry=1,
|
|
124
|
+
) -> TResponse:
|
|
125
|
+
try:
|
|
126
|
+
resp = func(
|
|
127
|
+
data,
|
|
128
|
+
metadata=tuple(self.get_headers().items()),
|
|
129
|
+
)
|
|
130
|
+
return resp
|
|
131
|
+
except grpc.RpcError as exp:
|
|
132
|
+
if retry > 0:
|
|
133
|
+
return self.grpc_exec(func, data, retry=retry - 1)
|
|
134
|
+
else:
|
|
135
|
+
status_code = exp.code()
|
|
136
|
+
status = rpc_status.from_call(exp)
|
|
137
|
+
messages = [status.message]
|
|
138
|
+
if status_code == grpc.StatusCode.INVALID_ARGUMENT:
|
|
139
|
+
for detail in status.details:
|
|
140
|
+
if detail.Is(ErrorInfo.DESCRIPTOR):
|
|
141
|
+
info = ErrorInfo()
|
|
142
|
+
detail.Unpack(info)
|
|
143
|
+
if info.validation_error_info:
|
|
144
|
+
for fv in info.validation_error_info.field_violations:
|
|
145
|
+
messages.append(f"{fv.field}: {fv.description}")
|
|
146
|
+
|
|
147
|
+
raise Exception("\n".join(messages))
|
|
148
|
+
except Exception as exp:
|
|
149
|
+
raise exp
|
|
150
|
+
|
|
151
|
+
def get_headers(self, headers: Optional[dict] = None) -> dict:
|
|
152
|
+
"""
|
|
153
|
+
Method to get user defined headers and returns collated header params
|
|
154
|
+
|
|
155
|
+
:param headers : User defined header dictionary
|
|
156
|
+
:type : ``` dict ```
|
|
157
|
+
:returns
|
|
158
|
+
dict
|
|
159
|
+
"""
|
|
160
|
+
default_headers = {
|
|
161
|
+
"user-agent": f"{self.user_agent}",
|
|
162
|
+
"x-api-version": f"{self.api_version}",
|
|
163
|
+
"x-sdk-version": f"{self.sdk_version}",
|
|
164
|
+
}
|
|
165
|
+
if self.access_token:
|
|
166
|
+
default_headers.update({"authorization": f"Bearer {self.access_token}"})
|
|
167
|
+
if headers:
|
|
168
|
+
return {**default_headers, **headers}
|
|
169
|
+
return default_headers
|
scalekit/domain.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
from scalekit.core import CoreClient
|
|
3
|
+
from scalekit.v1.domains.domains_pb2 import *
|
|
4
|
+
from scalekit.v1.domains.domains_pb2_grpc import DomainServiceStub
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class DomainClient:
|
|
8
|
+
"""Class definition for Domain Client"""
|
|
9
|
+
|
|
10
|
+
def __init__(self, core_client: CoreClient):
|
|
11
|
+
"""
|
|
12
|
+
Initializer for Domain Client
|
|
13
|
+
|
|
14
|
+
:param core_client : CoreClient Object
|
|
15
|
+
:type : ``` obj ```
|
|
16
|
+
:returns
|
|
17
|
+
None
|
|
18
|
+
"""
|
|
19
|
+
self.core_client = core_client
|
|
20
|
+
self.domain_service = DomainServiceStub(
|
|
21
|
+
self.core_client.grpc_secure_channel
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def create_domain(
|
|
25
|
+
self, organization_id: str, domain_name: str
|
|
26
|
+
) -> CreateDomainResponse:
|
|
27
|
+
"""
|
|
28
|
+
Method to create domain
|
|
29
|
+
|
|
30
|
+
:param organization_id : Organization id to create domain for
|
|
31
|
+
:type : ``` str ```
|
|
32
|
+
:param domain_name : Domain name for new creation
|
|
33
|
+
:type : ``` str ```
|
|
34
|
+
:returns
|
|
35
|
+
Domain Response
|
|
36
|
+
"""
|
|
37
|
+
return self.core_client.grpc_exec(
|
|
38
|
+
self.domain_service.CreateDomain.with_call,
|
|
39
|
+
CreateDomainRequest(
|
|
40
|
+
organization_id=organization_id,
|
|
41
|
+
domain=CreateDomain(domain=domain_name),
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def list_domains(self, organization_id: str) -> ListDomainResponse:
|
|
46
|
+
"""
|
|
47
|
+
Method to list existing domains
|
|
48
|
+
|
|
49
|
+
:param organization_id : Organization id to list domains for
|
|
50
|
+
:type : ``` str ```
|
|
51
|
+
:returns
|
|
52
|
+
List Domain Response
|
|
53
|
+
"""
|
|
54
|
+
return self.core_client.grpc_exec(
|
|
55
|
+
self.domain_service.ListDomains.with_call,
|
|
56
|
+
ListDomainRequest(organization_id=organization_id),
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
def get_domain(self, organization_id: str, domain_id: str) -> GetDomainResponse:
|
|
60
|
+
"""
|
|
61
|
+
Method to list existing domains
|
|
62
|
+
|
|
63
|
+
:param organization_id : Organization id to list domains for
|
|
64
|
+
:type : ``` str ```
|
|
65
|
+
:param domain_id : Domain name for new creation
|
|
66
|
+
:type : ``` str ```
|
|
67
|
+
:returns
|
|
68
|
+
Get Domain Response
|
|
69
|
+
"""
|
|
70
|
+
return self.core_client.grpc_exec(
|
|
71
|
+
self.domain_service.GetDomain.with_call,
|
|
72
|
+
GetDomainRequest(organization_id=organization_id, id=domain_id),
|
|
73
|
+
)
|
scalekit/organization.py
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from scalekit.core import CoreClient
|
|
4
|
+
from scalekit.v1.organizations.organizations_pb2 import *
|
|
5
|
+
from scalekit.v1.organizations.organizations_pb2_grpc import OrganizationServiceStub
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OrganizationClient:
|
|
9
|
+
"""Class definition for Organization Client"""
|
|
10
|
+
|
|
11
|
+
def __init__(self, core_client: CoreClient):
|
|
12
|
+
"""
|
|
13
|
+
Initializer for Organization Client
|
|
14
|
+
|
|
15
|
+
:param core_client : CoreClient Object
|
|
16
|
+
:type : ``` obj ```
|
|
17
|
+
:returns
|
|
18
|
+
None
|
|
19
|
+
"""
|
|
20
|
+
self.core_client = core_client
|
|
21
|
+
self.organization_service = OrganizationServiceStub(
|
|
22
|
+
self.core_client.grpc_secure_channel
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def list_organizations(
|
|
26
|
+
self, page_size: int, page_token: Optional[str] = None
|
|
27
|
+
) -> CreateOrganizationResponse:
|
|
28
|
+
"""
|
|
29
|
+
Method to list organizations
|
|
30
|
+
|
|
31
|
+
:param page_size : page size for org list fetch
|
|
32
|
+
:type : ``` int ```
|
|
33
|
+
:param page_token : page token for org list fetch
|
|
34
|
+
:type : ``` str ```
|
|
35
|
+
:returns:
|
|
36
|
+
list of organizations
|
|
37
|
+
"""
|
|
38
|
+
return self.core_client.grpc_exec(
|
|
39
|
+
self.organization_service.ListOrganization.with_call,
|
|
40
|
+
ListOrganizationsRequest(page_size=page_size, page_token=page_token),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def create_organization(
|
|
44
|
+
self, name: str, options: CreateOrganization
|
|
45
|
+
) -> CreateOrganizationResponse:
|
|
46
|
+
"""
|
|
47
|
+
Method to create organization based on given data
|
|
48
|
+
|
|
49
|
+
:param name : Name of the org to be created
|
|
50
|
+
:type : ``` str ```
|
|
51
|
+
:param options : Additional details for org to be created
|
|
52
|
+
:type : ``` obj ```
|
|
53
|
+
:returns:
|
|
54
|
+
Create Organization Response
|
|
55
|
+
"""
|
|
56
|
+
return self.core_client.grpc_exec(
|
|
57
|
+
self.organization_service.CreateOrganization.with_call,
|
|
58
|
+
CreateOrganizationRequest(
|
|
59
|
+
organization={"displayName": name, "externalId": options.external_id}
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def update_organization(
|
|
64
|
+
self, organization_id: str, organization: UpdateOrganization
|
|
65
|
+
) -> UpdateOrganizationResponse:
|
|
66
|
+
"""
|
|
67
|
+
Method to update organization based on given data
|
|
68
|
+
|
|
69
|
+
:param organization_id : Organization id to update
|
|
70
|
+
:type : ``` str ```
|
|
71
|
+
:param organization : Optional params for update organization operation
|
|
72
|
+
:type : ``` obj ```
|
|
73
|
+
:returns:
|
|
74
|
+
Update Organization Response
|
|
75
|
+
"""
|
|
76
|
+
return self.core_client.grpc_exec(
|
|
77
|
+
self.organization_service.UpdateOrganization.with_call,
|
|
78
|
+
UpdateOrganizationRequest(id=organization_id, organization=organization),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
def update_organization_by_external_id(
|
|
82
|
+
self, external_id: str
|
|
83
|
+
) -> UpdateOrganizationResponse:
|
|
84
|
+
"""
|
|
85
|
+
Method to update organization based on external id
|
|
86
|
+
|
|
87
|
+
:param external_id : External id to update org
|
|
88
|
+
:type : ``` str ```
|
|
89
|
+
:returns:
|
|
90
|
+
Update Organization Response
|
|
91
|
+
"""
|
|
92
|
+
return self.core_client.grpc_exec(
|
|
93
|
+
self.organization_service.UpdateOrganization.with_call,
|
|
94
|
+
UpdateOrganizationRequest(external_id=external_id),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
def get_organization(self, organization_id: str) -> GetOrganizationResponse:
|
|
98
|
+
"""
|
|
99
|
+
Method to get organization based on given org id
|
|
100
|
+
|
|
101
|
+
:param organization_id : Organization id
|
|
102
|
+
:type : ``` str ```
|
|
103
|
+
:returns:
|
|
104
|
+
Get Organization Response
|
|
105
|
+
"""
|
|
106
|
+
return self.core_client.grpc_exec(
|
|
107
|
+
self.organization_service.GetOrganization.with_call,
|
|
108
|
+
GetOrganizationRequest(id=organization_id),
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
def get_organization_by_external_id(self, external_id: str):
|
|
112
|
+
"""
|
|
113
|
+
Method to get organization based on given org id
|
|
114
|
+
|
|
115
|
+
:param external_id : External id to fetch org details
|
|
116
|
+
:type : ``` str ```
|
|
117
|
+
:returns:
|
|
118
|
+
Get Organization Response
|
|
119
|
+
"""
|
|
120
|
+
return self.core_client.grpc_exec(
|
|
121
|
+
self.organization_service.GetOrganization.with_call,
|
|
122
|
+
GetOrganizationRequest(external_id=external_id),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
def delete_organization(self, organization_id: str) -> None:
|
|
126
|
+
"""
|
|
127
|
+
Method to delete organization based on given org id
|
|
128
|
+
|
|
129
|
+
:param organization_id : Organization id
|
|
130
|
+
:type : ``` str ```
|
|
131
|
+
:returns:
|
|
132
|
+
None
|
|
133
|
+
"""
|
|
134
|
+
self.core_client.grpc_exec(
|
|
135
|
+
self.organization_service.DeleteOrganization.with_call,
|
|
136
|
+
DeleteOrganizationRequest(id=organization_id),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
def generate_portal_link(self, organization_id: str) -> GeneratePortalLinkResponse:
|
|
140
|
+
"""
|
|
141
|
+
Method to generate customer portal link
|
|
142
|
+
|
|
143
|
+
:param organization_id : Organization id to fetch portal link for
|
|
144
|
+
:type : ``` str ```
|
|
145
|
+
:return:
|
|
146
|
+
"""
|
|
147
|
+
response = self.core_client.grpc_exec(
|
|
148
|
+
self.organization_service.GeneratePortalLink.with_call,
|
|
149
|
+
GeneratePortalLinkRequest(id=organization_id),
|
|
150
|
+
)
|
|
151
|
+
if not response.link:
|
|
152
|
+
raise Exception("Error generating portal link")
|
|
153
|
+
return response.link
|
|
154
|
+
|
|
155
|
+
def get_portal_links(self, organization_id: str) -> GetPortalLinksResponse:
|
|
156
|
+
"""
|
|
157
|
+
Method to get customer portal links
|
|
158
|
+
|
|
159
|
+
:param organization_id : Organization id to fetch portal link for
|
|
160
|
+
:type : ``` str ```
|
|
161
|
+
:return:
|
|
162
|
+
"""
|
|
163
|
+
response = self.core_client.grpc_exec(
|
|
164
|
+
self.organization_service.GetPortalLinks.with_call,
|
|
165
|
+
GetPortalLinkRequest(id=organization_id),
|
|
166
|
+
)
|
|
167
|
+
return response.links
|
|
168
|
+
|
|
169
|
+
def delete_portal_link(self, organization_id: str) -> None:
|
|
170
|
+
"""
|
|
171
|
+
Method to delete customer portal link
|
|
172
|
+
|
|
173
|
+
:param organization_id : Organization id to delete portal link for
|
|
174
|
+
:type : ``` str ```
|
|
175
|
+
:returns:
|
|
176
|
+
None
|
|
177
|
+
"""
|
|
178
|
+
self.core_client.grpc_exec(
|
|
179
|
+
self.organization_service.DeletePortalLink.with_call,
|
|
180
|
+
DeletePortalLinkRequest(id=organization_id),
|
|
181
|
+
)
|
scalekit/v1/__init__.py
ADDED
|
File without changes
|
|
File without changes
|