Skip to content

ark_uap_get_access_policies_request

ArkUAPFilters

Bases: ArkCamelizedModel

Source code in ark_sdk_python/models/services/uap/common/ark_uap_get_access_policies_request.py
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
class ArkUAPFilters(ArkCamelizedModel):
    location_type: Annotated[
        Optional[List[ArkWorkspaceType]], Field(default=None, description='List of wanted location types for the policies')
    ]
    target_category: Annotated[
        Optional[List[ArkCategoryType]], Field(default=None, description='List of wanted target categories for the policies')
    ]
    policy_type: Annotated[
        Optional[List[ArkUAPPolicyType]], Field(default=None, description='List of wanted policy types for the policies')
    ]
    policy_tags: Annotated[Optional[List[str]], Field(default=None, description='List of wanted policy tags for the policies')]
    identities: Annotated[Optional[List[str]], Field(default=None, description='List of identities to filter the policies by')]
    status: Annotated[Optional[List[ArkUAPStatusType]], Field(default=None, description='List of wanted policy statuses for the policies')]
    text_search: Annotated[
        Optional[str], Field(default=None, description='Text search filter to apply on the policies names and descriptions')
    ]
    show_editable_policies: Annotated[Optional[bool], Field(default=None, description='Whether to show editable policies or not')]
    max_pages: Annotated[int, Field(default=1000000, description='The maximum number of pages for pagination, default is 1000000')]

    def model_dump(self, **kwargs) -> dict:
        data = super().model_dump(**kwargs)
        data['locationType'] = serialize_uap_policies_workspace_types(self.location_type)
        return data

    __FILTER_OPERATORS: Dict[str, ArkUAPFilterOperator] = {
        "locationType": ArkUAPFilterOperator.EQ,
        "policyType": ArkUAPFilterOperator.EQ,
        "targetCategory": ArkUAPFilterOperator.EQ,
        "policyTags": ArkUAPFilterOperator.EQ,
        "status": ArkUAPFilterOperator.EQ,
        "identities": ArkUAPFilterOperator.CONTAINS,
    }

    __MAP_ALIAS_TO_FIELD_NAME: Dict[str, str] = {
        "locationType": "location_type",
        "policyType": "policy_type",
        "targetCategory": "target_category",
        "policyTags": "policy_tags",
        "status": "status",
        "identities": "identities",
    }

    def build_filter_query_from_filters(self) -> str:
        """
        Summary : Builds a filter query string from the provided filters.

        Returns: the filter query string constructed from the filters.

        """
        clauses = []

        for field_name, operator in self.__FILTER_OPERATORS.items():
            values = getattr(self, self.__MAP_ALIAS_TO_FIELD_NAME.get(field_name), None)
            if field_name == "locationType":
                values = serialize_uap_policies_workspace_types(values) if values else None
            if values:
                item_clauses = [f"({field_name} {operator.value} '{v}')" for v in values]
                joined = f" {ArkUAPFilterOperator.OR.value} ".join(item_clauses)
                clauses.append(f"({joined})" if len(item_clauses) > 1 else item_clauses[0])

        return f"({' and '.join(clauses)})" if len(clauses) > 1 else (clauses[0] if clauses else "")

build_filter_query_from_filters()

Summary : Builds a filter query string from the provided filters.

Returns: the filter query string constructed from the filters.

Source code in ark_sdk_python/models/services/uap/common/ark_uap_get_access_policies_request.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def build_filter_query_from_filters(self) -> str:
    """
    Summary : Builds a filter query string from the provided filters.

    Returns: the filter query string constructed from the filters.

    """
    clauses = []

    for field_name, operator in self.__FILTER_OPERATORS.items():
        values = getattr(self, self.__MAP_ALIAS_TO_FIELD_NAME.get(field_name), None)
        if field_name == "locationType":
            values = serialize_uap_policies_workspace_types(values) if values else None
        if values:
            item_clauses = [f"({field_name} {operator.value} '{v}')" for v in values]
            joined = f" {ArkUAPFilterOperator.OR.value} ".join(item_clauses)
            clauses.append(f"({joined})" if len(item_clauses) > 1 else item_clauses[0])

    return f"({' and '.join(clauses)})" if len(clauses) > 1 else (clauses[0] if clauses else "")

ArkUAPGetAccessPoliciesRequest

Bases: ArkCamelizedModel

Source code in ark_sdk_python/models/services/uap/common/ark_uap_get_access_policies_request.py
 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
class ArkUAPGetAccessPoliciesRequest(ArkCamelizedModel):
    filters: Optional[ArkUAPFilters] = Field(default=None, description="The filter query to apply on the policies")
    limit: int = Field(default=50, description="The maximum number of policies to return in the response")
    next_token: Optional[str] = Field(default=None, description="The next token for pagination")

    def build_get_query_params(self) -> ArkUAPGetQueryParams:
        """
        Summary: Builds the query parameters for retrieving access policies.

        This method constructs the query parameters based on the provided filters and pagination options.


        Returns:
            ArkUAPGetQueryParams: The constructed query parameters for the access policies request.
        """

        query_params = ArkUAPGetQueryParams(limit=self.limit)
        if not self.filters:
            return query_params

        local_filters: ArkUAPFilters = getattr(self, 'filters', None)

        if local_filters.text_search:
            query_params.q = local_filters.text_search

        filter_query = local_filters.build_filter_query_from_filters()
        if filter_query:
            query_params.filter = filter_query

        if self.next_token:
            query_params.next_token = self.next_token

        if local_filters.show_editable_policies is not None:
            query_params.show_editable_policies = local_filters.show_editable_policies

        return query_params

build_get_query_params()

This method constructs the query parameters based on the provided filters and pagination options.

Returns:

Name Type Description
ArkUAPGetQueryParams ArkUAPGetQueryParams

The constructed query parameters for the access policies request.

Source code in ark_sdk_python/models/services/uap/common/ark_uap_get_access_policies_request.py
 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
def build_get_query_params(self) -> ArkUAPGetQueryParams:
    """
    Summary: Builds the query parameters for retrieving access policies.

    This method constructs the query parameters based on the provided filters and pagination options.


    Returns:
        ArkUAPGetQueryParams: The constructed query parameters for the access policies request.
    """

    query_params = ArkUAPGetQueryParams(limit=self.limit)
    if not self.filters:
        return query_params

    local_filters: ArkUAPFilters = getattr(self, 'filters', None)

    if local_filters.text_search:
        query_params.q = local_filters.text_search

    filter_query = local_filters.build_filter_query_from_filters()
    if filter_query:
        query_params.filter = filter_query

    if self.next_token:
        query_params.next_token = self.next_token

    if local_filters.show_editable_policies is not None:
        query_params.show_editable_policies = local_filters.show_editable_policies

    return query_params