pygeobox 1.0.0__py3-none-any.whl → 1.0.2__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.
pygeobox/settings.py CHANGED
@@ -1,166 +1,166 @@
1
- from typing import List, Dict, Optional, TYPE_CHECKING
2
- from urllib.parse import urljoin, urlencode
3
-
4
- from .base import Base
5
- from .utils import clean_data
6
- from .enums import MaxLogPolicy, InvalidDataPolicy, LoginFailurePolicy, MaxConcurrentSessionPolicy
7
-
8
-
9
- if TYPE_CHECKING:
10
- from . import GeoboxClient
11
-
12
- class SystemSettings(Base):
13
-
14
- BASE_ENDPOINT = 'settings/'
15
-
16
- def __init__(self,
17
- api: 'GeoboxClient',
18
- data: Optional[Dict] = {}):
19
- """
20
- Initialize a System Settings instance.
21
-
22
- Args:
23
- api (GeoboxClient): The GeoboxClient instance for making requests.
24
- data (Dict, optional): The data of the Setting.
25
- """
26
- super().__init__(api, data=data)
27
-
28
-
29
- @property
30
- def max_log_policy(self) -> 'MaxLogPolicy':
31
- """
32
- Get max log policy
33
-
34
- Returns:
35
- MaxLogPolicy: max log policy
36
- """
37
- return MaxLogPolicy(self.data.get('max_log_policy'))
38
-
39
-
40
- @property
41
- def invalid_data_policy(self) -> 'InvalidDataPolicy':
42
- """
43
- Get invalid data policy
44
-
45
- Returns:
46
- InvalidDataPolicy: invalid data policy
47
- """
48
- return InvalidDataPolicy(self.data.get('invalid_data_policy'))
49
-
50
-
51
- @property
52
- def login_failure_policy(self) -> 'LoginFailurePolicy':
53
- """
54
- Get login failure policy
55
-
56
- Returns:
57
- LoginFailurePolicy: login failure policy
58
- """
59
- return LoginFailurePolicy(self.data.get('login_failure_policy'))
60
-
61
-
62
- @property
63
- def max_concurrent_session_policy(self) -> 'MaxConcurrentSessionPolicy':
64
- """
65
- Get max concurrent sessions
66
-
67
- Returns:
68
- MaxConcurrentSessionPolicy: max concurrent sessions
69
- """
70
- return MaxConcurrentSessionPolicy(self.data.get('max_concurrent_session_policy'))
71
-
72
-
73
- def __repr__(self) -> str:
74
- """
75
- Return a string representation of the system setting instance.
76
-
77
- Returns:
78
- str: A string representation of the system setting instance.
79
- """
80
- return "SystemSettings()"
81
-
82
-
83
- @classmethod
84
- def get_system_settings(cls, api: 'GeoboxClient') -> 'SystemSettings':
85
- """
86
- Get System Settings object (Permission Required).
87
-
88
- Args:
89
- api (GeoboxClient): The GeoboxClient instance for making requests.
90
-
91
- Returns:
92
- SystemSetting: the system settings object.
93
-
94
- Example:
95
- >>> from geobox import GeoboxClient
96
- >>> from geobox.setting import SystemSettings
97
- >>> client = GeoboxClient()
98
- >>> setting = SystemSettings.get_system_settings(client)
99
- or
100
- >>> setting = client.get_system_settings()
101
- """
102
- params = clean_data({
103
- 'f': 'json'
104
- })
105
- query_string = urlencode(params)
106
- endpoint = urljoin(cls.BASE_ENDPOINT, f"?{query_string}")
107
- response = api.get(endpoint)
108
- return SystemSettings(api, response)
109
-
110
-
111
- def update(self, **kwargs) -> Dict:
112
- """
113
- Update the system settings.
114
-
115
- Keyword Args:
116
- brand_name (str)
117
- brand_website (str)
118
- max_log (int)
119
- max_log_policy (MaxLogPolicy)
120
- users_can_view_their_own_logs (bool)
121
- max_upload_file_size (int)
122
- invalid_data_policy (InvalidDataPolicy)
123
- max_login_attempts (int)
124
- login_failure_policy (LoginFailurePolicy)
125
- login_attempts_duration (int)
126
- min_password_length (int)
127
- max_concurrent_session (int)
128
- max_concurrent_session_policy (MaxConcurrentSessionPolicy)
129
- session_timeout (int)
130
- allowed_ip_addresses (Dict)
131
- blocked_ip_addresses (Dict)
132
-
133
- Returns:
134
- Dict: The updated system settings data.
135
-
136
- Raises:
137
- ValidationError: If the system settings data is invalid.
138
-
139
- Example:
140
- >>> from geobox import GeoboxClient
141
- >>> from geobox.setting import SystemSettings
142
- >>> client = GeoboxClient()
143
- >>> settings = SystemSetting.get_system_settings(client)
144
- or
145
- >>> settings = client.get_system_settings()
146
- >>> settings.update_system_settings(max_log=100000)
147
- """
148
- data = {
149
- "brand_name": kwargs.get('brand_name'),
150
- "brand_website": kwargs.get('brand_website'),
151
- "max_log": kwargs.get('max_log'),
152
- "max_log_policy": kwargs.get('max_log_policy').value if kwargs.get('max_log_policy') else None,
153
- "max_upload_file_size": kwargs.get('max_upload_file_size'),
154
- "invalid_data_policy": kwargs.get('invalid_data_policy').value if kwargs.get('invalid_data_policy') else None,
155
- "max_login_attempts": kwargs.get('max_login_attempts'),
156
- "login_failure_policy": kwargs.get('login_failure_policy').value if kwargs.get('login_failure_policy') else None,
157
- "login_attempts_duration": kwargs.get('login_attempts_duration'),
158
- "min_password_length": kwargs.get('min_password_length'),
159
- "max_concurrent_session": kwargs.get('max_concurrent_session'),
160
- "max_concurrent_session_policy": kwargs.get('max_concurrent_session_policy').value if kwargs.get('max_concurrent_session_policy') else None,
161
- "session_timeout": kwargs.get('session_timeout'),
162
- "allowed_ip_addresses": kwargs.get('allowed_ip_addresses'),
163
- "blocked_ip_addresses": kwargs.get('blocked_ip_addresses'),
164
-
165
- }
1
+ from typing import List, Dict, Optional, TYPE_CHECKING
2
+ from urllib.parse import urljoin, urlencode
3
+
4
+ from .base import Base
5
+ from .utils import clean_data
6
+ from .enums import MaxLogPolicy, InvalidDataPolicy, LoginFailurePolicy, MaxConcurrentSessionPolicy
7
+
8
+
9
+ if TYPE_CHECKING:
10
+ from . import GeoboxClient
11
+
12
+ class SystemSettings(Base):
13
+
14
+ BASE_ENDPOINT = 'settings/'
15
+
16
+ def __init__(self,
17
+ api: 'GeoboxClient',
18
+ data: Optional[Dict] = {}):
19
+ """
20
+ Initialize a System Settings instance.
21
+
22
+ Args:
23
+ api (GeoboxClient): The GeoboxClient instance for making requests.
24
+ data (Dict, optional): The data of the Setting.
25
+ """
26
+ super().__init__(api, data=data)
27
+
28
+
29
+ @property
30
+ def max_log_policy(self) -> 'MaxLogPolicy':
31
+ """
32
+ Get max log policy
33
+
34
+ Returns:
35
+ MaxLogPolicy: max log policy
36
+ """
37
+ return MaxLogPolicy(self.data.get('max_log_policy'))
38
+
39
+
40
+ @property
41
+ def invalid_data_policy(self) -> 'InvalidDataPolicy':
42
+ """
43
+ Get invalid data policy
44
+
45
+ Returns:
46
+ InvalidDataPolicy: invalid data policy
47
+ """
48
+ return InvalidDataPolicy(self.data.get('invalid_data_policy'))
49
+
50
+
51
+ @property
52
+ def login_failure_policy(self) -> 'LoginFailurePolicy':
53
+ """
54
+ Get login failure policy
55
+
56
+ Returns:
57
+ LoginFailurePolicy: login failure policy
58
+ """
59
+ return LoginFailurePolicy(self.data.get('login_failure_policy'))
60
+
61
+
62
+ @property
63
+ def max_concurrent_session_policy(self) -> 'MaxConcurrentSessionPolicy':
64
+ """
65
+ Get max concurrent sessions
66
+
67
+ Returns:
68
+ MaxConcurrentSessionPolicy: max concurrent sessions
69
+ """
70
+ return MaxConcurrentSessionPolicy(self.data.get('max_concurrent_session_policy'))
71
+
72
+
73
+ def __repr__(self) -> str:
74
+ """
75
+ Return a string representation of the system setting instance.
76
+
77
+ Returns:
78
+ str: A string representation of the system setting instance.
79
+ """
80
+ return "SystemSettings()"
81
+
82
+
83
+ @classmethod
84
+ def get_system_settings(cls, api: 'GeoboxClient') -> 'SystemSettings':
85
+ """
86
+ Get System Settings object (Permission Required).
87
+
88
+ Args:
89
+ api (GeoboxClient): The GeoboxClient instance for making requests.
90
+
91
+ Returns:
92
+ SystemSetting: the system settings object.
93
+
94
+ Example:
95
+ >>> from geobox import GeoboxClient
96
+ >>> from geobox.setting import SystemSettings
97
+ >>> client = GeoboxClient()
98
+ >>> setting = SystemSettings.get_system_settings(client)
99
+ or
100
+ >>> setting = client.get_system_settings()
101
+ """
102
+ params = clean_data({
103
+ 'f': 'json'
104
+ })
105
+ query_string = urlencode(params)
106
+ endpoint = urljoin(cls.BASE_ENDPOINT, f"?{query_string}")
107
+ response = api.get(endpoint)
108
+ return SystemSettings(api, response)
109
+
110
+
111
+ def update(self, **kwargs) -> Dict:
112
+ """
113
+ Update the system settings.
114
+
115
+ Keyword Args:
116
+ brand_name (str)
117
+ brand_website (str)
118
+ max_log (int)
119
+ max_log_policy (MaxLogPolicy)
120
+ users_can_view_their_own_logs (bool)
121
+ max_upload_file_size (int)
122
+ invalid_data_policy (InvalidDataPolicy)
123
+ max_login_attempts (int)
124
+ login_failure_policy (LoginFailurePolicy)
125
+ login_attempts_duration (int)
126
+ min_password_length (int)
127
+ max_concurrent_session (int)
128
+ max_concurrent_session_policy (MaxConcurrentSessionPolicy)
129
+ session_timeout (int)
130
+ allowed_ip_addresses (Dict)
131
+ blocked_ip_addresses (Dict)
132
+
133
+ Returns:
134
+ Dict: The updated system settings data.
135
+
136
+ Raises:
137
+ ValidationError: If the system settings data is invalid.
138
+
139
+ Example:
140
+ >>> from geobox import GeoboxClient
141
+ >>> from geobox.setting import SystemSettings
142
+ >>> client = GeoboxClient()
143
+ >>> settings = SystemSetting.get_system_settings(client)
144
+ or
145
+ >>> settings = client.get_system_settings()
146
+ >>> settings.update_system_settings(max_log=100000)
147
+ """
148
+ data = {
149
+ "brand_name": kwargs.get('brand_name'),
150
+ "brand_website": kwargs.get('brand_website'),
151
+ "max_log": kwargs.get('max_log'),
152
+ "max_log_policy": kwargs.get('max_log_policy').value if kwargs.get('max_log_policy') else None,
153
+ "max_upload_file_size": kwargs.get('max_upload_file_size'),
154
+ "invalid_data_policy": kwargs.get('invalid_data_policy').value if kwargs.get('invalid_data_policy') else None,
155
+ "max_login_attempts": kwargs.get('max_login_attempts'),
156
+ "login_failure_policy": kwargs.get('login_failure_policy').value if kwargs.get('login_failure_policy') else None,
157
+ "login_attempts_duration": kwargs.get('login_attempts_duration'),
158
+ "min_password_length": kwargs.get('min_password_length'),
159
+ "max_concurrent_session": kwargs.get('max_concurrent_session'),
160
+ "max_concurrent_session_policy": kwargs.get('max_concurrent_session_policy').value if kwargs.get('max_concurrent_session_policy') else None,
161
+ "session_timeout": kwargs.get('session_timeout'),
162
+ "allowed_ip_addresses": kwargs.get('allowed_ip_addresses'),
163
+ "blocked_ip_addresses": kwargs.get('blocked_ip_addresses'),
164
+
165
+ }
166
166
  return super()._update(self.BASE_ENDPOINT, data)