Skip to content

ark_uap_sia_db_access_policy

ArkUAPSIADBAccessPolicy

Bases: ArkUAPSIACommonAccessPolicy

Source code in ark_sdk_python/models/services/uap/sia/db/ark_uap_sia_db_access_policy.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
class ArkUAPSIADBAccessPolicy(ArkUAPSIACommonAccessPolicy):
    targets: Annotated[Dict[ArkWorkspaceType, ArkUAPSIADBTargets], Field(description='The targets of the db access policy')]

    @field_validator('targets', mode='before')
    @classmethod
    def validate_workspace_type(cls, val: Dict[str, Any]):
        if val is not None:
            for key in val.keys():
                if ArkWorkspaceType(key) not in [ArkWorkspaceType.FQDN_IP]:
                    raise ValueError('Invalid Workspace Type')
        return val

    def serialize_model(self, *args, **kwargs) -> Dict[str, Any]:
        """
        Serializes the model to a dictionary, including the profiles of each instance in the targets.
        Done to customize serialization of each instance's profile.
        This ensures that each instance's profile is serialized according to its authentication method,
        and included in the output under the 'profile' key.
        """
        data = super().model_dump(*args, **kwargs)

        for workspace_type, target in self.targets.items():
            serialized_instances = []
            for index, instance in enumerate(target.instances):
                profile = instance.profile_by_authentication_method()
                if profile is None:
                    raise ValueError(
                        f'No profile found for the given authentication method, instance: [{instance.instance_name}], authentication method: [{instance.authentication_method}]'
                    )

                instance_data = instance.model_dump(
                    *args,
                    **kwargs,
                )
                data['targets'][workspace_type]['instances'][index]['profile'] = profile.model_dump(*args, **kwargs)
                del data['targets'][workspace_type]['instances'][index][
                    instance.auth_method_to_profile_field_name()[instance.authentication_method]
                ]
                serialized_instances.append(instance_data)

        return data

serialize_model(*args, **kwargs)

Serializes the model to a dictionary, including the profiles of each instance in the targets. Done to customize serialization of each instance's profile. This ensures that each instance's profile is serialized according to its authentication method, and included in the output under the 'profile' key.

Source code in ark_sdk_python/models/services/uap/sia/db/ark_uap_sia_db_access_policy.py
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
def serialize_model(self, *args, **kwargs) -> Dict[str, Any]:
    """
    Serializes the model to a dictionary, including the profiles of each instance in the targets.
    Done to customize serialization of each instance's profile.
    This ensures that each instance's profile is serialized according to its authentication method,
    and included in the output under the 'profile' key.
    """
    data = super().model_dump(*args, **kwargs)

    for workspace_type, target in self.targets.items():
        serialized_instances = []
        for index, instance in enumerate(target.instances):
            profile = instance.profile_by_authentication_method()
            if profile is None:
                raise ValueError(
                    f'No profile found for the given authentication method, instance: [{instance.instance_name}], authentication method: [{instance.authentication_method}]'
                )

            instance_data = instance.model_dump(
                *args,
                **kwargs,
            )
            data['targets'][workspace_type]['instances'][index]['profile'] = profile.model_dump(*args, **kwargs)
            del data['targets'][workspace_type]['instances'][index][
                instance.auth_method_to_profile_field_name()[instance.authentication_method]
            ]
            serialized_instances.append(instance_data)

    return data