Class: Pvectl::Config::Models::ResolvedConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/config/models/resolved_config.rb

Overview

Represents the final resolved configuration ready for use.

ResolvedConfig is an immutable value object containing all settings needed to connect to a Proxmox server. It is created by merging configuration from file, environment variables, and CLI options.

Examples:

Creating a resolved config with token auth

config = ResolvedConfig.new(
  context_name: "production",
  server: "https://pve.example.com:8006",
  auth_type: :token,
  token_id: "root@pam!automation",
  token_secret: "secret-uuid"
)

Getting connection options for proxmox-api gem

options = config.to_connection_options
# => { server: "https://...", token: "root@pam!automation", ... }

Constant Summary collapse

DEFAULT_TIMEOUT =

Default values for retry/timeout settings

30
DEFAULT_RETRY_COUNT =
3
DEFAULT_RETRY_DELAY =
1
DEFAULT_MAX_RETRY_DELAY =
30
DEFAULT_RETRY_WRITES =
false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context_name:, server:, auth_type:, verify_ssl: true, certificate_authority: nil, token_id: nil, token_secret: nil, username: nil, password: nil, default_node: nil, timeout: nil, retry_count: nil, retry_delay: nil, max_retry_delay: nil, retry_writes: nil) ⇒ ResolvedConfig

Creates a new ResolvedConfig instance.

Parameters:

  • context_name (String)

    name of the active context

  • server (String)

    Proxmox server URL

  • auth_type (Symbol)

    :token or :password

  • verify_ssl (Boolean) (defaults to: true)

    whether to verify SSL (default: true)

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

    path to CA certificate

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

    API token ID (required for :token auth)

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

    API token secret (required for :token auth)

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

    username (required for :password auth)

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

    password (required for :password auth)

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

    default node for operations

  • timeout (Integer, nil) (defaults to: nil)

    request timeout (default: 30)

  • retry_count (Integer, nil) (defaults to: nil)

    max retries (default: 3)

  • retry_delay (Integer, nil) (defaults to: nil)

    base delay (default: 1)

  • max_retry_delay (Integer, nil) (defaults to: nil)

    max delay cap (default: 30)

  • retry_writes (Boolean, nil) (defaults to: nil)

    retry writes (default: false)



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/pvectl/config/models/resolved_config.rb', line 95

def initialize(context_name:, server:, auth_type:, verify_ssl: true,
               certificate_authority: nil, token_id: nil, token_secret: nil,
               username: nil, password: nil, default_node: nil,
               timeout: nil, retry_count: nil, retry_delay: nil,
               max_retry_delay: nil, retry_writes: nil)
  @context_name = context_name
  @server = server
  @verify_ssl = verify_ssl
  @certificate_authority = certificate_authority
  @auth_type = auth_type
  @token_id = token_id
  @token_secret = token_secret
  @username = username
  @password = password
  @default_node = default_node

  # Apply defaults for retry/timeout settings
  @timeout = timeout || DEFAULT_TIMEOUT
  @retry_count = retry_count || DEFAULT_RETRY_COUNT
  @retry_delay = retry_delay || DEFAULT_RETRY_DELAY
  @max_retry_delay = max_retry_delay || DEFAULT_MAX_RETRY_DELAY
  @retry_writes = retry_writes.nil? ? DEFAULT_RETRY_WRITES : retry_writes
end

Instance Attribute Details

#auth_typeSymbol (readonly)

Returns authentication type (:token or :password).

Returns:

  • (Symbol)

    authentication type (:token or :password)



46
47
48
# File 'lib/pvectl/config/models/resolved_config.rb', line 46

def auth_type
  @auth_type
end

#certificate_authorityString? (readonly)

Returns path to CA certificate file.

Returns:

  • (String, nil)

    path to CA certificate file



43
44
45
# File 'lib/pvectl/config/models/resolved_config.rb', line 43

def certificate_authority
  @certificate_authority
end

#context_nameString (readonly)

Returns name of the active context.

Returns:

  • (String)

    name of the active context



34
35
36
# File 'lib/pvectl/config/models/resolved_config.rb', line 34

def context_name
  @context_name
end

#default_nodeString? (readonly)

Returns default node for operations.

Returns:

  • (String, nil)

    default node for operations



61
62
63
# File 'lib/pvectl/config/models/resolved_config.rb', line 61

def default_node
  @default_node
end

#max_retry_delayInteger (readonly)

Returns maximum delay cap for exponential backoff.

Returns:

  • (Integer)

    maximum delay cap for exponential backoff



73
74
75
# File 'lib/pvectl/config/models/resolved_config.rb', line 73

def max_retry_delay
  @max_retry_delay
end

#passwordString? (readonly)

Returns password for password auth.

Returns:

  • (String, nil)

    password for password auth



58
59
60
# File 'lib/pvectl/config/models/resolved_config.rb', line 58

def password
  @password
end

#retry_countInteger (readonly)

Returns maximum retry attempts.

Returns:

  • (Integer)

    maximum retry attempts



67
68
69
# File 'lib/pvectl/config/models/resolved_config.rb', line 67

def retry_count
  @retry_count
end

#retry_delayInteger (readonly)

Returns base delay between retries in seconds.

Returns:

  • (Integer)

    base delay between retries in seconds



70
71
72
# File 'lib/pvectl/config/models/resolved_config.rb', line 70

def retry_delay
  @retry_delay
end

#retry_writesBoolean (readonly)

Returns whether to retry write operations.

Returns:

  • (Boolean)

    whether to retry write operations



76
77
78
# File 'lib/pvectl/config/models/resolved_config.rb', line 76

def retry_writes
  @retry_writes
end

#serverString (readonly)

Returns Proxmox server URL.

Returns:

  • (String)

    Proxmox server URL



37
38
39
# File 'lib/pvectl/config/models/resolved_config.rb', line 37

def server
  @server
end

#timeoutInteger (readonly)

Returns request timeout in seconds.

Returns:

  • (Integer)

    request timeout in seconds



64
65
66
# File 'lib/pvectl/config/models/resolved_config.rb', line 64

def timeout
  @timeout
end

#token_idString? (readonly)

Returns API token ID.

Returns:

  • (String, nil)

    API token ID



49
50
51
# File 'lib/pvectl/config/models/resolved_config.rb', line 49

def token_id
  @token_id
end

#token_secretString? (readonly)

Returns API token secret.

Returns:

  • (String, nil)

    API token secret



52
53
54
# File 'lib/pvectl/config/models/resolved_config.rb', line 52

def token_secret
  @token_secret
end

#usernameString? (readonly)

Returns username for password auth.

Returns:

  • (String, nil)

    username for password auth



55
56
57
# File 'lib/pvectl/config/models/resolved_config.rb', line 55

def username
  @username
end

#verify_sslBoolean (readonly)

Returns whether to verify SSL certificates.

Returns:

  • (Boolean)

    whether to verify SSL certificates



40
41
42
# File 'lib/pvectl/config/models/resolved_config.rb', line 40

def verify_ssl
  @verify_ssl
end

Instance Method Details

#password_auth?Boolean

Checks if this config uses password authentication.

Returns:

  • (Boolean)

    true if auth_type is :password



129
130
131
# File 'lib/pvectl/config/models/resolved_config.rb', line 129

def password_auth?
  auth_type == :password
end

#to_connection_optionsHash

Converts the config to options hash for proxmox-api gem.

Examples:

Token auth options

{
  server: "https://pve.example.com:8006",
  token: "root@pam!automation",
  secret: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  verify_ssl: false
}

Password auth options

{
  server: "https://pve.example.com:8006",
  username: "root@pam",
  password: "secret",
  verify_ssl: true
}

Returns:

  • (Hash)

    options for ProxmoxAPI.new



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/pvectl/config/models/resolved_config.rb', line 152

def to_connection_options
  options = {
    server: server,
    verify_ssl: verify_ssl
  }

  if token_auth?
    options[:token] = token_id
    options[:secret] = token_secret
  else
    options[:username] = username
    options[:password] = password
  end

  options
end

#token_auth?Boolean

Checks if this config uses API token authentication.

Returns:

  • (Boolean)

    true if auth_type is :token



122
123
124
# File 'lib/pvectl/config/models/resolved_config.rb', line 122

def token_auth?
  auth_type == :token
end