Conversation
1c3d49e to
bc90ad9
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
… coverage Synchronous client backed by requests.Session, covering the full OpenFaaS REST API: system info, namespaces, functions (deploy/update/scale/delete), secrets, and streaming logs. - requests.Session transport with FAAS_DEBUG hook-based logging - requests.auth.AuthBase auth classes: BasicAuth, TokenAuth, ClientCredentialsAuth - OpenFaaS IAM: ServiceAccountTokenSource, ClientCredentialsTokenSource, exchange_id_token, MemoryTokenCache, get_function_token() - Pydantic v2 models for all request and response types - Tests use requests-mock Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
- Add _parse_function_name_namespace helper to extract name/namespace from /function/<name>.<ns> and /async-function/<name>.<ns> paths - Add _FunctionAuth(requests.auth.AuthBase) compound auth that applies gateway auth then overrides Authorization with a per-function Bearer token - Add Client.invoke_function() supporting bytes/str payload, custom method/headers/query params, async invocation, callback URL, and use_function_auth for IAM-scoped per-function token exchange - Add echo handler and 18 new tests covering all invoke_function params - Update README with invoke_function API reference section Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
…ng to function invocations - Remove _FunctionAuth compound auth class - Add _BearerAuth for static Bearer token auth on function invocations - invoke_function with use_function_auth=True uses _BearerAuth(fn_token) - invoke_function with use_function_auth=False passes auth=None - Remove unused _parse_function_name_namespace helper and its tests Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
…dules
- Rename _parse_token_response -> parse_token_response to fix reportPrivateUsage
across auth.py and exchange.py
- Add explicit cast in BasicAuth.__call__ to silence Unknown return from requests stubs
- Remove unused _on_request hook from _transport.py (requests has no request hook;
request-side debug logging to be revisited)
- Remove or{} fallback on r.headers in _transport.py (headers is never None)
- Fix bare dict return annotations on to_api_dict() methods in models.py to dict[str, Any]
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
…d ClientCredentialsTokenSource - exchange_id_token: add timeout kwarg (default 30s) passed to session.post() - ClientCredentialsTokenSource: add timeout and http_client kwargs matching the exchange_id_token pattern; _fetch() uses _owns_session to avoid closing caller-provided sessions Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Remove the unnecessary delegation to HTTPBasicAuth via composition. Subclassing eliminates __init__, __call__, and the cast() workaround, keeping only the __repr__ override to avoid leaking the password. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Reuses the client's existing connection pool and inherits any proxy, SSL, or other session-level configuration for gateway token exchange. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Implements the builder package without secret sealing: - BuildConfig / BuildResult models with wire-format serialisation - make_tar: packs a build context dir + BuildConfig into a tar archive - create_build_context: assembles an on-disk context from a template and handler directory, skipping build/ and template/ handler subdirs - FunctionBuilder.build: blocking POST, returns a single BuildResult - FunctionBuilder.build_stream: streaming POST, yields BuildResult per NDJSON line - Optional HMAC-SHA256 request signing via hmac_secret (X-Build-Signature header) - 33 tests covering models, tar helpers, context assembly, and the HTTP client Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
What were your thoughts about this? |
…thod Async and sync invocation have different semantics — async queues work and always uses POST, sync invokes directly and supports any HTTP method. Conflating them behind an async_invoke flag made the API harder to use and required awkward validation. Two dedicated methods make the intent clear at the call site. - invoke_function: synchonous invocation, method is required and explicit - invoke_function_async: queued invocation via /async-function/, always POSTs internally, accepts an optional callback_url Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
This comment has been minimized.
This comment has been minimized.
The gateway requires the openfaas label to be present in the request body to identify the namespace as OpenFaaS-managed. Without it the gateway returned 401. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
AI Pull Request OverviewSummaryThis pull request introduces the initial OpenFaaS Python SDK, providing a synchronous client backed by Approval rating (1-10)9 Summary per fileSummary per file
Overall AssessmentThe OpenFaaS Python SDK implementation is comprehensive and well-engineered, providing a robust interface to the OpenFaaS API with strong typing, comprehensive error handling, and support for multiple authentication mechanisms. The use of Pydantic v2 ensures type safety and validation, while the thread-safe token caching and authentication implementations demonstrate attention to concurrency concerns. The test suite appears extensive, covering models, client operations, and authentication flows. However, there are several areas that warrant attention: error handling in log parsing could be more robust, potential race conditions in token caching under high concurrency, and some inconsistencies in model field types that may cause confusion. The implementation correctly handles the OpenFaaS API specification but could benefit from additional validation in edge cases. Detailed ReviewDetailed Reviewopenfaas/models.py
openfaas/client.py
openfaas/auth.py
openfaas/token_cache.py
openfaas/exchange.py
openfaas/exceptions.py
Tests
pyproject.toml
Security Considerations
Performance
Consistency
AI agent details. |
Description
Implements the initial Python SDK for OpenFaaS.
Provides a synchronous
Clientbacked byrequests, covering the full OpenFaaS REST API:Pydantic v2 models are used for all request and response types.
FAAS_DEBUG=1enables request/response logging with auth headers redacted.Authentication
All standard OpenFaaS auth strategies are included:
BasicAuth— HTTP BasicTokenAuth— OpenFaaS IAM token exchange (RFC 8693); caches and auto-refreshes the gateway JWT with a 10-second expiry buffer matching the Go SDKServiceAccountTokenSource— Reads a Kubernetes projected service account token from disk, re-read on every call so token rotation is transparentClientCredentialsTokenSource— Fetches tokens from an external IdP via OAuth 2.0client_credentials, with internal cachingClientCredentialsAuth—requests.auth.AuthBasewrapper around anyTokenSourceMemoryTokenCache— Thread-safe in-memory cache for per-function scoped tokens (used byget_function_token())TokenAuthalso implements theTokenSourceprotocol, enabling automatic wiring asfunction_token_sourcefor per-function scoped token exchange.Tests
100 tests covering models, all client endpoints, all auth strategies, token exchange, the memory token cache, and function invocation.
Motivation and Context