golf-mcp 0.1.19__py3-none-any.whl → 0.2.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.
Potentially problematic release.
This version of golf-mcp might be problematic. Click here for more details.
- golf/__init__.py +9 -1
- golf/_endpoints.py +6 -0
- golf/_endpoints_fallback.py +10 -0
- golf/auth/__init__.py +188 -84
- golf/auth/api_key.py +6 -14
- golf/auth/factory.py +333 -0
- golf/auth/helpers.py +12 -42
- golf/auth/providers.py +396 -0
- golf/auth/registry.py +256 -0
- golf/cli/branding.py +192 -0
- golf/cli/main.py +28 -69
- golf/commands/__init__.py +2 -0
- golf/commands/build.py +4 -7
- golf/commands/init.py +30 -53
- golf/commands/run.py +50 -20
- golf/core/builder.py +356 -412
- golf/core/builder_auth.py +63 -144
- golf/core/builder_telemetry.py +26 -3
- golf/core/config.py +38 -59
- golf/core/parser.py +132 -139
- golf/core/platform.py +12 -10
- golf/core/telemetry.py +11 -19
- golf/core/transformer.py +38 -15
- golf/examples/__pycache__/__init__.cpython-311.pyc +0 -0
- golf/examples/basic/.coverage +0 -0
- golf/examples/basic/.env.example +8 -4
- golf/examples/basic/README.md +117 -45
- golf/examples/basic/__pycache__/auth.cpython-311.pyc +0 -0
- golf/examples/basic/auth.py +76 -0
- golf/examples/basic/golf.json +2 -5
- golf/examples/basic/htmlcov/.gitignore +2 -0
- golf/examples/basic/htmlcov/class_index.html +547 -0
- golf/examples/basic/htmlcov/coverage_html_cb_6fb7b396.js +733 -0
- golf/examples/basic/htmlcov/favicon_32_cb_58284776.png +0 -0
- golf/examples/basic/htmlcov/function_index.html +2091 -0
- golf/examples/basic/htmlcov/index.html +349 -0
- golf/examples/basic/htmlcov/keybd_closed_cb_ce680311.png +0 -0
- golf/examples/basic/htmlcov/status.json +1 -0
- golf/examples/basic/htmlcov/style_cb_8e611ae1.css +337 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496___init___py.html +323 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_api_key_py.html +170 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_factory_py.html +430 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_helpers_py.html +288 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_providers_py.html +493 -0
- golf/examples/basic/htmlcov/z_1c9a91c0e91c8496_registry_py.html +353 -0
- golf/examples/basic/htmlcov/z_3ec3b3f490dc0950___init___py.html +120 -0
- golf/examples/basic/htmlcov/z_3ec3b3f490dc0950_instrumentation_py.html +1535 -0
- golf/examples/basic/htmlcov/z_4b8b9dd4ccccc5db___init___py.html +98 -0
- golf/examples/basic/htmlcov/z_4b8b9dd4ccccc5db_branding_py.html +289 -0
- golf/examples/basic/htmlcov/z_4b8b9dd4ccccc5db_main_py.html +476 -0
- golf/examples/basic/htmlcov/z_5a6c4e6bcc86fb2f___init___py.html +97 -0
- golf/examples/basic/htmlcov/z_6cadab9ec0df475d___init___py.html +102 -0
- golf/examples/basic/htmlcov/z_6cadab9ec0df475d_build_py.html +178 -0
- golf/examples/basic/htmlcov/z_6cadab9ec0df475d_init_py.html +387 -0
- golf/examples/basic/htmlcov/z_6cadab9ec0df475d_run_py.html +222 -0
- golf/examples/basic/htmlcov/z_6fcdee0582ba84e4___init___py.html +106 -0
- golf/examples/basic/htmlcov/z_6fcdee0582ba84e4__endpoints_fallback_py.html +107 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217___init___py.html +98 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_auth_py.html +306 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_metrics_py.html +329 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_py.html +1471 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_builder_telemetry_py.html +186 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_config_py.html +315 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_parser_py.html +1149 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_platform_py.html +279 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_telemetry_py.html +589 -0
- golf/examples/basic/htmlcov/z_7ba499ed22986217_transformer_py.html +286 -0
- golf/examples/basic/htmlcov/z_7d7da37693a43688___init___py.html +107 -0
- golf/examples/basic/htmlcov/z_7d7da37693a43688_collector_py.html +417 -0
- golf/examples/basic/htmlcov/z_7d7da37693a43688_registry_py.html +109 -0
- golf/examples/basic/htmlcov/z_abe733142b40ad4e___init___py.html +109 -0
- golf/examples/basic/htmlcov/z_abe733142b40ad4e_context_py.html +150 -0
- golf/examples/basic/htmlcov/z_abe733142b40ad4e_elicitation_py.html +267 -0
- golf/examples/basic/htmlcov/z_abe733142b40ad4e_sampling_py.html +318 -0
- golf/examples/basic/prompts/__pycache__/welcome.cpython-311.pyc +0 -0
- golf/examples/basic/prompts/welcome.py +3 -5
- golf/examples/basic/resources/__pycache__/current_time.cpython-311.pyc +0 -0
- golf/examples/basic/resources/__pycache__/info.cpython-311.pyc +0 -0
- golf/examples/basic/resources/current_time.py +5 -13
- golf/examples/basic/resources/weather/__pycache__/common.cpython-311.pyc +0 -0
- golf/examples/basic/resources/weather/__pycache__/current.cpython-311.pyc +0 -0
- golf/examples/basic/resources/weather/__pycache__/forecast.cpython-311.pyc +0 -0
- golf/examples/basic/resources/weather/city.py +46 -0
- golf/examples/basic/resources/weather/common.py +4 -11
- golf/examples/basic/resources/weather/current.py +5 -5
- golf/examples/basic/resources/weather/forecast.py +5 -5
- golf/examples/basic/tools/__pycache__/calculator.cpython-311.pyc +0 -0
- golf/examples/basic/tools/calculator.py +94 -0
- golf/examples/basic/tools/say/__pycache__/hello.cpython-311.pyc +0 -0
- golf/examples/basic/tools/say/hello.py +65 -0
- golf/metrics/collector.py +100 -19
- golf/telemetry/__init__.py +4 -0
- golf/telemetry/instrumentation.py +496 -174
- golf/utilities/__init__.py +12 -0
- golf/utilities/context.py +53 -0
- golf/utilities/elicitation.py +170 -0
- golf/utilities/sampling.py +221 -0
- {golf_mcp-0.1.19.dist-info → golf_mcp-0.2.0.dist-info}/METADATA +56 -110
- golf_mcp-0.2.0.dist-info/RECORD +110 -0
- golf/auth/oauth.py +0 -861
- golf/auth/provider.py +0 -115
- golf/examples/api_key/.env +0 -2
- golf/examples/api_key/.env.example +0 -1
- golf/examples/api_key/README.md +0 -84
- golf/examples/api_key/golf.json +0 -8
- golf/examples/api_key/pre_build.py +0 -11
- golf/examples/api_key/tools/issues/create.py +0 -93
- golf/examples/api_key/tools/issues/list.py +0 -92
- golf/examples/api_key/tools/repos/list.py +0 -111
- golf/examples/api_key/tools/search/code.py +0 -106
- golf/examples/api_key/tools/users/get.py +0 -82
- golf/examples/basic/.env +0 -5
- golf/examples/basic/pre_build.py +0 -28
- golf/examples/basic/tools/github_user.py +0 -65
- golf/examples/basic/tools/hello.py +0 -34
- golf/examples/basic/tools/payments/charge.py +0 -70
- golf/examples/basic/tools/payments/common.py +0 -36
- golf/examples/basic/tools/payments/refund.py +0 -61
- golf_mcp-0.1.19.dist-info/RECORD +0 -60
- {golf_mcp-0.1.19.dist-info → golf_mcp-0.2.0.dist-info}/WHEEL +0 -0
- {golf_mcp-0.1.19.dist-info → golf_mcp-0.2.0.dist-info}/entry_points.txt +0 -0
- {golf_mcp-0.1.19.dist-info → golf_mcp-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {golf_mcp-0.1.19.dist-info → golf_mcp-0.2.0.dist-info}/top_level.txt +0 -0
golf/__init__.py
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.2.0"
|
|
2
|
+
|
|
3
|
+
# Import endpoints with fallback for dev mode
|
|
4
|
+
try:
|
|
5
|
+
# In built wheels, this exists (generated from _endpoints.py.in)
|
|
6
|
+
from . import _endpoints
|
|
7
|
+
except ImportError:
|
|
8
|
+
# In editable/dev installs, fall back to env-based values
|
|
9
|
+
from . import _endpoints_fallback as _endpoints
|
golf/_endpoints.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Auto-generated at build time by setup.py:build_py
|
|
2
|
+
# This template contains placeholders that are replaced during build
|
|
3
|
+
|
|
4
|
+
# Platform endpoints
|
|
5
|
+
PLATFORM_API_URL = "https://golf-backend.golf-auth-1.authed-qukc4.ryvn.run/api/resources"
|
|
6
|
+
OTEL_ENDPOINT = "https://golf-backend.golf-auth-1.authed-qukc4.ryvn.run/api/v1/otel"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Fallback endpoints for development/editable installs."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
# These are used when the generated _endpoints.py doesn't exist (dev mode)
|
|
6
|
+
# or when environment variables override the built-in values
|
|
7
|
+
|
|
8
|
+
PLATFORM_API_URL = os.getenv("GOLF_PLATFORM_API_URL", "http://localhost:8000/api/resources")
|
|
9
|
+
|
|
10
|
+
OTEL_ENDPOINT = os.getenv("GOLF_OTEL_ENDPOINT", "http://localhost:4318/v1/traces")
|
golf/auth/__init__.py
CHANGED
|
@@ -1,122 +1,226 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Modern authentication for Golf MCP servers using FastMCP 2.11+ providers.
|
|
2
2
|
|
|
3
|
-
This module provides
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
This module provides authentication configuration and utilities for Golf servers,
|
|
4
|
+
leveraging FastMCP's built-in authentication system with JWT verification,
|
|
5
|
+
OAuth providers, and token management.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from typing import
|
|
8
|
+
from typing import Any
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
# Modern auth provider configurations and factory functions
|
|
11
|
+
from .providers import (
|
|
12
|
+
AuthConfig,
|
|
13
|
+
JWTAuthConfig,
|
|
14
|
+
StaticTokenConfig,
|
|
15
|
+
OAuthServerConfig,
|
|
16
|
+
RemoteAuthConfig,
|
|
17
|
+
)
|
|
18
|
+
from .factory import (
|
|
19
|
+
create_auth_provider,
|
|
20
|
+
create_simple_jwt_provider,
|
|
21
|
+
create_dev_token_provider,
|
|
22
|
+
)
|
|
23
|
+
from .registry import (
|
|
24
|
+
BaseProviderPlugin,
|
|
25
|
+
AuthProviderFactory,
|
|
26
|
+
get_provider_registry,
|
|
27
|
+
register_provider_factory,
|
|
28
|
+
register_provider_plugin,
|
|
29
|
+
)
|
|
11
30
|
|
|
31
|
+
# Re-export for backward compatibility
|
|
12
32
|
from .api_key import configure_api_key, get_api_key_config, is_api_key_configured
|
|
13
33
|
from .helpers import (
|
|
14
34
|
debug_api_key_context,
|
|
15
35
|
extract_token_from_header,
|
|
16
|
-
get_access_token,
|
|
17
36
|
get_api_key,
|
|
18
37
|
get_provider_token,
|
|
19
38
|
set_api_key,
|
|
20
39
|
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
""
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
40
|
+
|
|
41
|
+
# Public API
|
|
42
|
+
__all__ = [
|
|
43
|
+
# Main configuration functions
|
|
44
|
+
"configure_auth",
|
|
45
|
+
"configure_jwt_auth",
|
|
46
|
+
"configure_dev_auth",
|
|
47
|
+
"get_auth_config",
|
|
48
|
+
# Provider configurations
|
|
49
|
+
"AuthConfig",
|
|
50
|
+
"JWTAuthConfig",
|
|
51
|
+
"StaticTokenConfig",
|
|
52
|
+
"OAuthServerConfig",
|
|
53
|
+
"RemoteAuthConfig",
|
|
54
|
+
# Factory functions
|
|
55
|
+
"create_auth_provider",
|
|
56
|
+
"create_simple_jwt_provider",
|
|
57
|
+
"create_dev_token_provider",
|
|
58
|
+
# Provider registry and plugins
|
|
59
|
+
"BaseProviderPlugin",
|
|
60
|
+
"AuthProviderFactory",
|
|
61
|
+
"get_provider_registry",
|
|
62
|
+
"register_provider_factory",
|
|
63
|
+
"register_provider_plugin",
|
|
64
|
+
# API key functions (backward compatibility)
|
|
65
|
+
"configure_api_key",
|
|
66
|
+
"get_api_key_config",
|
|
67
|
+
"is_api_key_configured",
|
|
68
|
+
# Helper functions
|
|
69
|
+
"debug_api_key_context",
|
|
70
|
+
"extract_token_from_header",
|
|
71
|
+
"get_api_key",
|
|
72
|
+
"get_provider_token",
|
|
73
|
+
"set_api_key",
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
# Global storage for auth configuration
|
|
77
|
+
_auth_config: AuthConfig | None = None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def configure_auth(config: AuthConfig) -> None:
|
|
81
|
+
"""Configure authentication for the Golf server.
|
|
82
|
+
|
|
83
|
+
This function should be called in auth.py to set up authentication
|
|
84
|
+
using FastMCP's modern auth providers.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
config: Authentication configuration (JWT, OAuth, Static, or Remote)
|
|
88
|
+
The required_scopes should be specified in the config itself.
|
|
89
|
+
|
|
90
|
+
Examples:
|
|
91
|
+
# JWT authentication with Auth0
|
|
92
|
+
from golf.auth import configure_auth, JWTAuthConfig
|
|
93
|
+
|
|
94
|
+
configure_auth(
|
|
95
|
+
JWTAuthConfig(
|
|
96
|
+
jwks_uri="https://your-domain.auth0.com/.well-known/jwks.json",
|
|
97
|
+
issuer="https://your-domain.auth0.com/",
|
|
98
|
+
audience="https://your-api.example.com",
|
|
99
|
+
required_scopes=["read:data"],
|
|
100
|
+
)
|
|
63
101
|
)
|
|
64
102
|
|
|
103
|
+
# Development with static tokens
|
|
104
|
+
from golf.auth import configure_auth, StaticTokenConfig
|
|
105
|
+
|
|
106
|
+
configure_auth(
|
|
107
|
+
StaticTokenConfig(
|
|
108
|
+
tokens={
|
|
109
|
+
"dev-token-123": {
|
|
110
|
+
"client_id": "dev-client",
|
|
111
|
+
"scopes": ["read", "write"],
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
required_scopes=["read"],
|
|
115
|
+
)
|
|
116
|
+
)
|
|
65
117
|
|
|
66
|
-
#
|
|
67
|
-
|
|
118
|
+
# Full OAuth server
|
|
119
|
+
from golf.auth import configure_auth, OAuthServerConfig
|
|
120
|
+
|
|
121
|
+
configure_auth(
|
|
122
|
+
OAuthServerConfig(
|
|
123
|
+
base_url="https://your-server.example.com",
|
|
124
|
+
valid_scopes=["read", "write", "admin"],
|
|
125
|
+
default_scopes=["read"],
|
|
126
|
+
required_scopes=["read"],
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
"""
|
|
130
|
+
global _auth_config
|
|
131
|
+
_auth_config = config
|
|
68
132
|
|
|
69
133
|
|
|
70
|
-
def
|
|
71
|
-
|
|
72
|
-
|
|
134
|
+
def configure_jwt_auth(
|
|
135
|
+
*,
|
|
136
|
+
jwks_uri: str | None = None,
|
|
137
|
+
public_key: str | None = None,
|
|
138
|
+
issuer: str | None = None,
|
|
139
|
+
audience: str | list[str] | None = None,
|
|
73
140
|
required_scopes: list[str] | None = None,
|
|
74
|
-
|
|
141
|
+
**env_vars: str,
|
|
75
142
|
) -> None:
|
|
76
|
-
"""
|
|
77
|
-
|
|
78
|
-
This function should be called in pre_build.py to set up authentication.
|
|
143
|
+
"""Convenience function to configure JWT authentication.
|
|
79
144
|
|
|
80
145
|
Args:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
146
|
+
jwks_uri: JWKS URI for key fetching
|
|
147
|
+
public_key: Static public key (PEM format)
|
|
148
|
+
issuer: Expected issuer claim
|
|
149
|
+
audience: Expected audience claim(s)
|
|
150
|
+
required_scopes: Required scopes for all requests
|
|
151
|
+
**env_vars: Environment variable names (public_key_env_var,
|
|
152
|
+
jwks_uri_env_var, etc.)
|
|
86
153
|
"""
|
|
87
|
-
|
|
154
|
+
config = JWTAuthConfig(
|
|
155
|
+
jwks_uri=jwks_uri,
|
|
156
|
+
public_key=public_key,
|
|
157
|
+
issuer=issuer,
|
|
158
|
+
audience=audience,
|
|
159
|
+
required_scopes=required_scopes or [],
|
|
160
|
+
**env_vars,
|
|
161
|
+
)
|
|
162
|
+
configure_auth(config)
|
|
163
|
+
|
|
88
164
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
165
|
+
def configure_dev_auth(
|
|
166
|
+
tokens: dict[str, Any] | None = None,
|
|
167
|
+
required_scopes: list[str] | None = None,
|
|
168
|
+
) -> None:
|
|
169
|
+
"""Convenience function to configure development authentication.
|
|
94
170
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
required_scopes
|
|
98
|
-
|
|
171
|
+
Args:
|
|
172
|
+
tokens: Token dictionary or None for defaults
|
|
173
|
+
required_scopes: Required scopes for all requests
|
|
174
|
+
"""
|
|
175
|
+
if tokens is None:
|
|
176
|
+
tokens = {
|
|
177
|
+
"dev-token-123": {
|
|
178
|
+
"client_id": "dev-client",
|
|
179
|
+
"scopes": ["read", "write"],
|
|
180
|
+
},
|
|
181
|
+
"admin-token-456": {
|
|
182
|
+
"client_id": "admin-client",
|
|
183
|
+
"scopes": ["read", "write", "admin"],
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
config = StaticTokenConfig(
|
|
188
|
+
tokens=tokens,
|
|
189
|
+
required_scopes=required_scopes or [],
|
|
99
190
|
)
|
|
191
|
+
configure_auth(config)
|
|
100
192
|
|
|
101
193
|
|
|
102
|
-
def get_auth_config() ->
|
|
103
|
-
"""Get the current
|
|
194
|
+
def get_auth_config() -> AuthConfig | None:
|
|
195
|
+
"""Get the current auth configuration.
|
|
104
196
|
|
|
105
197
|
Returns:
|
|
106
|
-
|
|
198
|
+
AuthConfig if configured, None otherwise
|
|
107
199
|
"""
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
200
|
+
return _auth_config
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def is_auth_configured() -> bool:
|
|
204
|
+
"""Check if authentication is configured.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
True if authentication is configured, False otherwise
|
|
208
|
+
"""
|
|
209
|
+
return _auth_config is not None
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
# Breaking change in Golf 0.2.x: Legacy auth system removed
|
|
213
|
+
# Users must migrate to modern auth configurations
|
|
111
214
|
|
|
112
215
|
|
|
113
|
-
def
|
|
114
|
-
"""Create an
|
|
216
|
+
def create_auth_provider_from_config() -> object | None:
|
|
217
|
+
"""Create an auth provider from the current configuration.
|
|
115
218
|
|
|
116
219
|
Returns:
|
|
117
|
-
|
|
220
|
+
FastMCP AuthProvider instance or None if not configured
|
|
118
221
|
"""
|
|
119
|
-
|
|
222
|
+
config = get_auth_config()
|
|
223
|
+
if not config:
|
|
120
224
|
return None
|
|
121
225
|
|
|
122
|
-
return
|
|
226
|
+
return create_auth_provider(config)
|
golf/auth/api_key.py
CHANGED
|
@@ -11,28 +11,22 @@ from pydantic import BaseModel, Field
|
|
|
11
11
|
class ApiKeyConfig(BaseModel):
|
|
12
12
|
"""Configuration for API key authentication."""
|
|
13
13
|
|
|
14
|
-
header_name: str = Field(
|
|
15
|
-
"X-API-Key", description="Name of the header containing the API key"
|
|
16
|
-
)
|
|
14
|
+
header_name: str = Field("X-API-Key", description="Name of the header containing the API key")
|
|
17
15
|
header_prefix: str = Field(
|
|
18
16
|
"",
|
|
19
17
|
description="Optional prefix to strip from the header value (e.g., 'Bearer ')",
|
|
20
18
|
)
|
|
21
|
-
required: bool = Field(
|
|
22
|
-
True, description="Whether API key is required for all requests"
|
|
23
|
-
)
|
|
19
|
+
required: bool = Field(True, description="Whether API key is required for all requests")
|
|
24
20
|
|
|
25
21
|
|
|
26
22
|
# Global configuration storage
|
|
27
23
|
_api_key_config: ApiKeyConfig | None = None
|
|
28
24
|
|
|
29
25
|
|
|
30
|
-
def configure_api_key(
|
|
31
|
-
header_name: str = "X-API-Key", header_prefix: str = "", required: bool = True
|
|
32
|
-
) -> None:
|
|
26
|
+
def configure_api_key(header_name: str = "X-API-Key", header_prefix: str = "", required: bool = True) -> None:
|
|
33
27
|
"""Configure API key extraction from request headers.
|
|
34
28
|
|
|
35
|
-
This function should be called in
|
|
29
|
+
This function should be called in auth.py to set up API key handling.
|
|
36
30
|
|
|
37
31
|
Args:
|
|
38
32
|
header_name: Name of the header containing the API key (default: "X-API-Key")
|
|
@@ -40,7 +34,7 @@ def configure_api_key(
|
|
|
40
34
|
required: Whether API key is required for all requests (default: True)
|
|
41
35
|
|
|
42
36
|
Example:
|
|
43
|
-
# In
|
|
37
|
+
# In auth.py
|
|
44
38
|
from golf.auth.api_key import configure_api_key
|
|
45
39
|
|
|
46
40
|
# Require API key for all requests
|
|
@@ -58,9 +52,7 @@ def configure_api_key(
|
|
|
58
52
|
)
|
|
59
53
|
"""
|
|
60
54
|
global _api_key_config
|
|
61
|
-
_api_key_config = ApiKeyConfig(
|
|
62
|
-
header_name=header_name, header_prefix=header_prefix, required=required
|
|
63
|
-
)
|
|
55
|
+
_api_key_config = ApiKeyConfig(header_name=header_name, header_prefix=header_prefix, required=required)
|
|
64
56
|
|
|
65
57
|
|
|
66
58
|
def get_api_key_config() -> ApiKeyConfig | None:
|