Class: CldProvisioning::SDKHooks::CloudinaryAccountHook

Inherits:
AbstractSDKHook show all
Extended by:
T::Sig
Defined in:
lib/cld_provisioning/sdk_hooks/cloudinary_account_hook.rb

Overview

Populates account_id from CLOUDINARY_ACCOUNT_URL on init, and attaches Basic auth (provisioning_api_key:provisioning_api_secret) to every request.

Credential resolution order:

1. Explicit security passed to the SDK constructor
2. CLOUDINARY_ACCOUNT_URL / individual CLOUDINARY_ACCOUNT_* env vars

Instance Method Summary collapse

Methods included from AbstractAfterErrorHook

#after_error

Methods included from AbstractAfterSuccessHook

#after_success

Constructor Details

#initialize(config:) ⇒ CloudinaryAccountHook

Returns a new instance of CloudinaryAccountHook.



20
21
22
# File 'lib/cld_provisioning/sdk_hooks/cloudinary_account_hook.rb', line 20

def initialize(config:)
  @config = T.let(config, AccountConfig)
end

Instance Method Details

#before_request(hook_ctx:, request:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cld_provisioning/sdk_hooks/cloudinary_account_hook.rb', line 38

def before_request(hook_ctx:, request:)
  key, secret = resolve_credentials(hook_ctx)

  if key.empty? || secret.empty?
    raise "Provisioning API key and secret are required"
  end

  encoded = Base64.strict_encode64("#{key}:#{secret}")
  request.headers["Authorization"] = "Basic #{encoded}"

  request
end

#sdk_init(config:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cld_provisioning/sdk_hooks/cloudinary_account_hook.rb', line 25

def sdk_init(config:)
   = config.globals.dig(:parameters, :pathParam, :account_id)
  if (.nil? || (.is_a?(String) && .empty?)) && !@config..empty?
    config.globals[:parameters] ||= {}
    params = T.must(config.globals[:parameters])
    params[:pathParam] ||= {}
    T.must(params[:pathParam])[:account_id] = @config.
  end

  config
end