intflow-authctl 0.1.8__tar.gz → 0.2.0__tar.gz

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 (80) hide show
  1. intflow_authctl-0.2.0/.gitignore +8 -0
  2. intflow_authctl-0.2.0/PKG-INFO +62 -0
  3. intflow_authctl-0.2.0/README.md +41 -0
  4. intflow_authctl-0.2.0/pyproject.toml +86 -0
  5. intflow_authctl-0.2.0/src/intflow_authctl/__init__.py +3 -0
  6. intflow_authctl-0.2.0/src/intflow_authctl/api_client.py +141 -0
  7. intflow_authctl-0.2.0/src/intflow_authctl/audit.py +39 -0
  8. intflow_authctl-0.2.0/src/intflow_authctl/cli.py +57 -0
  9. intflow_authctl-0.2.0/src/intflow_authctl/clients.py +173 -0
  10. intflow_authctl-0.2.0/src/intflow_authctl/command_utils.py +36 -0
  11. intflow_authctl-0.2.0/src/intflow_authctl/commands.py +234 -0
  12. {intflow_authctl-0.1.8/src/intflow_auth/authctl_cli → intflow_authctl-0.2.0/src/intflow_authctl}/config.py +204 -151
  13. {intflow_authctl-0.1.8/src/intflow_auth/authctl_cli → intflow_authctl-0.2.0/src/intflow_authctl}/constants.py +7 -7
  14. intflow_authctl-0.1.8/src/intflow_auth/authctl_credentials.py → intflow_authctl-0.2.0/src/intflow_authctl/credentials.py +57 -57
  15. {intflow_authctl-0.1.8/src/intflow_auth/authctl_cli → intflow_authctl-0.2.0/src/intflow_authctl}/errors.py +5 -5
  16. {intflow_authctl-0.1.8/src/intflow_auth/authctl_cli → intflow_authctl-0.2.0/src/intflow_authctl}/output.py +166 -152
  17. {intflow_authctl-0.1.8/src/intflow_auth/authctl_cli → intflow_authctl-0.2.0/src/intflow_authctl}/parser.py +695 -633
  18. {intflow_authctl-0.1.8/src/intflow_auth → intflow_authctl-0.2.0/src/intflow_authctl}/py.typed +1 -1
  19. intflow_authctl-0.2.0/src/intflow_authctl/tokens.py +63 -0
  20. intflow_authctl-0.2.0/src/intflow_authctl/users.py +119 -0
  21. intflow_authctl-0.2.0/src/intflow_authctl/validation.py +218 -0
  22. intflow_authctl-0.1.8/.gitignore +0 -53
  23. intflow_authctl-0.1.8/PKG-INFO +0 -56
  24. intflow_authctl-0.1.8/README.package.md +0 -28
  25. intflow_authctl-0.1.8/pyproject.toml +0 -102
  26. intflow_authctl-0.1.8/src/intflow_auth/__init__.py +0 -3
  27. intflow_authctl-0.1.8/src/intflow_auth/admin_auth.py +0 -512
  28. intflow_authctl-0.1.8/src/intflow_auth/api/__init__.py +0 -1
  29. intflow_authctl-0.1.8/src/intflow_auth/api/admin_app_roles.py +0 -197
  30. intflow_authctl-0.1.8/src/intflow_auth/api/admin_audit.py +0 -77
  31. intflow_authctl-0.1.8/src/intflow_auth/api/admin_clients.py +0 -346
  32. intflow_authctl-0.1.8/src/intflow_auth/api/admin_operator_tokens.py +0 -357
  33. intflow_authctl-0.1.8/src/intflow_auth/api/admin_roles.py +0 -232
  34. intflow_authctl-0.1.8/src/intflow_auth/api/admin_users.py +0 -243
  35. intflow_authctl-0.1.8/src/intflow_auth/api/cli_login.py +0 -341
  36. intflow_authctl-0.1.8/src/intflow_auth/api/dependencies.py +0 -77
  37. intflow_authctl-0.1.8/src/intflow_auth/api/health.py +0 -25
  38. intflow_authctl-0.1.8/src/intflow_auth/api/login.py +0 -495
  39. intflow_authctl-0.1.8/src/intflow_auth/api/oauth.py +0 -595
  40. intflow_authctl-0.1.8/src/intflow_auth/api/oidc.py +0 -137
  41. intflow_authctl-0.1.8/src/intflow_auth/api/pagination.py +0 -19
  42. intflow_authctl-0.1.8/src/intflow_auth/api/rate_limits.py +0 -57
  43. intflow_authctl-0.1.8/src/intflow_auth/api/router.py +0 -30
  44. intflow_authctl-0.1.8/src/intflow_auth/api/session_management.py +0 -268
  45. intflow_authctl-0.1.8/src/intflow_auth/app.py +0 -183
  46. intflow_authctl-0.1.8/src/intflow_auth/app_roles.py +0 -531
  47. intflow_authctl-0.1.8/src/intflow_auth/audit.py +0 -370
  48. intflow_authctl-0.1.8/src/intflow_auth/authctl_cli/__init__.py +0 -1
  49. intflow_authctl-0.1.8/src/intflow_auth/authctl_cli/api_client.py +0 -114
  50. intflow_authctl-0.1.8/src/intflow_auth/authctl_cli/commands.py +0 -578
  51. intflow_authctl-0.1.8/src/intflow_auth/authctl_cli/validation.py +0 -70
  52. intflow_authctl-0.1.8/src/intflow_auth/authorization_codes.py +0 -531
  53. intflow_authctl-0.1.8/src/intflow_auth/bootstrap.py +0 -297
  54. intflow_authctl-0.1.8/src/intflow_auth/cli.py +0 -213
  55. intflow_authctl-0.1.8/src/intflow_auth/cli_login_service.py +0 -483
  56. intflow_authctl-0.1.8/src/intflow_auth/cli_login_transactions.py +0 -621
  57. intflow_authctl-0.1.8/src/intflow_auth/config.py +0 -467
  58. intflow_authctl-0.1.8/src/intflow_auth/context.py +0 -43
  59. intflow_authctl-0.1.8/src/intflow_auth/csrf.py +0 -59
  60. intflow_authctl-0.1.8/src/intflow_auth/database.py +0 -101
  61. intflow_authctl-0.1.8/src/intflow_auth/errors.py +0 -61
  62. intflow_authctl-0.1.8/src/intflow_auth/google_oauth.py +0 -600
  63. intflow_authctl-0.1.8/src/intflow_auth/logging.py +0 -246
  64. intflow_authctl-0.1.8/src/intflow_auth/login_transactions.py +0 -481
  65. intflow_authctl-0.1.8/src/intflow_auth/middleware.py +0 -24
  66. intflow_authctl-0.1.8/src/intflow_auth/oauth_clients.py +0 -640
  67. intflow_authctl-0.1.8/src/intflow_auth/oauth_service.py +0 -681
  68. intflow_authctl-0.1.8/src/intflow_auth/operator_admin_tokens.py +0 -558
  69. intflow_authctl-0.1.8/src/intflow_auth/pagination.py +0 -102
  70. intflow_authctl-0.1.8/src/intflow_auth/rate_limits.py +0 -114
  71. intflow_authctl-0.1.8/src/intflow_auth/readiness.py +0 -240
  72. intflow_authctl-0.1.8/src/intflow_auth/refresh_tokens.py +0 -559
  73. intflow_authctl-0.1.8/src/intflow_auth/roles.py +0 -290
  74. intflow_authctl-0.1.8/src/intflow_auth/secret_resolution.py +0 -339
  75. intflow_authctl-0.1.8/src/intflow_auth/sessions.py +0 -525
  76. intflow_authctl-0.1.8/src/intflow_auth/signing_keys.py +0 -298
  77. intflow_authctl-0.1.8/src/intflow_auth/store_resolver.py +0 -286
  78. intflow_authctl-0.1.8/src/intflow_auth/tokens.py +0 -78
  79. intflow_authctl-0.1.8/src/intflow_auth/usage_metadata.py +0 -15
  80. intflow_authctl-0.1.8/src/intflow_auth/users.py +0 -592
@@ -0,0 +1,8 @@
1
+ /dist/
2
+ /.coverage*
3
+ /coverage*.json
4
+ /.pytest_cache/
5
+ /.mypy_cache/
6
+ /.ruff_cache/
7
+ /**/__pycache__/
8
+ *.egg-info/
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.4
2
+ Name: intflow-authctl
3
+ Version: 0.2.0
4
+ Summary: Intflow Auth operator CLI.
5
+ Author: Intflow
6
+ License: Proprietary
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: httpx<1,>=0.28
9
+ Requires-Dist: keyring<26,>=25
10
+ Provides-Extra: dev
11
+ Requires-Dist: build<2,>=1.2; extra == 'dev'
12
+ Requires-Dist: hatchling<2,>=1.27; extra == 'dev'
13
+ Requires-Dist: mypy<3,>=1.13; extra == 'dev'
14
+ Requires-Dist: packaging<27,>=24; extra == 'dev'
15
+ Requires-Dist: pytest-cov<8,>=6; extra == 'dev'
16
+ Requires-Dist: pytest-timeout<3,>=2.4; extra == 'dev'
17
+ Requires-Dist: pytest<10,>=8; extra == 'dev'
18
+ Requires-Dist: ruff<1,>=0.9; extra == 'dev'
19
+ Requires-Dist: twine<7,>=6; extra == 'dev'
20
+ Description-Content-Type: text/markdown
21
+
22
+ # intflow-authctl
23
+
24
+ `intflow-authctl` is the Python operator CLI package for Intflow Auth.
25
+
26
+ ## Install
27
+
28
+ ```powershell
29
+ py -3.12 -m pip install --user --upgrade intflow-authctl
30
+ ```
31
+
32
+ ## CLI
33
+
34
+ ```powershell
35
+ intflow-authctl login
36
+ intflow-authctl whoami
37
+ intflow-authctl users list
38
+ intflow-authctl clients list
39
+ intflow-authctl clients rotate-secret <oauth-client-id> --grace-seconds 0
40
+ intflow-authctl logout --revoke
41
+ ```
42
+
43
+ The CLI is intended for authorized Intflow operators. It manages local operator
44
+ credentials through the supported credential backends and communicates with an
45
+ Intflow Auth deployment over the Admin API.
46
+
47
+ Failed commands return a nonzero exit code and write a bounded diagnostic to
48
+ stderr. Admin HTTP failures include only the status, a validated service error
49
+ code when present, and bounded `Retry-After` guidance. Upstream descriptions,
50
+ malformed bodies, credentials, and raw transport causes are not rendered.
51
+ Automation should parse JSON stdout only after a successful command.
52
+
53
+ ## Package Scope
54
+
55
+ This distribution contains only the operator CLI, Admin API client, output and
56
+ validation logic, and credential-store adapters. It does not contain the Auth
57
+ service, database models, migrations, or service bootstrap commands.
58
+
59
+ ## Requirements
60
+
61
+ - Python 3.12 or later.
62
+ - Access to an authorized Intflow Auth deployment.
@@ -0,0 +1,41 @@
1
+ # intflow-authctl
2
+
3
+ `intflow-authctl` is the Python operator CLI package for Intflow Auth.
4
+
5
+ ## Install
6
+
7
+ ```powershell
8
+ py -3.12 -m pip install --user --upgrade intflow-authctl
9
+ ```
10
+
11
+ ## CLI
12
+
13
+ ```powershell
14
+ intflow-authctl login
15
+ intflow-authctl whoami
16
+ intflow-authctl users list
17
+ intflow-authctl clients list
18
+ intflow-authctl clients rotate-secret <oauth-client-id> --grace-seconds 0
19
+ intflow-authctl logout --revoke
20
+ ```
21
+
22
+ The CLI is intended for authorized Intflow operators. It manages local operator
23
+ credentials through the supported credential backends and communicates with an
24
+ Intflow Auth deployment over the Admin API.
25
+
26
+ Failed commands return a nonzero exit code and write a bounded diagnostic to
27
+ stderr. Admin HTTP failures include only the status, a validated service error
28
+ code when present, and bounded `Retry-After` guidance. Upstream descriptions,
29
+ malformed bodies, credentials, and raw transport causes are not rendered.
30
+ Automation should parse JSON stdout only after a successful command.
31
+
32
+ ## Package Scope
33
+
34
+ This distribution contains only the operator CLI, Admin API client, output and
35
+ validation logic, and credential-store adapters. It does not contain the Auth
36
+ service, database models, migrations, or service bootstrap commands.
37
+
38
+ ## Requirements
39
+
40
+ - Python 3.12 or later.
41
+ - Access to an authorized Intflow Auth deployment.
@@ -0,0 +1,86 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "intflow-authctl"
7
+ version = "0.2.0"
8
+ description = "Intflow Auth operator CLI."
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = { text = "Proprietary" }
12
+ authors = [
13
+ { name = "Intflow" }
14
+ ]
15
+ dependencies = [
16
+ "httpx>=0.28,<1",
17
+ "keyring>=25,<26"
18
+ ]
19
+
20
+ [project.scripts]
21
+ intflow-authctl = "intflow_authctl.cli:authctl_main"
22
+
23
+ [project.optional-dependencies]
24
+ dev = [
25
+ "build>=1.2,<2",
26
+ "hatchling>=1.27,<2",
27
+ "mypy>=1.13,<3",
28
+ "packaging>=24,<27",
29
+ "pytest>=8,<10",
30
+ "pytest-cov>=6,<8",
31
+ "pytest-timeout>=2.4,<3",
32
+ "ruff>=0.9,<1",
33
+ "twine>=6,<7"
34
+ ]
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/intflow_authctl"]
38
+
39
+ [tool.hatch.build.targets.sdist]
40
+ ignore-vcs = true
41
+ include = [
42
+ "/README.md",
43
+ "/pyproject.toml",
44
+ "/src/intflow_authctl"
45
+ ]
46
+ exclude = [
47
+ "/.gitignore"
48
+ ]
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
52
+ pythonpath = ["src"]
53
+ timeout = 30
54
+ filterwarnings = [
55
+ "error"
56
+ ]
57
+
58
+ [tool.coverage.run]
59
+ source = ["intflow_authctl"]
60
+ branch = true
61
+
62
+ [tool.coverage.report]
63
+ fail_under = 0
64
+ show_missing = true
65
+ skip_covered = true
66
+
67
+ [tool.mypy]
68
+ python_version = "3.12"
69
+ show_error_codes = true
70
+ warn_unused_configs = true
71
+ files = ["src/intflow_authctl"]
72
+
73
+ [tool.ruff]
74
+ line-length = 100
75
+ target-version = "py312"
76
+ src = ["src", "tests"]
77
+
78
+ [tool.ruff.lint]
79
+ select = [
80
+ "E",
81
+ "F",
82
+ "I",
83
+ "UP",
84
+ "B",
85
+ "SIM"
86
+ ]
@@ -0,0 +1,3 @@
1
+ """Internal implementation package for the Intflow Auth operator CLI."""
2
+
3
+ __version__ = "0.2.0"
@@ -0,0 +1,141 @@
1
+ """HTTP transport helpers for the Intflow Auth operator CLI."""
2
+
3
+ import re
4
+
5
+ import httpx
6
+
7
+ from intflow_authctl.constants import DEFAULT_AUTHCTL_TIMEOUT_SECONDS
8
+ from intflow_authctl.errors import AuthctlError
9
+ from intflow_authctl.validation import _normalize_base_url
10
+
11
+ MAX_RETRY_AFTER_SECONDS = 86_400
12
+ MAX_ERROR_BODY_BYTES = 16_384
13
+
14
+
15
+ def _api_request(
16
+ config: dict[str, object],
17
+ method: str,
18
+ path: str,
19
+ *,
20
+ client_factory,
21
+ json_body: dict[str, object] | None = None,
22
+ params: dict[str, object] | None = None,
23
+ ) -> dict[str, object]:
24
+ base_url = config.get("base_url")
25
+ token = config.get("token")
26
+ if not isinstance(base_url, str) or not isinstance(token, str):
27
+ raise AuthctlError("Run intflow-authctl login before calling Admin APIs.")
28
+
29
+ headers = {"Authorization": f"Bearer {token}"}
30
+ return _api_request_to_base_url(
31
+ base_url,
32
+ method,
33
+ path,
34
+ headers=headers,
35
+ json_body=json_body,
36
+ params=params,
37
+ client_factory=client_factory,
38
+ )
39
+
40
+
41
+ def _api_request_without_auth(
42
+ base_url: str,
43
+ method: str,
44
+ path: str,
45
+ *,
46
+ client_factory,
47
+ json_body: dict[str, object] | None = None,
48
+ ) -> dict[str, object]:
49
+ return _api_request_to_base_url(
50
+ base_url,
51
+ method,
52
+ path,
53
+ headers={},
54
+ json_body=json_body,
55
+ params=None,
56
+ client_factory=client_factory,
57
+ )
58
+
59
+
60
+ def _api_request_to_base_url(
61
+ base_url: str,
62
+ method: str,
63
+ path: str,
64
+ *,
65
+ headers: dict[str, str],
66
+ client_factory,
67
+ json_body: dict[str, object] | None,
68
+ params: dict[str, object] | None,
69
+ ) -> dict[str, object]:
70
+ base_url = _normalize_base_url(base_url)
71
+ try:
72
+ with client_factory(
73
+ base_url=base_url,
74
+ headers=headers,
75
+ timeout=DEFAULT_AUTHCTL_TIMEOUT_SECONDS,
76
+ ) as client:
77
+ request_kwargs: dict[str, object] = {"params": params}
78
+ if json_body is not None:
79
+ request_kwargs["json"] = json_body
80
+ response = client.request(
81
+ method,
82
+ path,
83
+ follow_redirects=False,
84
+ **request_kwargs,
85
+ )
86
+ except httpx.TimeoutException:
87
+ raise AuthctlError("Admin API request timed out.") from None
88
+ except httpx.HTTPError:
89
+ raise AuthctlError("Admin API request failed.") from None
90
+ if 300 <= response.status_code < 400:
91
+ raise AuthctlError("Admin API redirect was refused to protect the bearer token.")
92
+ if response.status_code >= 400:
93
+ retry_after = _retry_after_seconds(response.headers.get("retry-after"))
94
+ retry_message = (
95
+ "" if retry_after is None else f" Retry after {retry_after} seconds."
96
+ )
97
+ raise AuthctlError(
98
+ f"Admin API request failed: {response.status_code} "
99
+ f"{_safe_error_message(response)}.{retry_message}"
100
+ )
101
+ if response.status_code == 204 or not response.content:
102
+ return {"status": "ok"}
103
+ try:
104
+ data = response.json()
105
+ except ValueError:
106
+ raise AuthctlError("Admin API returned an unexpected non-JSON response.") from None
107
+ if not isinstance(data, dict):
108
+ raise AuthctlError("Admin API returned an unexpected response.")
109
+ return data
110
+
111
+
112
+ def _required_response_string(response: dict[str, object], key: str) -> str:
113
+ value = response.get(key)
114
+ if not isinstance(value, str) or not value:
115
+ raise AuthctlError(f"Admin API response did not include {key}.")
116
+ return value
117
+
118
+
119
+ def _safe_error_message(response: httpx.Response) -> str:
120
+ if not response.content:
121
+ return "error response"
122
+ if len(response.content) > MAX_ERROR_BODY_BYTES:
123
+ return "invalid error response"
124
+ try:
125
+ data = response.json()
126
+ except ValueError:
127
+ return "invalid error response"
128
+ if isinstance(data, dict):
129
+ error = data.get("error")
130
+ if isinstance(error, dict):
131
+ code = error.get("code")
132
+ if isinstance(code, str) and re.fullmatch(r"[A-Za-z0-9_.:-]{1,128}", code):
133
+ return code
134
+ return "invalid error response"
135
+
136
+
137
+ def _retry_after_seconds(value: str | None) -> int | None:
138
+ if value is None or not value.isdigit():
139
+ return None
140
+ seconds = int(value)
141
+ return seconds if 0 <= seconds <= MAX_RETRY_AFTER_SECONDS else None
@@ -0,0 +1,39 @@
1
+ """Audit-event command handlers for authctl."""
2
+
3
+ import argparse
4
+
5
+ from intflow_authctl.api_client import _api_request
6
+ from intflow_authctl.errors import AuthctlError
7
+
8
+
9
+ def _run_authctl_audit_command(
10
+ args: argparse.Namespace,
11
+ config: dict[str, object],
12
+ *,
13
+ client_factory,
14
+ ) -> dict[str, object]:
15
+ if args.audit_command == "list":
16
+ params = {
17
+ name: value
18
+ for name in (
19
+ "actor_user_id",
20
+ "target_user_id",
21
+ "user_id",
22
+ "client_id",
23
+ "event_type",
24
+ "correlation_id",
25
+ "occurred_after",
26
+ "occurred_before",
27
+ "limit",
28
+ "cursor",
29
+ )
30
+ if (value := getattr(args, name)) is not None
31
+ }
32
+ return _api_request(
33
+ config,
34
+ "GET",
35
+ "/v1/admin/audit-events",
36
+ params=params or None,
37
+ client_factory=client_factory,
38
+ )
39
+ raise AuthctlError(f"Unsupported audit command: {args.audit_command}")
@@ -0,0 +1,57 @@
1
+ """Operator Admin API command-line entry point."""
2
+
3
+ import sys
4
+ from typing import TextIO
5
+
6
+ import httpx
7
+
8
+ from intflow_authctl.commands import _run_authctl_command
9
+ from intflow_authctl.constants import (
10
+ AUTHCTL_CONFIG_ENV,
11
+ AUTHCTL_CREDENTIAL_SERVICE,
12
+ DEFAULT_AUTHCTL_BASE_URL,
13
+ DEFAULT_AUTHCTL_LOGIN_TTL,
14
+ DEFAULT_AUTHCTL_TIMEOUT_SECONDS,
15
+ )
16
+ from intflow_authctl.credentials import AuthctlCredentialStore
17
+ from intflow_authctl.errors import AuthctlError
18
+ from intflow_authctl.output import _print_authctl_result
19
+ from intflow_authctl.parser import AuthctlArgumentParser, _build_authctl_parser
20
+
21
+ __all__ = [
22
+ "AUTHCTL_CONFIG_ENV",
23
+ "AUTHCTL_CREDENTIAL_SERVICE",
24
+ "DEFAULT_AUTHCTL_BASE_URL",
25
+ "DEFAULT_AUTHCTL_LOGIN_TTL",
26
+ "DEFAULT_AUTHCTL_TIMEOUT_SECONDS",
27
+ "AuthctlArgumentParser",
28
+ "AuthctlError",
29
+ "authctl_main",
30
+ ]
31
+
32
+
33
+ def authctl_main(
34
+ argv: list[str] | None = None,
35
+ *,
36
+ output: TextIO = sys.stdout,
37
+ error_output: TextIO = sys.stderr,
38
+ input_stream: TextIO = sys.stdin,
39
+ client_factory=httpx.Client,
40
+ credential_store: AuthctlCredentialStore | None = None,
41
+ ) -> None:
42
+ """Run the routine operator Admin API CLI."""
43
+ parser = _build_authctl_parser()
44
+ args = parser.parse_args(argv)
45
+ try:
46
+ result = _run_authctl_command(
47
+ args,
48
+ output=output,
49
+ error_output=error_output,
50
+ input_stream=input_stream,
51
+ client_factory=client_factory,
52
+ credential_store=credential_store,
53
+ )
54
+ except AuthctlError as exc:
55
+ parser.exit(status=2, message=f"{exc}\n")
56
+ if result is not None:
57
+ _print_authctl_result(args, result, output)
@@ -0,0 +1,173 @@
1
+ """OAuth client command handlers for authctl."""
2
+
3
+ import argparse
4
+
5
+ from intflow_authctl.api_client import _api_request
6
+ from intflow_authctl.command_utils import (
7
+ _enabled_filter_value,
8
+ _request_params,
9
+ _with_match_count,
10
+ )
11
+ from intflow_authctl.errors import AuthctlError
12
+ from intflow_authctl.validation import (
13
+ OAuthClientValidationError,
14
+ validate_oauth_scopes,
15
+ validate_redirect_uris,
16
+ )
17
+
18
+
19
+ def _run_authctl_clients_command(
20
+ args: argparse.Namespace,
21
+ config: dict[str, object],
22
+ *,
23
+ client_factory,
24
+ ) -> dict[str, object]:
25
+ if args.clients_command == "list":
26
+ return _api_request(
27
+ config,
28
+ "GET",
29
+ "/v1/admin/clients",
30
+ params=_request_params(
31
+ args,
32
+ "limit",
33
+ "cursor",
34
+ extra={"enabled": _enabled_filter_value(args)},
35
+ ),
36
+ client_factory=client_factory,
37
+ )
38
+ if args.clients_command == "find":
39
+ response = _api_request(
40
+ config,
41
+ "GET",
42
+ "/v1/admin/clients",
43
+ params=_request_params(
44
+ args,
45
+ "name",
46
+ "query",
47
+ "limit",
48
+ "cursor",
49
+ extra={"enabled": _enabled_filter_value(args)},
50
+ ),
51
+ client_factory=client_factory,
52
+ )
53
+ return _with_match_count(response, "clients")
54
+ if args.clients_command == "create":
55
+ create_body: dict[str, object] = {
56
+ "name": args.name,
57
+ "client_type": args.client_type,
58
+ "redirect_uris": list(_validate_cli_redirect_uris(args.redirect_uri)),
59
+ "allowed_scopes": list(_validate_cli_scopes(args.scopes)),
60
+ }
61
+ if args.admin_access_required:
62
+ create_body["admin_access_required"] = True
63
+ return _api_request(
64
+ config,
65
+ "POST",
66
+ "/v1/admin/clients",
67
+ json_body=create_body,
68
+ client_factory=client_factory,
69
+ )
70
+ if args.clients_command == "update":
71
+ update_body: dict[str, object] = {}
72
+ if args.name is not None:
73
+ update_body["name"] = args.name
74
+ if args.redirect_uris is not None:
75
+ update_body["redirect_uris"] = list(
76
+ _validate_cli_redirect_uris(args.redirect_uris)
77
+ )
78
+ if args.scopes is not None:
79
+ update_body["allowed_scopes"] = list(_validate_cli_scopes(args.scopes))
80
+ if args.enable:
81
+ update_body["enabled"] = True
82
+ if args.disable:
83
+ update_body["enabled"] = False
84
+ if args.admin_access_required:
85
+ update_body["admin_access_required"] = True
86
+ if args.no_admin_access_required:
87
+ update_body["admin_access_required"] = False
88
+ if not update_body:
89
+ raise AuthctlError("At least one client update field is required.")
90
+ return _api_request(
91
+ config,
92
+ "PATCH",
93
+ f"/v1/admin/clients/{args.client_id}",
94
+ json_body=update_body,
95
+ client_factory=client_factory,
96
+ )
97
+ if args.clients_command == "disable":
98
+ return _api_request(
99
+ config,
100
+ "POST",
101
+ f"/v1/admin/clients/{args.client_id}:disable",
102
+ client_factory=client_factory,
103
+ )
104
+ if args.clients_command == "rotate-secret":
105
+ rotate_body = _rotate_secret_body(args.grace_seconds)
106
+ return _api_request(
107
+ config,
108
+ "POST",
109
+ f"/v1/admin/clients/{args.client_id}:rotate-secret",
110
+ json_body=rotate_body,
111
+ client_factory=client_factory,
112
+ )
113
+ if args.clients_command == "admins":
114
+ return _run_authctl_client_admins_command(
115
+ args,
116
+ config,
117
+ client_factory=client_factory,
118
+ )
119
+ raise AuthctlError(f"Unsupported clients command: {args.clients_command}")
120
+
121
+
122
+ def _run_authctl_client_admins_command(
123
+ args: argparse.Namespace,
124
+ config: dict[str, object],
125
+ *,
126
+ client_factory,
127
+ ) -> dict[str, object]:
128
+ base_path = f"/v1/admin/clients/{args.client_id}/admins"
129
+ if args.client_admins_command == "list":
130
+ return _api_request(
131
+ config,
132
+ "GET",
133
+ base_path,
134
+ params=_request_params(args, "limit", "cursor"),
135
+ client_factory=client_factory,
136
+ )
137
+ if args.client_admins_command == "grant":
138
+ return _api_request(
139
+ config,
140
+ "PUT",
141
+ f"{base_path}/{args.user_id}",
142
+ client_factory=client_factory,
143
+ )
144
+ if args.client_admins_command == "revoke":
145
+ return _api_request(
146
+ config,
147
+ "DELETE",
148
+ f"{base_path}/{args.user_id}",
149
+ client_factory=client_factory,
150
+ )
151
+ raise AuthctlError(f"Unsupported clients admins command: {args.client_admins_command}")
152
+
153
+
154
+ def _validate_cli_redirect_uris(values: list[str]) -> tuple[str, ...]:
155
+ try:
156
+ return validate_redirect_uris(values)
157
+ except OAuthClientValidationError as exc:
158
+ raise AuthctlError(str(exc)) from exc
159
+
160
+
161
+ def _validate_cli_scopes(values: list[str]) -> tuple[str, ...]:
162
+ try:
163
+ return validate_oauth_scopes(values)
164
+ except OAuthClientValidationError as exc:
165
+ raise AuthctlError(str(exc)) from exc
166
+
167
+
168
+ def _rotate_secret_body(grace_seconds: int | None) -> dict[str, object] | None:
169
+ if grace_seconds is None:
170
+ return None
171
+ if grace_seconds < 0 or grace_seconds > 86_400:
172
+ raise AuthctlError("--grace-seconds must be between 0 and 86400.")
173
+ return {"grace_seconds": grace_seconds}
@@ -0,0 +1,36 @@
1
+ """Shared helpers for authctl command-family modules."""
2
+
3
+ import argparse
4
+
5
+ from intflow_authctl.output import _response_list
6
+
7
+
8
+ def _request_params(
9
+ args: argparse.Namespace,
10
+ *names: str,
11
+ extra: dict[str, object] | None = None,
12
+ ) -> dict[str, object] | None:
13
+ params = {
14
+ name: value
15
+ for name in names
16
+ if (value := getattr(args, name, None)) is not None
17
+ }
18
+ if extra is not None:
19
+ params.update({name: value for name, value in extra.items() if value is not None})
20
+ return params or None
21
+
22
+
23
+ def _enabled_filter_value(args: argparse.Namespace) -> bool | None:
24
+ if getattr(args, "enabled", False):
25
+ return True
26
+ if getattr(args, "disabled", False):
27
+ return False
28
+ return None
29
+
30
+
31
+ def _with_match_count(
32
+ response: dict[str, object],
33
+ key: str,
34
+ ) -> dict[str, object]:
35
+ records = _response_list(response, key)
36
+ return {**response, "match_count": len(records)}