Skip to content

ark_api

ArkAPI

Source code in ark_sdk_python/ark_api.py
 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
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
class ArkAPI:
    def __init__(self, authenticators: List[ArkAuth], profile: Optional[ArkProfile] = None) -> None:
        self.__authenticators = authenticators
        self.__lazy_loaded_services: Dict[str, ArkService] = {}
        self.__profile = profile or ArkProfileLoader.load_default_profile()

    def __lazy_load_service(self, service_type: Type[ArkService]) -> ArkService:
        service_name = service_type.service_config().service_name
        required_auth_names = service_type.service_config().required_authenticator_names
        required_autheneticators = [auth for auth in self.__authenticators if auth.authenticator_name() in required_auth_names]
        optional_authenticators = [
            auth
            for auth in self.__authenticators
            if auth.authenticator_name() in service_type.service_config().optional_authenticator_names
        ]
        if len(required_autheneticators) == len(required_auth_names):
            authenticators = {f'{a.authenticator_name()}_auth': a for a in required_autheneticators + optional_authenticators}
            self.__lazy_loaded_services[service_name] = service_type(**authenticators)
        else:
            raise ArkServiceException(
                f'{service_name.title()} is not supported or missing fitting authenticators, please make sure you are logged in'
            )
        return self.__lazy_loaded_services[service_name]

    def authenticator(self, authenticator_name: str) -> ArkAuth:
        """
        Returns the specified authenticator.

        Args:
            authenticator_name (str): _description_

        Raises:
            ArkServiceException: _description_

        Returns:
            ArkAuth: _description_
        """
        for auth in self.__authenticators:
            if auth.authenticator_name() == authenticator_name:
                return auth
        raise ArkServiceException(f'{authenticator_name} is not supported or not found')

    def service(self, service_type: Type[ArkService]) -> ArkService:
        """
        Returns the specified service when the appropriate authenticators were provided.

        Args:
            service_type (Type[ArkService]): _description_

        Raises:
            ArkServiceException: _description_

        Returns:
            ArkService: _description_
        """
        if not issubclass(service_type, ArkService):
            raise ArkServiceException(f"Type {service_type} is invalid")
        service_name = service_type.service_config().service_name
        if service_name in self.__lazy_loaded_services:
            return self.__lazy_loaded_services[service_name]
        return self.__lazy_load_service(service_type)

    @property
    def profile(self) -> ArkProfile:
        """
        Gets the API profile

        Returns:
            ArkProfile: _description_
        """
        return self.__profile

    @property
    def identity_directories(self) -> "ArkIdentityDirectoriesService":
        """
        Returns the Identity Directories Service if the appropriate authenticators were given

        Returns:
            ArkIdentityDirectoriesService: _description_
        """
        from ark_sdk_python.services.identity.directories import ArkIdentityDirectoriesService

        return cast(ArkIdentityDirectoriesService, self.service(ArkIdentityDirectoriesService))

    @property
    def identity_policies(self) -> "ArkIdentityPoliciesService":
        """
        Returns the Identity Policies Service if the appropriate authenticators were given

        Returns:
            ArkIdentityPoliciesService: _description_
        """
        from ark_sdk_python.services.identity.policies import ArkIdentityPoliciesService

        return cast(ArkIdentityPoliciesService, self.service(ArkIdentityPoliciesService))

    @property
    def identity_roles(self) -> "ArkIdentityRolesService":
        """
        Returns the Identity Roles Service if the appropriate authenticators were given

        Returns:
            ArkIdentityRolesService: _description_
        """
        from ark_sdk_python.services.identity.roles import ArkIdentityRolesService

        return cast(ArkIdentityRolesService, self.service(ArkIdentityRolesService))

    @property
    def identity_users(self) -> "ArkIdentityUsersService":
        """
        Returns the Identity Users Service if the appropriate authenticators were given

        Returns:
            ArkIdentityUsersService: _description_
        """
        from ark_sdk_python.services.identity.users import ArkIdentityUsersService

        return cast(ArkIdentityUsersService, self.service(ArkIdentityUsersService))

    @property
    def dpa_workspaces_db(self) -> "ArkDPADBWorkspaceService":
        """
        Returns the DPA DB Workspace service if the appropriate authenticators were provided.

        Returns:
            ArkDPADBWorkspaceService: _description_
        """
        from ark_sdk_python.services.dpa.workspaces.db import ArkDPADBWorkspaceService

        return cast(ArkDPADBWorkspaceService, self.service(ArkDPADBWorkspaceService))

    @property
    def dpa_policies_vm(self) -> "ArkDPAVMPoliciesService":
        """
        Returns the DPA VM Policies service if the appropriate authenticators were provided.

        Returns:
            ArkDPAVMPoliciesService: _description_
        """
        from ark_sdk_python.services.dpa.policies.vm import ArkDPAVMPoliciesService

        return cast(ArkDPAVMPoliciesService, self.service(ArkDPAVMPoliciesService))

    @property
    def dpa_policies_db(self) -> "ArkDPADBPoliciesService":
        """
        Returns the DPA DB Policies service if the appropriate authenticators were provided.

        Returns:
            ArkDPADBPoliciesService: _description_
        """
        from ark_sdk_python.services.dpa.policies.db import ArkDPADBPoliciesService

        return cast(ArkDPADBPoliciesService, self.service(ArkDPADBPoliciesService))

    @property
    def dpa_secrets_db(self) -> "ArkDPADBSecretsService":
        """
        Returns the DPA DB Secrets service if the appropriate authenticators were provided.

        Returns:
            ArkDPADBSecretsService: _description_
        """
        from ark_sdk_python.services.dpa.secrets.db import ArkDPADBSecretsService

        return cast(ArkDPADBSecretsService, self.service(ArkDPADBSecretsService))

    @property
    def dpa_sso(self) -> "ArkDPASSOService":
        """
        Returns the DPA sso service if the appropriate authenticators were provided.

        Returns:
            ArkDPASSOService: _description_
        """
        from ark_sdk_python.services.dpa.sso import ArkDPASSOService

        return cast(ArkDPASSOService, self.service(ArkDPASSOService))

    @property
    def dpa_db(self) -> "ArkDPADBService":
        """
        Returns the DPA DB service if the appropriate authenticators were provided.

        Returns:
            ArkDPADBService: _description_
        """
        from ark_sdk_python.services.dpa.db import ArkDPADBService

        return cast(ArkDPADBService, self.service(ArkDPADBService))

    @property
    def dpa_certificates(self) -> "ArkDPACertificatesService":
        """
        Returns DPA certificates service if the appropriate authenticators were provided.

        Returns:
            ArkDPACertificatesService: _description_
        """
        from ark_sdk_python.services.dpa.certificates import ArkDPACertificatesService

        return cast(ArkDPACertificatesService, self.service(ArkDPACertificatesService))

    @property
    def dpa_k8s(self) -> "ArkDPAK8SService":
        """
        Returns the DPA Policies service if the appropriate authenticators were provided.

        Returns:
            ArkDPAK8SService: _description_
        """
        from ark_sdk_python.services.dpa.k8s import ArkDPAK8SService

        return cast(ArkDPAK8SService, self.service(ArkDPAK8SService))

    @property
    def sm(self) -> "ArkSMService":
        """
        Returns the SM service if the appropriate authenticators were given

        Returns:
            ArkSMService: _description_
        """
        from ark_sdk_python.services.sm import ArkSMService

        return cast(ArkSMService, self.service(ArkSMService))

    @property
    def pcloud_accounts(self) -> "ArkPCloudAccountsService":
        """
        Returns the PCloud Accounts service if the appropriate authenticators were given

        Returns:
            ArkPCloudAccountsService: _description_
        """
        from ark_sdk_python.services.pcloud.accounts import ArkPCloudAccountsService

        return cast(ArkPCloudAccountsService, self.service(ArkPCloudAccountsService))

    @property
    def pcloud_safes(self) -> "ArkPCloudSafesService":
        """
        Returns the PCloud Safes service if the appropriate authenticators were given

        Returns:
            ArkPCloudSafesService: _description_
        """
        from ark_sdk_python.services.pcloud.safes import ArkPCloudSafesService

        return cast(ArkPCloudSafesService, self.service(ArkPCloudSafesService))

    @property
    def pcloud_platforms(self) -> "ArkPCloudPlatformsService":
        """
        Returns the PCloud Platforms service if the appropriate authenticators were given

        Returns:
            ArkPCloudPlatformsService: _description_
        """
        from ark_sdk_python.services.pcloud.platforms import ArkPCloudPlatformsService

        return cast(ArkPCloudPlatformsService, self.service(ArkPCloudPlatformsService))

dpa_certificates: 'ArkDPACertificatesService' property

Returns DPA certificates service if the appropriate authenticators were provided.

Returns:

Name Type Description
ArkDPACertificatesService 'ArkDPACertificatesService'

description

dpa_db: 'ArkDPADBService' property

Returns the DPA DB service if the appropriate authenticators were provided.

Returns:

Name Type Description
ArkDPADBService 'ArkDPADBService'

description

dpa_k8s: 'ArkDPAK8SService' property

Returns the DPA Policies service if the appropriate authenticators were provided.

Returns:

Name Type Description
ArkDPAK8SService 'ArkDPAK8SService'

description

dpa_policies_db: 'ArkDPADBPoliciesService' property

Returns the DPA DB Policies service if the appropriate authenticators were provided.

Returns:

Name Type Description
ArkDPADBPoliciesService 'ArkDPADBPoliciesService'

description

dpa_policies_vm: 'ArkDPAVMPoliciesService' property

Returns the DPA VM Policies service if the appropriate authenticators were provided.

Returns:

Name Type Description
ArkDPAVMPoliciesService 'ArkDPAVMPoliciesService'

description

dpa_secrets_db: 'ArkDPADBSecretsService' property

Returns the DPA DB Secrets service if the appropriate authenticators were provided.

Returns:

Name Type Description
ArkDPADBSecretsService 'ArkDPADBSecretsService'

description

dpa_sso: 'ArkDPASSOService' property

Returns the DPA sso service if the appropriate authenticators were provided.

Returns:

Name Type Description
ArkDPASSOService 'ArkDPASSOService'

description

dpa_workspaces_db: 'ArkDPADBWorkspaceService' property

Returns the DPA DB Workspace service if the appropriate authenticators were provided.

Returns:

Name Type Description
ArkDPADBWorkspaceService 'ArkDPADBWorkspaceService'

description

identity_directories: 'ArkIdentityDirectoriesService' property

Returns the Identity Directories Service if the appropriate authenticators were given

Returns:

Name Type Description
ArkIdentityDirectoriesService 'ArkIdentityDirectoriesService'

description

identity_policies: 'ArkIdentityPoliciesService' property

Returns the Identity Policies Service if the appropriate authenticators were given

Returns:

Name Type Description
ArkIdentityPoliciesService 'ArkIdentityPoliciesService'

description

identity_roles: 'ArkIdentityRolesService' property

Returns the Identity Roles Service if the appropriate authenticators were given

Returns:

Name Type Description
ArkIdentityRolesService 'ArkIdentityRolesService'

description

identity_users: 'ArkIdentityUsersService' property

Returns the Identity Users Service if the appropriate authenticators were given

Returns:

Name Type Description
ArkIdentityUsersService 'ArkIdentityUsersService'

description

pcloud_accounts: 'ArkPCloudAccountsService' property

Returns the PCloud Accounts service if the appropriate authenticators were given

Returns:

Name Type Description
ArkPCloudAccountsService 'ArkPCloudAccountsService'

description

pcloud_platforms: 'ArkPCloudPlatformsService' property

Returns the PCloud Platforms service if the appropriate authenticators were given

Returns:

Name Type Description
ArkPCloudPlatformsService 'ArkPCloudPlatformsService'

description

pcloud_safes: 'ArkPCloudSafesService' property

Returns the PCloud Safes service if the appropriate authenticators were given

Returns:

Name Type Description
ArkPCloudSafesService 'ArkPCloudSafesService'

description

profile: ArkProfile property

Gets the API profile

Returns:

Name Type Description
ArkProfile ArkProfile

description

sm: 'ArkSMService' property

Returns the SM service if the appropriate authenticators were given

Returns:

Name Type Description
ArkSMService 'ArkSMService'

description

authenticator(authenticator_name)

Returns the specified authenticator.

Parameters:

Name Type Description Default
authenticator_name str

description

required

Raises:

Type Description
ArkServiceException

description

Returns:

Name Type Description
ArkAuth ArkAuth

description

Source code in ark_sdk_python/ark_api.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def authenticator(self, authenticator_name: str) -> ArkAuth:
    """
    Returns the specified authenticator.

    Args:
        authenticator_name (str): _description_

    Raises:
        ArkServiceException: _description_

    Returns:
        ArkAuth: _description_
    """
    for auth in self.__authenticators:
        if auth.authenticator_name() == authenticator_name:
            return auth
    raise ArkServiceException(f'{authenticator_name} is not supported or not found')

service(service_type)

Returns the specified service when the appropriate authenticators were provided.

Parameters:

Name Type Description Default
service_type Type[ArkService]

description

required

Raises:

Type Description
ArkServiceException

description

Returns:

Name Type Description
ArkService ArkService

description

Source code in ark_sdk_python/ark_api.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def service(self, service_type: Type[ArkService]) -> ArkService:
    """
    Returns the specified service when the appropriate authenticators were provided.

    Args:
        service_type (Type[ArkService]): _description_

    Raises:
        ArkServiceException: _description_

    Returns:
        ArkService: _description_
    """
    if not issubclass(service_type, ArkService):
        raise ArkServiceException(f"Type {service_type} is invalid")
    service_name = service_type.service_config().service_name
    if service_name in self.__lazy_loaded_services:
        return self.__lazy_loaded_services[service_name]
    return self.__lazy_load_service(service_type)