agilicus 1.260.1__py3-none-any.whl → 1.261.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.
@@ -77,7 +77,7 @@ class ApiClient(object):
77
77
  self.default_headers[header_name] = header_value
78
78
  self.cookie = cookie
79
79
  # Set default User-Agent.
80
- self.user_agent = 'OpenAPI-Generator/1.260.1/python'
80
+ self.user_agent = 'OpenAPI-Generator/1.261.0/python'
81
81
 
82
82
  def __enter__(self):
83
83
  return self
@@ -387,7 +387,7 @@ class Configuration(object):
387
387
  "OS: {env}\n"\
388
388
  "Python Version: {pyversion}\n"\
389
389
  "Version of the API: 2024.06.21\n"\
390
- "SDK Package Version: 1.260.1".\
390
+ "SDK Package Version: 1.261.0".\
391
391
  format(env=sys.platform, pyversion=sys.version)
392
392
 
393
393
  def get_host_settings(self):
@@ -4,7 +4,7 @@ Agilicus is API-first. Modern software is controlled by other software, is open,
4
4
  The `agilicus_api` package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
5
5
 
6
6
  - API version: 2024.06.21
7
- - Package version: 1.260.1
7
+ - Package version: 1.261.0
8
8
  - Build package: org.openapitools.codegen.languages.PythonClientCodegen
9
9
  For more information, please visit [https://www.agilicus.com/api](https://www.agilicus.com/api)
10
10
 
@@ -1,4 +1,7 @@
1
1
  import copy
2
+ import datetime
3
+ import json
4
+ import os
2
5
  from ..input_helpers import (
3
6
  get_org_from_input_or_ctx,
4
7
  model_from_dict,
@@ -18,6 +21,9 @@ from agilicus import (
18
21
  SimpleResourcePolicyTemplateStructure,
19
22
  SimpleResourcePolicyTemplate,
20
23
  StandaloneRuleName,
24
+ RuleAction,
25
+ ResourceConfig,
26
+ RulesConfig,
21
27
  RuleCondition,
22
28
  HttpRuleCondition,
23
29
  EmptiableObjectType,
@@ -197,7 +203,7 @@ def set_source_info_policy(
197
203
  return resp
198
204
 
199
205
 
200
- def migrate_policy_rules(ctx, org_id=None, **kwargs):
206
+ def migrate_policy_rules(ctx, org_id=None, dump_dir=None, **kwargs):
201
207
  org_id = get_org_from_input_or_ctx(ctx, org_id=org_id)
202
208
  kwargs = strip_none(kwargs)
203
209
  if not kwargs.get("resource_id"):
@@ -205,22 +211,21 @@ def migrate_policy_rules(ctx, org_id=None, **kwargs):
205
211
  for res in query_resources(
206
212
  ctx, resource_type="application", org_id=org_id, **kwargs
207
213
  ):
208
- migrate_resource(ctx, res)
214
+ migrate_resource(ctx, res, dump_dir=dump_dir)
209
215
 
210
216
 
211
- def migrate_resource(ctx, resource):
217
+ def migrate_resource(ctx, resource, dump_dir=None):
212
218
  print(f" migrating resource: {resource.spec.name}")
213
- if (
214
- not resource.spec.config
215
- or not resource.spec.config.rules_config
216
- or not resource.spec.config.rules_config.rules
217
- ):
218
- print(" no rules found")
219
- return
219
+ resource.spec.config = resource.spec.config or ResourceConfig()
220
+ resource.spec.config.rules_config = (
221
+ resource.spec.config.rules_config or RulesConfig()
222
+ )
223
+
224
+ rules = resource.spec.config.rules_config.rules or []
220
225
  policy_structures = []
221
- for rule in resource.spec.config.rules_config.rules:
226
+ for rule in rules:
222
227
  node = SimpleResourcePolicyTemplateStructureNode(
223
- priority=0,
228
+ priority=rule.priority or 0,
224
229
  rule_name=StandaloneRuleName(rule.name),
225
230
  children=[],
226
231
  )
@@ -231,9 +236,7 @@ def migrate_resource(ctx, resource):
231
236
  )
232
237
  )
233
238
  template = SimpleResourcePolicyTemplate(
234
- rules=[
235
- _migrate_http_rule(rule) for rule in resource.spec.config.rules_config.rules
236
- ],
239
+ rules=[_migrate_http_rule(rule) for rule in rules],
237
240
  policy_structure=policy_structures,
238
241
  template_type="simple_resource",
239
242
  )
@@ -264,14 +267,34 @@ def migrate_resource(ctx, resource):
264
267
  ),
265
268
  to_dict=False,
266
269
  )
270
+
271
+ _clear_old_rules(apiclient, resource, dump_dir)
272
+
267
273
  return resp
268
274
 
269
275
 
276
+ def _dump_resource_rules(resource, dump_dir):
277
+ now = datetime.datetime.now().strftime("%Y-%m-%dT%H-%M-%S")
278
+ file_name = f"{resource.spec.org_id}-{resource.spec.name}-{now}.json"
279
+ with open(os.path.join(dump_dir, file_name), "w") as f:
280
+ json.dump(resource.spec.config.rules_config.to_dict(), f)
281
+
282
+
283
+ def _clear_old_rules(apiclient, resource, dump_dir):
284
+ if dump_dir:
285
+ _dump_resource_rules(resource, dump_dir)
286
+
287
+ resource.spec.config.rules_config = RulesConfig(rules=[])
288
+
289
+ apiclient.resources_api.replace_resource(resource.metadata.id, resource=resource)
290
+
291
+
270
292
  def _migrate_http_rule(input_rule):
271
293
  if input_rule.extended_condition is not None:
272
294
  return input_rule
273
295
 
274
296
  new_rule = copy.deepcopy(input_rule)
297
+ new_rule.actions = new_rule.actions or [RuleAction(action="allow")]
275
298
  input_cond = new_rule.condition.to_dict()
276
299
  input_cond["condition_type"] = "http_rule_condition"
277
300
  cond = model_from_dict(HttpRuleCondition, input_cond)
@@ -42,6 +42,7 @@ def cli_command_list_multifactor_policies(ctx, **kwargs):
42
42
  @click.command(name="list-policy-templates", help="shows all policy templates")
43
43
  @click.option("--org-id", default=None)
44
44
  @click.option("--template-type", default=None)
45
+ @click.option("--include-invalid", type=bool, default=None)
45
46
  @click.option("--name", default=None)
46
47
  @click.pass_context
47
48
  def cli_command_list_policy_templates(ctx, **kwargs):
@@ -93,6 +94,7 @@ def cli_command_delete_policy_template(ctx, **kwargs):
93
94
  @click.command(name="migrate-policy-rules")
94
95
  @click.option("--org-id", default=None)
95
96
  @click.option("--resource-id", default=None)
97
+ @click.option("--dump-dir", default=None, help="A directory to cache migrated rules")
96
98
  @click.pass_context
97
99
  def cli_command_migrate_policy_rules(ctx, **kwargs):
98
100
  policies.migrate_policy_rules(ctx, **kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: agilicus
3
- Version: 1.260.1
3
+ Version: 1.261.0
4
4
  Summary: Agilicus SDK
5
5
  Home-page: https://www.agilicus.com/
6
6
  License: MIT
@@ -71,9 +71,9 @@ agilicus/agilicus_api/api/users_api.py,sha256=xhcIheRgjfMpQ3RbekgnOp3ODUUm6deY1H
71
71
  agilicus/agilicus_api/api/users_api_mock.py,sha256=wA_xiqL3Pz3KjljKlsmf5NveLZS1FpbaKJHBp7QvarY,15411
72
72
  agilicus/agilicus_api/api/whoami_api.py,sha256=c95A5Rfll7idVIb09yTzUjqAVDpyVlRugUjprI5JBbo,7941
73
73
  agilicus/agilicus_api/api/whoami_api_mock.py,sha256=rlvZoWnMCqORMZBg7SOv6d3xp52kELdh6wXcCaIZ93w,346
74
- agilicus/agilicus_api/api_client.py,sha256=I9ZM7SRER3QnseT7-UhGkjb6ftxirm55O_nSAFrwPYQ,38845
74
+ agilicus/agilicus_api/api_client.py,sha256=ENFmNXGSJobDqAVsfDDikSxHyW0DF8cfPbudHpxmBkk,38845
75
75
  agilicus/agilicus_api/apis/__init__.py,sha256=aJZD7x-umdSni6ZBr4XxzpH8pwtU9hA5LlCDxcqa1Q8,2224
76
- agilicus/agilicus_api/configuration.py,sha256=Beg1By_amZD90nXPlwZO_biErR7mhOOOUaS73J3TkaA,18447
76
+ agilicus/agilicus_api/configuration.py,sha256=tyt3WRMFNRvKjZNGnwvEkREO_nklyahMiWpGOrpOhqg,18447
77
77
  agilicus/agilicus_api/docs/APIKey.md,sha256=4cKuz4_l9HcEDnUrLwYbEnn9C2WoDayrjfrY1Ixgaf4,1747
78
78
  agilicus/agilicus_api/docs/APIKeyIntrospect.md,sha256=nJ-zkuFm3JMbWFDYYN_vYyQk1snGBtBvIxtCQxamhAU,1019
79
79
  agilicus/agilicus_api/docs/APIKeyIntrospectAuthorizationInfo.md,sha256=7RApOOLjvWQs5sw2jb25g7i3Kta1BiEY-s8VRXfppH8,725
@@ -2508,7 +2508,7 @@ agilicus/agilicus_api/test/test_x509_root_certificate.py,sha256=H82JE5XkABLdxrdI
2508
2508
  agilicus/agilicus_api/test/test_x509_root_certificate_spec.py,sha256=Avjjv9atO5hYlSmAJU1CzS7M0l-0bPs6q4N5iXSoMcs,2832
2509
2509
  agilicus/agilicus_api/test/test_x509_root_certificate_status.py,sha256=6Iw5aUxT4lNJnOHK0ehotwh-niT9tuSCJIjRe1DKlRg,2846
2510
2510
  agilicus/agilicus_api/test/test_xss_settings.py,sha256=Stf0gqkOTrsfpeYF22QDlz85_Nny56SSwv5dpFZoNQU,2746
2511
- agilicus/agilicus_api_README.md,sha256=HbAfJbtzSZG7ZyZ4VnJweX4tm74kzO5SeRx60WnvFJU,161008
2511
+ agilicus/agilicus_api_README.md,sha256=ARSi8m1rYg64uKu-_E8WkIa8xjQ0lHnlpmcs6pRkGgs,161008
2512
2512
  agilicus/aliases.ini,sha256=MxqiVo2f2xdUDVF1YDkNW36AIqN8hrYjlTVfraEUZXY,455
2513
2513
  agilicus/amq.py,sha256=yxi-YTbJPVl10s78Hlr1dmrQR63iaSIoROGVILzFPmE,1775
2514
2514
  agilicus/apps.py,sha256=uYNUNy5rCYjx90KnR_X_aESof9xzSuLYT5w8myN_VVE,52091
@@ -2572,8 +2572,8 @@ agilicus/output/tests/column_builder_test.py,sha256=fKP4V5sqXtmEIr-Q0gWVSFdBqCUt
2572
2572
  agilicus/pagination/pagination.py,sha256=hC7eLHxXKe4Iv7LdOZK3Dh8R_fKQIr9PPiWKJVyP4Nk,1672
2573
2573
  agilicus/patches.py,sha256=qTqLOgCAcFZPcPOkgfqMnK9bnqTXMvj_0ERsjRFcZug,1384
2574
2574
  agilicus/permissions.py,sha256=uB65yuDFICp1N10m0cdUjgizx9MQzAbLbAsBSTw1Rcc,2117
2575
- agilicus/policy/policies.py,sha256=H4MKMJJuuQ7LsXRKH7d7TrcGLvzIkcuC5FmyO5OD1AE,8817
2576
- agilicus/policy/policy_main.py,sha256=0fASWbzeWpaQEjwX5VOg90ZI-HZvOLCPJdrV3ahd4Hk,3732
2575
+ agilicus/policy/policies.py,sha256=LrteEsXjou_RyW_PcqijBhtN2jaIomXFXQIfNArUP6I,9625
2576
+ agilicus/policy/policy_main.py,sha256=CSg7cFHlZo12eu9T-ugTM1U_sp7QWOXtQN14jbe7KyQ,3878
2577
2577
  agilicus/policy/templates.py,sha256=EUvAhOhSjDuLAe2UKIFEzBp5pNpOT5y1r7uyV_GG6uI,5638
2578
2578
  agilicus/policy_config/policy_config.py,sha256=s1GwbBI5wuLINcViTKE8NdfcntLEegwpUEi7pqmdKkY,627
2579
2579
  agilicus/policy_config/policy_config_main.py,sha256=ReiOziCvPShjunCt3ohrEMGq0IaP0eNyIXEvEg_WD1M,788
@@ -2599,8 +2599,8 @@ agilicus/trusted_certs/trusted_certs_main.py,sha256=6dHHWXvNIcUa_nA9ptigL4Vibe4n
2599
2599
  agilicus/users.py,sha256=JT7TIiUOtSFXPOdxmIVFm7ygZTH1FjsIkD9j-vjLuMM,38474
2600
2600
  agilicus/version.py,sha256=G9OFdL1v_4dLDfk6I6taDNypM5bbO-JHAwilsu9LYgg,23
2601
2601
  agilicus/whoami.py,sha256=kqghtWMgZOd2rhKmfguDwCTm6A3gNS8Kj-S2IBxBtl0,206
2602
- agilicus-1.260.1.dist-info/LICENSE.txt,sha256=Zq4tqiCroC2CVrBB_PWjapRdvpae23nljdiaSkOzUho,1061
2603
- agilicus-1.260.1.dist-info/METADATA,sha256=BZymIJhRbbsOpUHYvHX5ADC7avEJNBih2yuvNhROupM,3822
2604
- agilicus-1.260.1.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
2605
- agilicus-1.260.1.dist-info/entry_points.txt,sha256=a66hGozzLkHu0IewFzIMbSAhMTNTddUaA2T3_16Gb_s,51
2606
- agilicus-1.260.1.dist-info/RECORD,,
2602
+ agilicus-1.261.0.dist-info/LICENSE.txt,sha256=Zq4tqiCroC2CVrBB_PWjapRdvpae23nljdiaSkOzUho,1061
2603
+ agilicus-1.261.0.dist-info/METADATA,sha256=WfbLexPUatEevNmdnHQ6FnpQLgD-E8PHAPaV8M8aS00,3822
2604
+ agilicus-1.261.0.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
2605
+ agilicus-1.261.0.dist-info/entry_points.txt,sha256=a66hGozzLkHu0IewFzIMbSAhMTNTddUaA2T3_16Gb_s,51
2606
+ agilicus-1.261.0.dist-info/RECORD,,