infrahub-server 1.3.8__py3-none-any.whl → 1.3.9__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.
infrahub/core/account.py CHANGED
@@ -5,9 +5,10 @@ from typing import TYPE_CHECKING, Any
5
5
 
6
6
  from typing_extensions import Self
7
7
 
8
- from infrahub.core.constants import InfrahubKind, PermissionDecision
8
+ from infrahub.core.constants import NULL_VALUE, InfrahubKind, PermissionDecision
9
9
  from infrahub.core.query import Query, QueryType
10
10
  from infrahub.core.registry import registry
11
+ from infrahub.core.timestamp import Timestamp
11
12
 
12
13
  if TYPE_CHECKING:
13
14
  from infrahub.core.branch import Branch
@@ -519,47 +520,72 @@ class AccountTokenValidateQuery(Query):
519
520
  super().__init__(**kwargs)
520
521
 
521
522
  async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
522
- token_filter_perms, token_params = self.branch.get_query_filter_relationships(
523
- rel_labels=["r1", "r2"], at=self.at, include_outside_parentheses=True
523
+ branch_filter, branch_params = self.branch.get_query_filter_path(
524
+ at=self.at.to_string(), branch_agnostic=self.branch_agnostic, is_isolated=False
524
525
  )
525
- self.params.update(token_params)
526
-
527
- account_filter_perms, account_params = self.branch.get_query_filter_relationships(
528
- rel_labels=["r31", "r41", "r5", "r6"], at=self.at, include_outside_parentheses=True
526
+ self.params.update(branch_params)
527
+ self.params.update(
528
+ {
529
+ "token_attr_name": "token",
530
+ "token_relationship_name": "account__token",
531
+ "token_value": self.token,
532
+ "null_value": NULL_VALUE,
533
+ }
529
534
  )
530
- self.params.update(account_params)
531
535
 
532
- self.params["token_value"] = self.token
533
-
534
- # ruff: noqa: E501
535
536
  query = """
536
- MATCH (at:InternalAccountToken)-[r1:HAS_ATTRIBUTE]-(a:Attribute {name: "token"})-[r2:HAS_VALUE]-(av:AttributeValue { value: $token_value })
537
- WHERE %s
538
- WITH at
539
- MATCH (at)-[r31]-(:Relationship)-[r41]-(acc:CoreGenericAccount)-[r5:HAS_ATTRIBUTE]-(an:Attribute {name: "name"})-[r6:HAS_VALUE]-(av:AttributeValue)
540
- WHERE %s
541
- """ % (
542
- "\n AND ".join(token_filter_perms),
543
- "\n AND ".join(account_filter_perms),
544
- )
545
-
537
+ // --------------
538
+ // get the active token node for this token value, if it exists
539
+ // --------------
540
+ MATCH (token_node:%(token_node_kind)s)-[r1:HAS_ATTRIBUTE]->(:Attribute {name: $token_attr_name})
541
+ -[r2:HAS_VALUE]->(av:AttributeValue { value: $token_value })
542
+ WHERE all(r in [r1, r2] WHERE (%(branch_filter)s))
543
+ ORDER BY r1.branch_level DESC, r1.from DESC, r1.status ASC, r2.branch_level DESC, r2.from DESC, r2.status ASC
544
+ LIMIT 1
545
+ WITH token_node
546
+ WHERE r1.status = "active" AND r2.status = "active"
547
+ // --------------
548
+ // get the expiration time
549
+ // --------------
550
+ OPTIONAL MATCH (token_node)-[r1:HAS_ATTRIBUTE]->(:Attribute {name: "expiration"})
551
+ -[r2:HAS_VALUE]->(av)
552
+ WHERE all(r in [r1, r2] WHERE (%(branch_filter)s))
553
+ ORDER BY r1.branch_level DESC, r1.from DESC, r1.status ASC, r2.branch_level DESC, r2.from DESC, r2.status ASC
554
+ LIMIT 1
555
+ WITH token_node, CASE
556
+ WHEN r1.status = "active" AND r2.status = "active" AND av.value <> $null_value THEN av.value
557
+ ELSE NULL
558
+ END AS expiration
559
+ // --------------
560
+ // get the linked account node from the token node
561
+ // --------------
562
+ MATCH (token_node)-[r1:IS_RELATED]-(:Relationship {name: $token_relationship_name})-[r2:IS_RELATED]-(account_node:%(account_node_kind)s)
563
+ WHERE all(r in [r1, r2] WHERE (%(branch_filter)s))
564
+ ORDER BY r1.branch_level DESC, r1.from DESC, r1.status ASC, r2.branch_level DESC, r2.from DESC, r2.status ASC
565
+ LIMIT 1
566
+ WITH expiration, account_node
567
+ WHERE r1.status = "active" AND r2.status = "active"
568
+ """ % {
569
+ "branch_filter": branch_filter,
570
+ "token_node_kind": InfrahubKind.ACCOUNTTOKEN,
571
+ "account_node_kind": InfrahubKind.GENERICACCOUNT,
572
+ }
546
573
  self.add_to_query(query)
547
-
548
- self.return_labels = ["at", "av", "acc"]
549
-
550
- def get_account_name(self) -> str | None:
551
- """Return the account name that matched the query or None."""
552
- if result := self.get_result():
553
- return result.get("av").get("value")
554
-
555
- return None
574
+ self.return_labels = ["account_node.uuid AS account_uuid", "expiration"]
556
575
 
557
576
  def get_account_id(self) -> str | None:
558
577
  """Return the account id that matched the query or a None."""
559
- if result := self.get_result():
560
- return result.get("acc").get("uuid")
561
-
562
- return None
578
+ result = self.get_result()
579
+ if not result:
580
+ return None
581
+ account_uuid = result.get_as_str(label="account_uuid")
582
+ expiration_with_tz = result.get_as_str(label="expiration")
583
+ if expiration_with_tz is None:
584
+ return account_uuid
585
+ expiration = Timestamp(expiration_with_tz)
586
+ if expiration < Timestamp():
587
+ return None
588
+ return account_uuid
563
589
 
564
590
 
565
591
  async def validate_token(token: str, db: InfrahubDatabase, branch: Branch | str | None = None) -> str | None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: infrahub-server
3
- Version: 1.3.8
3
+ Version: 1.3.9
4
4
  Summary: Infrahub is taking a new approach to Infrastructure Management by providing a new generation of datastore to organize and control all the data that defines how an infrastructure should run.
5
5
  License: Apache-2.0
6
6
  Author: OpsMill
@@ -59,7 +59,7 @@ infrahub/constants/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
59
59
  infrahub/constants/database.py,sha256=WmV1iuOk4xulxZHOVvO3sS_VF1eTf7fKh0TPe_RnfV4,507
60
60
  infrahub/context.py,sha256=8SZRKSECkkcsNNzDaKEUJ7Nyr0EzUfToAy969LXjQVk,1554
61
61
  infrahub/core/__init__.py,sha256=z6EJBZyCYCBqinoBtX9li6BTBbbGV8WCkE_4CrEsmDA,104
62
- infrahub/core/account.py,sha256=s8ZC7J8rtEvQZQjbVuiKMlPhl6aQjtAjbZhBejLC0X8,26182
62
+ infrahub/core/account.py,sha256=RHJfKad7uEsoJLfYCJy_Qzu-qGIJQ4tkEIxyc2AwkSY,27470
63
63
  infrahub/core/attribute.py,sha256=stmJ_dOr7rFTXzH80keuE64f6y3K3393GiSYeOaay3s,44257
64
64
  infrahub/core/branch/__init__.py,sha256=h0oIj0gHp1xI-N1cYW8_N6VZ81CBOmLuiUt5cS5nKuk,49
65
65
  infrahub/core/branch/enums.py,sha256=vGnaTCzikvMcLikKN25TJ8uCmhnD448dp1ve1_tLjwQ,186
@@ -810,8 +810,8 @@ infrahub_testcontainers/models.py,sha256=ASYyvl7d_WQz_i7y8-3iab9hwwmCl3OCJavqVbe
810
810
  infrahub_testcontainers/performance_test.py,sha256=hvwiy6tc_lWniYqGkqfOXVGAmA_IV15VOZqbiD9ezno,6149
811
811
  infrahub_testcontainers/plugin.py,sha256=I3RuZQ0dARyKHuqCf0y1Yj731P2Mwf3BJUehRJKeWrs,5645
812
812
  infrahub_testcontainers/prometheus.yml,sha256=610xQEyj3xuVJMzPkC4m1fRnCrjGpiRBrXA2ytCLa54,599
813
- infrahub_server-1.3.8.dist-info/LICENSE.txt,sha256=7GQO7kxVoQYnZtFrjZBKLRXbrGwwwimHPPOJtqXsozQ,11340
814
- infrahub_server-1.3.8.dist-info/METADATA,sha256=AM93SvBG4Wl4D53wWQ9ktQPK0ZqIa87Osu0e0EWFOBg,8189
815
- infrahub_server-1.3.8.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
816
- infrahub_server-1.3.8.dist-info/entry_points.txt,sha256=UXIeFWDsrV-4IllNvUEd6KieYGzQfn9paga2YyABOQI,393
817
- infrahub_server-1.3.8.dist-info/RECORD,,
813
+ infrahub_server-1.3.9.dist-info/LICENSE.txt,sha256=7GQO7kxVoQYnZtFrjZBKLRXbrGwwwimHPPOJtqXsozQ,11340
814
+ infrahub_server-1.3.9.dist-info/METADATA,sha256=g8W3hQDrz6WZLYsqp7mEd7iCaEWnDDtGd6jqNpZI86M,8189
815
+ infrahub_server-1.3.9.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
816
+ infrahub_server-1.3.9.dist-info/entry_points.txt,sha256=UXIeFWDsrV-4IllNvUEd6KieYGzQfn9paga2YyABOQI,393
817
+ infrahub_server-1.3.9.dist-info/RECORD,,