Class: Zitadel::Client::TransportOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/zitadel/client/transport_options.rb

Overview

Immutable transport options for configuring HTTP connections.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_headers: {}, ca_cert_path: nil, insecure: false, proxy_url: nil) ⇒ TransportOptions

Creates a new TransportOptions instance.

Parameters:

  • default_headers (Hash{String => String}) (defaults to: {})

    Default HTTP headers sent to the origin server with every request.

  • ca_cert_path (String, nil) (defaults to: nil)

    Path to a custom CA certificate file for TLS verification.

  • insecure (Boolean) (defaults to: false)

    Whether to disable TLS certificate verification.

  • proxy_url (String, nil) (defaults to: nil)

    Proxy URL for HTTP connections.



28
29
30
31
32
33
34
# File 'lib/zitadel/client/transport_options.rb', line 28

def initialize(default_headers: {}, ca_cert_path: nil, insecure: false, proxy_url: nil)
  @default_headers = default_headers.dup.freeze
  @ca_cert_path = ca_cert_path&.dup&.freeze
  @insecure = insecure
  @proxy_url = proxy_url&.dup&.freeze
  freeze
end

Instance Attribute Details

#ca_cert_pathString? (readonly)

Returns Path to a custom CA certificate file for TLS verification.

Returns:

  • (String, nil)

    Path to a custom CA certificate file for TLS verification.



13
14
15
# File 'lib/zitadel/client/transport_options.rb', line 13

def ca_cert_path
  @ca_cert_path
end

#default_headersHash{String => String} (readonly)

Returns Default HTTP headers sent to the origin server with every request.

Returns:

  • (Hash{String => String})

    Default HTTP headers sent to the origin server with every request.



10
11
12
# File 'lib/zitadel/client/transport_options.rb', line 10

def default_headers
  @default_headers
end

#insecureBoolean (readonly)

Returns Whether to disable TLS certificate verification.

Returns:

  • (Boolean)

    Whether to disable TLS certificate verification.



16
17
18
# File 'lib/zitadel/client/transport_options.rb', line 16

def insecure
  @insecure
end

#proxy_urlString? (readonly)

Returns Proxy URL for HTTP connections.

Returns:

  • (String, nil)

    Proxy URL for HTTP connections.



19
20
21
# File 'lib/zitadel/client/transport_options.rb', line 19

def proxy_url
  @proxy_url
end

Class Method Details

.defaultsTransportOptions

Returns a TransportOptions instance with all default values.

Returns:



39
40
41
# File 'lib/zitadel/client/transport_options.rb', line 39

def self.defaults
  new
end

Instance Method Details

#to_connection_optsHash

Builds Faraday connection options from these transport options.

rubocop:disable Metrics/AbcSize, Metrics/MethodLength

Returns:

  • (Hash)

    connection options for OAuth2::Client



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/zitadel/client/transport_options.rb', line 47

def to_connection_opts
  opts = {}
  if insecure
    opts[:ssl] = { verify: false }
  elsif ca_cert_path
    store = OpenSSL::X509::Store.new
    store.set_default_paths
    store.add_file(ca_cert_path)
    opts[:ssl] = { cert_store: store, verify: true }
  end
  opts[:proxy] = proxy_url if proxy_url
  opts[:headers] = default_headers.dup if default_headers.any?
  opts
end