Class: Fluence::Gateway::Client
- Inherits:
-
Object
- Object
- Fluence::Gateway::Client
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/fluence/gateway/http_client.rb
Overview
Singleton HTTP client for the Fluence API gateway.
Handles OAuth2 client_credentials authentication transparently: the
service token is fetched on the first request and refreshed on demand.
End-user Bearer tokens can be forwarded per call or for an entire
block, and the target service can be encoded into the URL via the
service: kwarg or the #with_service block helper.
All HTTP verbs (get, post, put, patch, delete) are defined
on both the singleton instance and the class (class-level delegation),
so callers never need to reference .instance explicitly.
Thread-safety: the OAuth2::Client cache and token refresh are guarded
by a reentrant Monitor, which allows access_token_for (already
inside the lock) to call oauth_client_for (which also takes the
lock) without deadlocking. Per-block scopes (#with_user_token,
#with_service, #with_tenant) are stored in Thread.current and
restored when the block exits, including on exception.
Class Method Summary collapse
-
.delete(path, user_token: nil, service: nil, tenant: nil, raw: false, **opts) ⇒ Hash, ...
Performs a DELETE request on the gateway.
-
.get(path, user_token: nil, service: nil, tenant: nil, raw: false, **opts) ⇒ Hash, ...
Performs a GET request on the gateway.
-
.patch(path, user_token: nil, service: nil, tenant: nil, body: nil, raw: false, **opts) ⇒ Hash, ...
Performs a PATCH request on the gateway.
-
.post(path, user_token: nil, service: nil, tenant: nil, body: nil, raw: false, **opts) ⇒ Hash, ...
Performs a POST request on the gateway.
-
.put(path, user_token: nil, service: nil, tenant: nil, body: nil, raw: false, **opts) ⇒ Hash, ...
Performs a PUT request on the gateway.
-
.with_service(service) { ... } ⇒ Object
Scopes a block of gateway calls to the given backend service.
-
.with_tenant(tenant) { ... } ⇒ Object
Scopes a block of gateway calls to the given tenant.
-
.with_user_token(token) { ... } ⇒ Object
Scopes a block of gateway calls to forward
tokenas the end-user Bearer instead of the cached service token.
Class Method Details
.delete(path, user_token: nil, service: nil, tenant: nil, raw: false, **opts) ⇒ Hash, ...
Performs a DELETE request on the gateway.
.get(path, user_token: nil, service: nil, tenant: nil, raw: false, **opts) ⇒ Hash, ...
Performs a GET request on the gateway.
.patch(path, user_token: nil, service: nil, tenant: nil, body: nil, raw: false, **opts) ⇒ Hash, ...
Performs a PATCH request on the gateway.
.post(path, user_token: nil, service: nil, tenant: nil, body: nil, raw: false, **opts) ⇒ Hash, ...
Performs a POST request on the gateway.
.put(path, user_token: nil, service: nil, tenant: nil, body: nil, raw: false, **opts) ⇒ Hash, ...
Performs a PUT request on the gateway.
.with_service(service) { ... } ⇒ Object
Scopes a block of gateway calls to the given backend service.
Paths issued inside the block are automatically prefixed with
/backend/<service>/. When service is a Symbol, underscores are
converted to dashes (:base_valeur → base-valeur); when it is a
String, it is used as-is. The scope is stored in Thread.current
and restored when the block exits, including on exception. A
service: kwarg on a call site always wins over the value set here.
.with_tenant(tenant) { ... } ⇒ Object
Scopes a block of gateway calls to the given tenant.
Calls issued inside the block are routed through the tenant's
gateway/credentials (resolved via
Fluence::Gateway::Configuration::Settings#tenant_config). Accepts user-declared
tenants from config.tenants and the gem's built-in tenants
(e.g. :mosaic). The name is validated eagerly — an unknown
tenant raises UnknownTenantError before the block runs. A
tenant: kwarg on a call site always wins over the value set
here; tenant: nil explicitly forces the global default tenant.
The scope is stored in Thread.current and restored when the
block exits, including on exception.
.with_user_token(token) { ... } ⇒ Object
Scopes a block of gateway calls to forward token as the end-user
Bearer instead of the cached service token.
The token is stored in Thread.current so it survives nested calls
on the same thread but does not leak to other threads. Any explicit
user_token: kwarg on a call site always wins over the value set
here. The previous value (if any) is restored when the block exits,
including on exception.