Class: Ovh::Client::Signature
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Ovh::Client::Signature
- Defined in:
- lib/ovh-client/client/signature.rb
Overview
Faraday middleware that signs each request with OVH's scheme. It runs after ovh-api's built-in request middleware (so it sees the serialized body and the final URL) and just before the adapter, so the signed URL matches what is sent byte-for-byte.
Registered via Configuration#use, which passes options as a single positional Hash (Ruby 3 does not convert a positional Hash to keywords), so #initialize takes an options Hash rather than keyword parameters.
Instance Method Summary collapse
-
#initialize(app, options) ⇒ Signature
constructor
A new instance of Signature.
- #on_request(env) ⇒ Object
Constructor Details
#initialize(app, options) ⇒ Signature
Returns a new instance of Signature.
16 17 18 19 20 21 22 |
# File 'lib/ovh-client/client/signature.rb', line 16 def initialize(app, ) super(app) @application_key = .fetch(:application_key) @application_secret = .fetch(:application_secret) @consumer_key = .fetch(:consumer_key) @clock = .fetch(:clock) end |
Instance Method Details
#on_request(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ovh-client/client/signature.rb', line 24 def on_request(env) case env.url.path when %r{\A/[^/]+/auth/time/?\z} # Public endpoint used to measure clock skew: never signed, and it must # not trigger lazy sync (that would recurse through this middleware). nil when %r{\A/[^/]+/auth/credential/?\z} # Consumer-key bootstrap is POST /auth/credential: unsigned, application # header only (there may be no consumer key yet). Other verbs on this path # (e.g. GET to list credential IDs) are ordinary signed calls. env.method == :post ? (env.request_headers['X-Ovh-Application'] = @application_key) : sign(env) else sign(env) end end |