ingot-auth 0.1.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.
Files changed (241) hide show
  1. ingot_auth/__init__.py +10 -0
  2. ingot_auth/__main__.py +46 -0
  3. ingot_auth/access/__init__.py +29 -0
  4. ingot_auth/access/groups/__init__.py +111 -0
  5. ingot_auth/access/groups/commands.py +38 -0
  6. ingot_auth/access/groups/entities.py +52 -0
  7. ingot_auth/access/groups/errors.py +38 -0
  8. ingot_auth/access/groups/items.py +15 -0
  9. ingot_auth/access/groups/operations.py +30 -0
  10. ingot_auth/access/groups/permissions.py +11 -0
  11. ingot_auth/access/groups/v1/__init__.py +0 -0
  12. ingot_auth/access/groups/v1/groups.proto +29 -0
  13. ingot_auth/access/groups/v1/groups_pb2.py +48 -0
  14. ingot_auth/access/groups/v1/groups_pb2.pyi +120 -0
  15. ingot_auth/access/groups/v1/groups_pb2_grpc.py +101 -0
  16. ingot_auth/access/groups/v1/groups_pb2_grpc.pyi +58 -0
  17. ingot_auth/access/members/__init__.py +53 -0
  18. ingot_auth/access/members/commands.py +122 -0
  19. ingot_auth/access/members/operations.py +134 -0
  20. ingot_auth/access/members/permissions.py +13 -0
  21. ingot_auth/access/members/v1/__init__.py +0 -0
  22. ingot_auth/access/members/v1/members.proto +58 -0
  23. ingot_auth/access/members/v1/members_pb2.py +56 -0
  24. ingot_auth/access/members/v1/members_pb2.pyi +214 -0
  25. ingot_auth/access/members/v1/members_pb2_grpc.py +233 -0
  26. ingot_auth/access/members/v1/members_pb2_grpc.pyi +94 -0
  27. ingot_auth/access/strategies.py +36 -0
  28. ingot_auth/auth/__init__.py +41 -0
  29. ingot_auth/caches/__init__.py +37 -0
  30. ingot_auth/caches/attempts.py +40 -0
  31. ingot_auth/caches/callers.py +72 -0
  32. ingot_auth/caches/errors.py +20 -0
  33. ingot_auth/caches/items.py +46 -0
  34. ingot_auth/caches/sessions.py +53 -0
  35. ingot_auth/contrib/__init__.py +4 -0
  36. ingot_auth/contrib/caches/__init__.py +4 -0
  37. ingot_auth/contrib/caches/memory/__init__.py +28 -0
  38. ingot_auth/contrib/caches/memory/attempts.py +40 -0
  39. ingot_auth/contrib/caches/memory/callers.py +51 -0
  40. ingot_auth/contrib/caches/memory/sessions.py +47 -0
  41. ingot_auth/contrib/storages/__init__.py +4 -0
  42. ingot_auth/contrib/storages/memory/__init__.py +84 -0
  43. ingot_auth/contrib/storages/memory/access/__init__.py +15 -0
  44. ingot_auth/contrib/storages/memory/access/members.py +36 -0
  45. ingot_auth/contrib/storages/memory/profiles/__init__.py +55 -0
  46. ingot_auth/contrib/storages/memory/profiles/attrs.py +11 -0
  47. ingot_auth/contrib/storages/memory/profiles/identities.py +39 -0
  48. ingot_auth/contrib/storages/memory/profiles/secrets.py +31 -0
  49. ingot_auth/contrib/storages/memory/profiles/tags.py +11 -0
  50. ingot_auth/contrib/storages/memory/registry.py +67 -0
  51. ingot_auth/contrib/storages/memory/sessions/__init__.py +76 -0
  52. ingot_auth/contrib/storages/memory/sessions/attrs.py +13 -0
  53. ingot_auth/contrib/storages/memory/sessions/presets.py +59 -0
  54. ingot_auth/contrib/storages/memory/sign_up/__init__.py +15 -0
  55. ingot_auth/contrib/storages/memory/sign_up/records.py +37 -0
  56. ingot_auth/contrib/storages/memory/state.py +32 -0
  57. ingot_auth/contrib/storages/mongodb/__init__.py +104 -0
  58. ingot_auth/contrib/storages/mongodb/access/__init__.py +15 -0
  59. ingot_auth/contrib/storages/mongodb/access/members.py +63 -0
  60. ingot_auth/contrib/storages/mongodb/collection.py +80 -0
  61. ingot_auth/contrib/storages/mongodb/profiles/__init__.py +62 -0
  62. ingot_auth/contrib/storages/mongodb/profiles/attrs.py +32 -0
  63. ingot_auth/contrib/storages/mongodb/profiles/identities.py +59 -0
  64. ingot_auth/contrib/storages/mongodb/profiles/secrets.py +38 -0
  65. ingot_auth/contrib/storages/mongodb/profiles/tags.py +26 -0
  66. ingot_auth/contrib/storages/mongodb/registry.py +102 -0
  67. ingot_auth/contrib/storages/mongodb/sessions/__init__.py +113 -0
  68. ingot_auth/contrib/storages/mongodb/sessions/attrs.py +42 -0
  69. ingot_auth/contrib/storages/mongodb/sessions/presets.py +89 -0
  70. ingot_auth/contrib/storages/mongodb/sign_up/__init__.py +15 -0
  71. ingot_auth/contrib/storages/mongodb/sign_up/records.py +54 -0
  72. ingot_auth/contrib/storages/mongodb/values.py +44 -0
  73. ingot_auth/contrib/transports/__init__.py +1 -0
  74. ingot_auth/contrib/transports/grpcio/__init__.py +79 -0
  75. ingot_auth/contrib/transports/grpcio/access/__init__.py +30 -0
  76. ingot_auth/contrib/transports/grpcio/access/groups.py +31 -0
  77. ingot_auth/contrib/transports/grpcio/access/members.py +56 -0
  78. ingot_auth/contrib/transports/grpcio/base.py +84 -0
  79. ingot_auth/contrib/transports/grpcio/errors.py +232 -0
  80. ingot_auth/contrib/transports/grpcio/metadata.py +114 -0
  81. ingot_auth/contrib/transports/grpcio/methods/__init__.py +17 -0
  82. ingot_auth/contrib/transports/grpcio/methods/nickname.py +78 -0
  83. ingot_auth/contrib/transports/grpcio/profiles/__init__.py +28 -0
  84. ingot_auth/contrib/transports/grpcio/profiles/attrs.py +87 -0
  85. ingot_auth/contrib/transports/grpcio/profiles/tags.py +62 -0
  86. ingot_auth/contrib/transports/grpcio/sessions/__init__.py +34 -0
  87. ingot_auth/contrib/transports/grpcio/sessions/attrs.py +180 -0
  88. ingot_auth/contrib/transports/grpcio/sessions/presets.py +113 -0
  89. ingot_auth/contrib/transports/grpcio/sign_in.py +19 -0
  90. ingot_auth/contrib/transports/grpcio/sign_up.py +15 -0
  91. ingot_auth/logging/__init__.py +25 -0
  92. ingot_auth/metadata/__init__.py +31 -0
  93. ingot_auth/metadata/items.py +64 -0
  94. ingot_auth/metadata/operations.py +73 -0
  95. ingot_auth/metadata/permissions.py +11 -0
  96. ingot_auth/metadata/v1/__init__.py +0 -0
  97. ingot_auth/metadata/v1/metadata.proto +86 -0
  98. ingot_auth/metadata/v1/metadata_pb2.py +60 -0
  99. ingot_auth/metadata/v1/metadata_pb2.pyi +301 -0
  100. ingot_auth/metadata/v1/metadata_pb2_grpc.py +107 -0
  101. ingot_auth/metadata/v1/metadata_pb2_grpc.pyi +67 -0
  102. ingot_auth/methods/__init__.py +104 -0
  103. ingot_auth/methods/base.py +200 -0
  104. ingot_auth/methods/email_code/__init__.py +172 -0
  105. ingot_auth/methods/email_code/configs.py +16 -0
  106. ingot_auth/methods/email_code/permissions.py +15 -0
  107. ingot_auth/methods/email_code/policies.py +28 -0
  108. ingot_auth/methods/errors.py +96 -0
  109. ingot_auth/methods/nickname/__init__.py +124 -0
  110. ingot_auth/methods/nickname/configs.py +16 -0
  111. ingot_auth/methods/nickname/permissions.py +15 -0
  112. ingot_auth/methods/nickname/policies.py +30 -0
  113. ingot_auth/methods/nickname/v1/__init__.py +0 -0
  114. ingot_auth/methods/nickname/v1/nickname.proto +45 -0
  115. ingot_auth/methods/nickname/v1/nickname_pb2.py +49 -0
  116. ingot_auth/methods/nickname/v1/nickname_pb2.pyi +136 -0
  117. ingot_auth/methods/nickname/v1/nickname_pb2_grpc.py +148 -0
  118. ingot_auth/methods/nickname/v1/nickname_pb2_grpc.pyi +76 -0
  119. ingot_auth/methods/operations.py +185 -0
  120. ingot_auth/methods/password/__init__.py +102 -0
  121. ingot_auth/methods/password/policies.py +41 -0
  122. ingot_auth/methods/password/scrypt.py +61 -0
  123. ingot_auth/methods/steps.py +33 -0
  124. ingot_auth/policies/__init__.py +32 -0
  125. ingot_auth/policies/chars.py +78 -0
  126. ingot_auth/policies/errors.py +24 -0
  127. ingot_auth/policies/length.py +36 -0
  128. ingot_auth/policies/parameters.py +16 -0
  129. ingot_auth/profiles/__init__.py +23 -0
  130. ingot_auth/profiles/attrs/__init__.py +44 -0
  131. ingot_auth/profiles/attrs/commands.py +112 -0
  132. ingot_auth/profiles/attrs/operations.py +68 -0
  133. ingot_auth/profiles/attrs/permissions.py +14 -0
  134. ingot_auth/profiles/attrs/v1/__init__.py +0 -0
  135. ingot_auth/profiles/attrs/v1/attrs.proto +69 -0
  136. ingot_auth/profiles/attrs/v1/attrs_pb2.py +58 -0
  137. ingot_auth/profiles/attrs/v1/attrs_pb2.pyi +243 -0
  138. ingot_auth/profiles/attrs/v1/attrs_pb2_grpc.py +233 -0
  139. ingot_auth/profiles/attrs/v1/attrs_pb2_grpc.pyi +94 -0
  140. ingot_auth/profiles/tags/__init__.py +44 -0
  141. ingot_auth/profiles/tags/commands.py +72 -0
  142. ingot_auth/profiles/tags/operations.py +68 -0
  143. ingot_auth/profiles/tags/permissions.py +14 -0
  144. ingot_auth/profiles/tags/v1/__init__.py +0 -0
  145. ingot_auth/profiles/tags/v1/tags.proto +59 -0
  146. ingot_auth/profiles/tags/v1/tags_pb2.py +56 -0
  147. ingot_auth/profiles/tags/v1/tags_pb2.pyi +217 -0
  148. ingot_auth/profiles/tags/v1/tags_pb2_grpc.py +233 -0
  149. ingot_auth/profiles/tags/v1/tags_pb2_grpc.pyi +94 -0
  150. ingot_auth/project.py +24 -0
  151. ingot_auth/py.typed +0 -0
  152. ingot_auth/registry/__init__.py +12 -0
  153. ingot_auth/registry/commands.py +141 -0
  154. ingot_auth/registry/errors.py +51 -0
  155. ingot_auth/registry/operations.py +111 -0
  156. ingot_auth/sessions/__init__.py +164 -0
  157. ingot_auth/sessions/attrs/__init__.py +49 -0
  158. ingot_auth/sessions/attrs/commands.py +128 -0
  159. ingot_auth/sessions/attrs/operations.py +69 -0
  160. ingot_auth/sessions/attrs/permissions.py +14 -0
  161. ingot_auth/sessions/attrs/v1/__init__.py +0 -0
  162. ingot_auth/sessions/attrs/v1/attrs.proto +97 -0
  163. ingot_auth/sessions/attrs/v1/attrs_pb2.py +63 -0
  164. ingot_auth/sessions/attrs/v1/attrs_pb2.pyi +314 -0
  165. ingot_auth/sessions/attrs/v1/attrs_pb2_grpc.py +233 -0
  166. ingot_auth/sessions/attrs/v1/attrs_pb2_grpc.pyi +94 -0
  167. ingot_auth/sessions/attrs/values.py +43 -0
  168. ingot_auth/sessions/errors.py +22 -0
  169. ingot_auth/sessions/items.py +16 -0
  170. ingot_auth/sessions/lifetimes.py +53 -0
  171. ingot_auth/sessions/presets/__init__.py +61 -0
  172. ingot_auth/sessions/presets/commands.py +184 -0
  173. ingot_auth/sessions/presets/operations.py +146 -0
  174. ingot_auth/sessions/presets/permissions.py +16 -0
  175. ingot_auth/sessions/presets/v1/__init__.py +0 -0
  176. ingot_auth/sessions/presets/v1/presets.proto +96 -0
  177. ingot_auth/sessions/presets/v1/presets_pb2.py +70 -0
  178. ingot_auth/sessions/presets/v1/presets_pb2.pyi +360 -0
  179. ingot_auth/sessions/presets/v1/presets_pb2_grpc.py +368 -0
  180. ingot_auth/sessions/presets/v1/presets_pb2_grpc.pyi +136 -0
  181. ingot_auth/settings/__init__.py +14 -0
  182. ingot_auth/settings/configs.py +23 -0
  183. ingot_auth/sign_in/__init__.py +49 -0
  184. ingot_auth/sign_in/items.py +59 -0
  185. ingot_auth/sign_in/operations.py +149 -0
  186. ingot_auth/sign_in/permissions.py +14 -0
  187. ingot_auth/sign_in/timings.py +74 -0
  188. ingot_auth/sign_in/v1/__init__.py +0 -0
  189. ingot_auth/sign_in/v1/sign_in.proto +27 -0
  190. ingot_auth/sign_in/v1/sign_in_pb2.py +40 -0
  191. ingot_auth/sign_in/v1/sign_in_pb2.pyi +90 -0
  192. ingot_auth/sign_in/v1/sign_in_pb2_grpc.py +24 -0
  193. ingot_auth/sign_in/v1/sign_in_pb2_grpc.pyi +20 -0
  194. ingot_auth/sign_up/__init__.py +36 -0
  195. ingot_auth/sign_up/items.py +54 -0
  196. ingot_auth/sign_up/operations.py +148 -0
  197. ingot_auth/sign_up/permissions.py +14 -0
  198. ingot_auth/sign_up/v1/__init__.py +0 -0
  199. ingot_auth/sign_up/v1/sign_up.proto +25 -0
  200. ingot_auth/sign_up/v1/sign_up_pb2.py +40 -0
  201. ingot_auth/sign_up/v1/sign_up_pb2.pyi +85 -0
  202. ingot_auth/sign_up/v1/sign_up_pb2_grpc.py +24 -0
  203. ingot_auth/sign_up/v1/sign_up_pb2_grpc.pyi +20 -0
  204. ingot_auth/storages/__init__.py +222 -0
  205. ingot_auth/storages/access/__init__.py +19 -0
  206. ingot_auth/storages/access/items.py +16 -0
  207. ingot_auth/storages/access/members.py +53 -0
  208. ingot_auth/storages/errors.py +80 -0
  209. ingot_auth/storages/items.py +47 -0
  210. ingot_auth/storages/profiles/__init__.py +81 -0
  211. ingot_auth/storages/profiles/attrs.py +14 -0
  212. ingot_auth/storages/profiles/errors.py +88 -0
  213. ingot_auth/storages/profiles/identities.py +45 -0
  214. ingot_auth/storages/profiles/items.py +49 -0
  215. ingot_auth/storages/profiles/secrets.py +42 -0
  216. ingot_auth/storages/profiles/tags.py +14 -0
  217. ingot_auth/storages/registry.py +72 -0
  218. ingot_auth/storages/sessions/__init__.py +100 -0
  219. ingot_auth/storages/sessions/attrs.py +14 -0
  220. ingot_auth/storages/sessions/errors.py +28 -0
  221. ingot_auth/storages/sessions/items.py +102 -0
  222. ingot_auth/storages/sessions/presets.py +57 -0
  223. ingot_auth/storages/sign_up/__init__.py +22 -0
  224. ingot_auth/storages/sign_up/errors.py +21 -0
  225. ingot_auth/storages/sign_up/items.py +26 -0
  226. ingot_auth/storages/sign_up/records.py +36 -0
  227. ingot_auth/testing/__init__.py +1 -0
  228. ingot_auth/testing/contracts/__init__.py +49 -0
  229. ingot_auth/testing/contracts/access.py +50 -0
  230. ingot_auth/testing/contracts/base.py +31 -0
  231. ingot_auth/testing/contracts/cache.py +154 -0
  232. ingot_auth/testing/contracts/profiles.py +112 -0
  233. ingot_auth/testing/contracts/sessions.py +83 -0
  234. ingot_auth/testing/contracts/sign_up.py +36 -0
  235. ingot_auth/testing/contracts/storage.py +355 -0
  236. ingot_auth/testing/contracts/transactions.py +105 -0
  237. ingot_auth/testing/methods.py +104 -0
  238. ingot_auth-0.1.0.dist-info/METADATA +85 -0
  239. ingot_auth-0.1.0.dist-info/RECORD +241 -0
  240. ingot_auth-0.1.0.dist-info/WHEEL +4 -0
  241. ingot_auth-0.1.0.dist-info/licenses/LICENSE +201 -0
ingot_auth/__init__.py ADDED
@@ -0,0 +1,10 @@
1
+ """
2
+ ingot-auth: the sign-up, the sign-in and the sessions of the users of Ingots
3
+ applications. An application inherits from :class:`AuthProject`, or joins
4
+ the units of the addon, ``settings``, ``logging`` and ``auth``, with those of
5
+ its other addons.
6
+ """
7
+
8
+ __all__ = ("AuthProject",)
9
+
10
+ from .project import AuthProject
ingot_auth/__main__.py ADDED
@@ -0,0 +1,46 @@
1
+ """
2
+ Runs the addon on its own: ``python -m ingot_auth logging info``. The
3
+ storage and the cache are in memory, so what a command stores is gone with
4
+ it.
5
+ """
6
+
7
+ import sys
8
+
9
+ from ingots.defaults.logging import configure_startup_logging
10
+ from ingots.puer import Slot
11
+ from ingots.puer.cli import CommandRunner
12
+
13
+ from .auth import AuthUnit
14
+ from .contrib.caches.memory import AuthMemoryCache
15
+ from .contrib.storages.memory import AuthMemoryStorage
16
+ from .project import AuthProject
17
+ from .sessions import AuthFixedLifetime, AuthSessionsUnit
18
+ from .sign_in import AuthNoTiming, AuthSignInUnit
19
+
20
+
21
+ class AuthMemorySessionsUnit(AuthSessionsUnit):
22
+ lifetime = Slot(AuthFixedLifetime)
23
+
24
+
25
+ class AuthMemorySignInUnit(AuthSignInUnit):
26
+ timing = Slot(AuthNoTiming)
27
+
28
+
29
+ class AuthMemoryUnit(AuthUnit):
30
+ storage = Slot(AuthMemoryStorage)
31
+ cache = Slot(AuthMemoryCache)
32
+ sessions = Slot(AuthMemorySessionsUnit)
33
+ sign_in = Slot(AuthMemorySignInUnit)
34
+
35
+
36
+ class AuthMemoryProject(AuthProject):
37
+ auth = Slot(AuthMemoryUnit)
38
+
39
+
40
+ def main() -> None:
41
+ configure_startup_logging()
42
+ sys.exit(CommandRunner(AuthMemoryProject).run())
43
+
44
+
45
+ if __name__ == "__main__":
46
+ main()
@@ -0,0 +1,29 @@
1
+ """
2
+ The access: the groups of the users, what each grants, and the members of
3
+ each. The permissions of a signed-in user are the union of what its groups
4
+ grant, by the strategy of the slot ``permissions``. An application declares
5
+ its groups in its own :class:`AuthGroupsUnit`::
6
+
7
+ class AppAccessUnit(AuthAccessUnit):
8
+ groups = Slot(AppGroupsUnit)
9
+ """
10
+
11
+ __all__ = ("AuthAccessUnit", "AuthGroupsGrants")
12
+
13
+ from ingots.puer import Slot
14
+ from ingots.puer.cli import CliUnit
15
+
16
+ from .groups import AuthGroupsUnit
17
+ from .members import AuthMembersUnit
18
+ from .strategies import AuthGroupsGrants
19
+
20
+
21
+ class AuthAccessUnit(CliUnit):
22
+ """The access: the groups, their members and the permissions of a user."""
23
+
24
+ cli_name = "access"
25
+ cli_description = "The groups of the users and their members."
26
+
27
+ groups = Slot(AuthGroupsUnit)
28
+ members = Slot(AuthMembersUnit)
29
+ permissions = Slot(AuthGroupsGrants)
@@ -0,0 +1,111 @@
1
+ """
2
+ The groups of the users, each granting permissions. The code is their
3
+ source, the first: an application declares them as slots of
4
+ :class:`AuthGroupsUnit`, the name of the slot the name of the group::
5
+
6
+ class AppGroupsUnit(AuthGroupsUnit):
7
+ admins = Slot(AdminsGroup)
8
+
9
+ The core declares one, ``signed_in``, :class:`AuthSignedInGroup`, of every
10
+ signed-in user.
11
+ """
12
+
13
+ __all__ = (
14
+ "AuthGroup",
15
+ "AuthGroupError",
16
+ "AuthGroupInfo",
17
+ "AuthGroupNotFoundError",
18
+ "AuthGroupsUnit",
19
+ "AuthGroupsPermissions",
20
+ "AuthListGroupsOperation",
21
+ "AuthListGroupsCommand",
22
+ "AuthSignedInGroup",
23
+ )
24
+
25
+ import hashlib
26
+ import json
27
+ import re
28
+ import typing as t
29
+
30
+ from ingots.puer import Factory, Slot
31
+ from ingots.puer.cli import CliUnit
32
+
33
+ from .commands import AuthListGroupsCommand
34
+ from .entities import AuthGroup, AuthSignedInGroup
35
+ from .errors import AuthGroupError, AuthGroupNotFoundError
36
+ from .items import AuthGroupInfo
37
+ from .operations import AuthListGroupsOperation
38
+ from .permissions import AuthGroupsPermissions
39
+
40
+ # a name is of the scripts and the memberships, for good
41
+ NAME_PATTERN: t.Final = re.compile(r"[a-z][a-z0-9_]*")
42
+
43
+
44
+ class AuthGroupsUnit(CliUnit):
45
+ """
46
+ The groups, ``signed_in`` here, of every signed-in user: whatever their
47
+ source, they come by :meth:`get` and :meth:`get_all`. A name of a group
48
+ is lowercase letters, digits and ``_``, checked when the class is
49
+ created.
50
+ """
51
+
52
+ cli_name = "groups"
53
+ cli_description = "The groups of the users."
54
+
55
+ op_list = Factory(AuthListGroupsOperation)
56
+
57
+ cmd_list = Slot(AuthListGroupsCommand)
58
+
59
+ signed_in = Slot(AuthSignedInGroup)
60
+
61
+ _digest: str
62
+
63
+ @t.override
64
+ @classmethod
65
+ def __init_subclass__(cls, **kwargs: t.Any) -> None:
66
+ super().__init_subclass__(**kwargs)
67
+ for name, _ in cls.slots_iter(AuthGroup):
68
+ if NAME_PATTERN.fullmatch(name) is None:
69
+ raise TypeError(
70
+ f"{cls.__qualname__}.{name}: a name of a group is lowercase "
71
+ f"letters, digits and '_'"
72
+ )
73
+
74
+ @t.final
75
+ def get_all(self) -> tuple[AuthGroup, ...]:
76
+ """The groups, in the order of their slots."""
77
+ return tuple(
78
+ self.slots_find_entity(name, AuthGroup)
79
+ for name, _ in type(self).slots_iter(AuthGroup)
80
+ )
81
+
82
+ @t.final
83
+ def get(self, name: str) -> AuthGroup:
84
+ """
85
+ The group of a name.
86
+
87
+ :raises AuthGroupNotFoundError: no group has the name.
88
+ """
89
+ try:
90
+ return self.slots_find_entity(name, AuthGroup)
91
+ except LookupError:
92
+ raise AuthGroupNotFoundError.for_name(name) from None
93
+
94
+ @t.final
95
+ def get_digest(self) -> str:
96
+ """
97
+ A digest of the groups and what each grants, computed once, as they
98
+ change with a deploy only: the key of a caller in the cache holds it,
99
+ so that a deploy changing them finds none of the callers formed
100
+ before.
101
+ """
102
+ try:
103
+ return self._digest
104
+ except AttributeError:
105
+ pass
106
+ grants = sorted(
107
+ (group.get_name(), sorted(group.get_permissions().items()))
108
+ for group in self.get_all()
109
+ )
110
+ self._digest = hashlib.sha256(json.dumps(grants).encode()).hexdigest()
111
+ return self._digest
@@ -0,0 +1,38 @@
1
+ """The commands of the groups."""
2
+
3
+ __all__ = ("AuthListGroupsCommand",)
4
+
5
+ import typing as t
6
+
7
+ from ingots.defaults.operations import BaseOperationCommand
8
+
9
+ from .items import AuthGroupInfo
10
+ from .operations import AuthListGroupsOperation
11
+
12
+ if t.TYPE_CHECKING:
13
+ from ingots.puer import BoundFactory
14
+
15
+ from ingot_auth.project import AuthProject
16
+
17
+
18
+ class AuthListGroupsCommand(BaseOperationCommand[None, tuple[AuthGroupInfo, ...]]):
19
+ """
20
+ Prints the groups, one a line: the name, then what it grants, a mask a
21
+ domain, sorted by the domain: ``auth.access.members=3``.
22
+ """
23
+
24
+ project: "AuthProject"
25
+
26
+ cli_name = "list"
27
+ cli_description = "Prints the groups and what each grants."
28
+
29
+ @t.override
30
+ def _get_operation(self) -> "BoundFactory[AuthListGroupsOperation]":
31
+ return self.project.auth.access.groups.op_list
32
+
33
+ @t.override
34
+ async def _run(self) -> None:
35
+ for group in await self.run_operation(None):
36
+ permissions = sorted(group.permissions.items())
37
+ masks = (f"{domain}={mask}" for domain, mask in permissions)
38
+ print("\t".join((group.name, *masks)))
@@ -0,0 +1,52 @@
1
+ """The groups: what each grants, declared in the code."""
2
+
3
+ __all__ = ("AuthGroup", "AuthSignedInGroup")
4
+
5
+ import typing as t
6
+
7
+ from ingots.defaults.operations import Permissions
8
+ from ingots.puer import Entity
9
+
10
+ if t.TYPE_CHECKING:
11
+ from ingot_auth.project import AuthProject
12
+
13
+
14
+ class AuthGroup(Entity):
15
+ """
16
+ A group of the users, a slot of :class:`AuthGroupsUnit`, its name the name
17
+ of the slot. What it grants is of its hook, :meth:`_get_permissions`,
18
+ nothing here: each class adds its own to ``super()``, so that an addon
19
+ and the application grant to the same group, the application declaring
20
+ the class that joins them.
21
+ """
22
+
23
+ project: "AuthProject"
24
+
25
+ @t.final
26
+ def get_name(self) -> str:
27
+ """The name of the group: the path of its slot in the groups."""
28
+ return self.project.auth.access.groups.slots_find_path(self)
29
+
30
+ @t.final
31
+ def get_permissions(self) -> Permissions:
32
+ """What the group grants: the union of the hooks of its classes."""
33
+ return self._get_permissions()
34
+
35
+ def _get_permissions(self) -> Permissions:
36
+ """What the class grants, with ``super()``: nothing here."""
37
+ return Permissions()
38
+
39
+
40
+ class AuthSignedInGroup(AuthGroup):
41
+ """
42
+ The group ``signed_in`` of the core: every signed-in user is a member,
43
+ none stored. It grants what the methods give a signed-in user by their
44
+ toggles, the ``CAN_SIGN_IN`` of each method open; what an application
45
+ and its addons grant every signed-in user, they add by the hook, the
46
+ application declaring the class that joins them in the slot.
47
+ """
48
+
49
+ @t.override
50
+ def _get_permissions(self) -> Permissions:
51
+ methods = self.project.auth.methods
52
+ return super()._get_permissions() | methods.get_signed_in_permissions()
@@ -0,0 +1,38 @@
1
+ """The errors of the groups."""
2
+
3
+ __all__ = ("AuthGroupError", "AuthGroupNotFoundError")
4
+
5
+ import typing as t
6
+
7
+
8
+ class AuthGroupError(Exception):
9
+ """
10
+ An error of a group. ``args`` are the message and the name of the
11
+ group, so the error survives pickling; create it with the class methods
12
+ of its subclasses.
13
+ """
14
+
15
+ @property
16
+ def name(self) -> str:
17
+ return t.cast(str, self.args[1])
18
+
19
+ @t.override
20
+ def __str__(self) -> str:
21
+ return str(self.args[0])
22
+
23
+
24
+ class AuthGroupNotFoundError(AuthGroupError):
25
+ """No group has the name, or the group keeps no members to tell of."""
26
+
27
+ @classmethod
28
+ def for_name(cls, name: str) -> t.Self:
29
+ """No source of the groups has one of the name."""
30
+ return cls(f"no group {name!r}", name)
31
+
32
+ @classmethod
33
+ def for_members(cls, name: str) -> t.Self:
34
+ """
35
+ The group keeps no members: every signed-in user is one, none is
36
+ added, removed or listed.
37
+ """
38
+ return cls(f"the group {name!r} has every signed-in user", name)
@@ -0,0 +1,15 @@
1
+ """What the operations of the groups give."""
2
+
3
+ __all__ = ("AuthGroupInfo",)
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from ingots.defaults.operations import Permissions
8
+
9
+
10
+ @dataclass(frozen=True, slots=True, kw_only=True)
11
+ class AuthGroupInfo:
12
+ """A group as an operator reads it: its name and what it grants."""
13
+
14
+ name: str
15
+ permissions: Permissions
@@ -0,0 +1,30 @@
1
+ """The operations of the groups."""
2
+
3
+ __all__ = ("AuthListGroupsOperation",)
4
+
5
+ import typing as t
6
+
7
+ from ingots.defaults.operations import BaseOperation, OperationMetadata, Permissions
8
+
9
+ from .items import AuthGroupInfo
10
+ from .permissions import AuthGroupsPermissions
11
+
12
+ if t.TYPE_CHECKING:
13
+ from ingot_auth.project import AuthProject
14
+
15
+
16
+ class AuthListGroupsOperation(BaseOperation[None, tuple[AuthGroupInfo, ...]]):
17
+ """The groups, in the order of their slots, each with what it grants."""
18
+
19
+ PERMISSIONS = Permissions(AuthGroupsPermissions.CAN_READ)
20
+
21
+ project: "AuthProject"
22
+
23
+ @t.override
24
+ async def _run(
25
+ self, parameters: None, metadata: OperationMetadata
26
+ ) -> tuple[AuthGroupInfo, ...]:
27
+ return tuple(
28
+ AuthGroupInfo(name=group.get_name(), permissions=group.get_permissions())
29
+ for group in self.project.auth.access.groups.get_all()
30
+ )
@@ -0,0 +1,11 @@
1
+ """The permissions of the groups."""
2
+
3
+ __all__ = ("AuthGroupsPermissions",)
4
+
5
+ from ingots.defaults.operations import PermissionFlags
6
+
7
+
8
+ class AuthGroupsPermissions(PermissionFlags, domain="auth.access.groups"):
9
+ """The operations on the groups, which the code declares: reading them."""
10
+
11
+ CAN_READ = 1 << 0
File without changes
@@ -0,0 +1,29 @@
1
+ syntax = "proto3";
2
+
3
+ package ingot_auth.access.groups.v1;
4
+
5
+ // The groups of the users, declared in the code of the server: read only.
6
+ service Groups {
7
+ // Requires PERMISSION_CAN_READ.
8
+ rpc ListGroups(ListGroupsRequest) returns (ListGroupsResponse);
9
+ }
10
+
11
+ // The bits of the domain `auth.access.groups` the RPCs require: an aid for a
12
+ // client building its interface, the server checks them anyway.
13
+ enum Permission {
14
+ PERMISSION_UNSPECIFIED = 0;
15
+ PERMISSION_CAN_READ = 1;
16
+ }
17
+
18
+ // A group: its name and what it grants, a mask by the domain of the
19
+ // permissions.
20
+ message Group {
21
+ string name = 1;
22
+ map<string, uint64> permissions = 2;
23
+ }
24
+
25
+ message ListGroupsRequest {}
26
+
27
+ message ListGroupsResponse {
28
+ repeated Group groups = 1;
29
+ }
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # NO CHECKED-IN PROTOBUF GENCODE
4
+ # source: ingot_auth/access/groups/v1/groups.proto
5
+ # Protobuf Python Version: 7.35.1
6
+ """Generated protocol buffer code."""
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import descriptor_pool as _descriptor_pool
9
+ from google.protobuf import runtime_version as _runtime_version
10
+ from google.protobuf import symbol_database as _symbol_database
11
+ from google.protobuf.internal import builder as _builder
12
+ _runtime_version.ValidateProtobufRuntimeVersion(
13
+ _runtime_version.Domain.PUBLIC,
14
+ 7,
15
+ 35,
16
+ 1,
17
+ '',
18
+ 'ingot_auth/access/groups/v1/groups.proto'
19
+ )
20
+ # @@protoc_insertion_point(imports)
21
+
22
+ _sym_db = _symbol_database.Default()
23
+
24
+
25
+
26
+
27
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n(ingot_auth/access/groups/v1/groups.proto\x12\x1bingot_auth.access.groups.v1\"\x93\x01\n\x05Group\x12\x0c\n\x04name\x18\x01 \x01(\t\x12H\n\x0bpermissions\x18\x02 \x03(\x0b\x32\x33.ingot_auth.access.groups.v1.Group.PermissionsEntry\x1a\x32\n\x10PermissionsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x04:\x02\x38\x01\"\x13\n\x11ListGroupsRequest\"H\n\x12ListGroupsResponse\x12\x32\n\x06groups\x18\x01 \x03(\x0b\x32\".ingot_auth.access.groups.v1.Group*A\n\nPermission\x12\x1a\n\x16PERMISSION_UNSPECIFIED\x10\x00\x12\x17\n\x13PERMISSION_CAN_READ\x10\x01\x32w\n\x06Groups\x12m\n\nListGroups\x12..ingot_auth.access.groups.v1.ListGroupsRequest\x1a/.ingot_auth.access.groups.v1.ListGroupsResponseb\x06proto3')
28
+
29
+ _globals = globals()
30
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
31
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'ingot_auth.access.groups.v1.groups_pb2', _globals)
32
+ if not _descriptor._USE_C_DESCRIPTORS:
33
+ DESCRIPTOR._loaded_options = None
34
+ _globals['_GROUP_PERMISSIONSENTRY']._loaded_options = None
35
+ _globals['_GROUP_PERMISSIONSENTRY']._serialized_options = b'8\001'
36
+ _globals['_PERMISSION']._serialized_start=318
37
+ _globals['_PERMISSION']._serialized_end=383
38
+ _globals['_GROUP']._serialized_start=74
39
+ _globals['_GROUP']._serialized_end=221
40
+ _globals['_GROUP_PERMISSIONSENTRY']._serialized_start=171
41
+ _globals['_GROUP_PERMISSIONSENTRY']._serialized_end=221
42
+ _globals['_LISTGROUPSREQUEST']._serialized_start=223
43
+ _globals['_LISTGROUPSREQUEST']._serialized_end=242
44
+ _globals['_LISTGROUPSRESPONSE']._serialized_start=244
45
+ _globals['_LISTGROUPSRESPONSE']._serialized_end=316
46
+ _globals['_GROUPS']._serialized_start=385
47
+ _globals['_GROUPS']._serialized_end=504
48
+ # @@protoc_insertion_point(module_scope)
@@ -0,0 +1,120 @@
1
+ """
2
+ @generated by mypy-protobuf. Do not edit manually!
3
+ isort:skip_file
4
+ """
5
+
6
+ from collections import abc as _abc
7
+ from google.protobuf import descriptor as _descriptor
8
+ from google.protobuf import message as _message
9
+ from google.protobuf.internal import containers as _containers
10
+ from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper
11
+ import builtins as _builtins
12
+ import sys
13
+ import typing as _typing
14
+
15
+ if sys.version_info >= (3, 11):
16
+ from typing import TypeAlias as _TypeAlias, Never as _Never
17
+ else:
18
+ from typing_extensions import TypeAlias as _TypeAlias, Never as _Never
19
+
20
+ DESCRIPTOR: _descriptor.FileDescriptor
21
+
22
+ class _Permission:
23
+ ValueType = _typing.NewType("ValueType", _builtins.int)
24
+ V: _TypeAlias = ValueType # noqa: Y015
25
+
26
+ class _PermissionEnumTypeWrapper(_enum_type_wrapper._EnumTypeWrapper[_Permission.ValueType], _builtins.type):
27
+ DESCRIPTOR: _descriptor.EnumDescriptor
28
+ PERMISSION_UNSPECIFIED: _Permission.ValueType # 0
29
+ PERMISSION_CAN_READ: _Permission.ValueType # 1
30
+
31
+ class Permission(_Permission, metaclass=_PermissionEnumTypeWrapper):
32
+ """The bits of the domain `auth.access.groups` the RPCs require: an aid for a
33
+ client building its interface, the server checks them anyway.
34
+ """
35
+
36
+ PERMISSION_UNSPECIFIED: Permission.ValueType # 0
37
+ PERMISSION_CAN_READ: Permission.ValueType # 1
38
+ Global___Permission: _TypeAlias = Permission # noqa: Y015
39
+
40
+ @_typing.final
41
+ class Group(_message.Message):
42
+ """A group: its name and what it grants, a mask by the domain of the
43
+ permissions.
44
+ """
45
+
46
+ DESCRIPTOR: _descriptor.Descriptor
47
+
48
+ @_typing.final
49
+ class PermissionsEntry(_message.Message):
50
+ DESCRIPTOR: _descriptor.Descriptor
51
+
52
+ KEY_FIELD_NUMBER: _builtins.int
53
+ VALUE_FIELD_NUMBER: _builtins.int
54
+ key: _builtins.str
55
+ value: _builtins.int
56
+ def __init__(
57
+ self,
58
+ *,
59
+ key: _builtins.str = ...,
60
+ value: _builtins.int = ...,
61
+ ) -> None: ...
62
+ _HasFieldArgType: _TypeAlias = _Never # noqa: Y015
63
+ def HasField(self, field_name: _HasFieldArgType) -> _builtins.bool: ...
64
+ _ClearFieldArgType: _TypeAlias = _typing.Literal["key", b"key", "value", b"value"] # noqa: Y015
65
+ def ClearField(self, field_name: _ClearFieldArgType) -> None: ...
66
+ def WhichOneof(self, oneof_group: _Never) -> None: ...
67
+
68
+ NAME_FIELD_NUMBER: _builtins.int
69
+ PERMISSIONS_FIELD_NUMBER: _builtins.int
70
+ name: _builtins.str
71
+ @_builtins.property
72
+ def permissions(self) -> _containers.ScalarMap[_builtins.str, _builtins.int]: ...
73
+ def __init__(
74
+ self,
75
+ *,
76
+ name: _builtins.str = ...,
77
+ permissions: _abc.Mapping[_builtins.str, _builtins.int] | None = ...,
78
+ ) -> None: ...
79
+ _HasFieldArgType: _TypeAlias = _Never # noqa: Y015
80
+ def HasField(self, field_name: _HasFieldArgType) -> _builtins.bool: ...
81
+ _ClearFieldArgType: _TypeAlias = _typing.Literal["name", b"name", "permissions", b"permissions"] # noqa: Y015
82
+ def ClearField(self, field_name: _ClearFieldArgType) -> None: ...
83
+ def WhichOneof(self, oneof_group: _Never) -> None: ...
84
+
85
+ Global___Group: _TypeAlias = Group # noqa: Y015
86
+
87
+ @_typing.final
88
+ class ListGroupsRequest(_message.Message):
89
+ DESCRIPTOR: _descriptor.Descriptor
90
+
91
+ def __init__(
92
+ self,
93
+ ) -> None: ...
94
+ _HasFieldArgType: _TypeAlias = _Never # noqa: Y015
95
+ def HasField(self, field_name: _HasFieldArgType) -> _builtins.bool: ...
96
+ _ClearFieldArgType: _TypeAlias = _Never # noqa: Y015
97
+ def ClearField(self, field_name: _ClearFieldArgType) -> None: ...
98
+ def WhichOneof(self, oneof_group: _Never) -> None: ...
99
+
100
+ Global___ListGroupsRequest: _TypeAlias = ListGroupsRequest # noqa: Y015
101
+
102
+ @_typing.final
103
+ class ListGroupsResponse(_message.Message):
104
+ DESCRIPTOR: _descriptor.Descriptor
105
+
106
+ GROUPS_FIELD_NUMBER: _builtins.int
107
+ @_builtins.property
108
+ def groups(self) -> _containers.RepeatedCompositeFieldContainer[Global___Group]: ...
109
+ def __init__(
110
+ self,
111
+ *,
112
+ groups: _abc.Iterable[Global___Group] | None = ...,
113
+ ) -> None: ...
114
+ _HasFieldArgType: _TypeAlias = _Never # noqa: Y015
115
+ def HasField(self, field_name: _HasFieldArgType) -> _builtins.bool: ...
116
+ _ClearFieldArgType: _TypeAlias = _typing.Literal["groups", b"groups"] # noqa: Y015
117
+ def ClearField(self, field_name: _ClearFieldArgType) -> None: ...
118
+ def WhichOneof(self, oneof_group: _Never) -> None: ...
119
+
120
+ Global___ListGroupsResponse: _TypeAlias = ListGroupsResponse # noqa: Y015