Class: Pvectl::Config::Models::User
- Inherits:
-
Object
- Object
- Pvectl::Config::Models::User
- Defined in:
- lib/pvectl/config/models/user.rb
Overview
Represents user credentials for Proxmox API authentication.
User is an immutable value object supporting two authentication methods:
-
API Token authentication (token_id + token_secret)
-
Username/Password authentication (username + password)
Constant Summary collapse
- SECRET_MASK =
Mask used to hide secrets in output
"********"
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Unique name identifying this user.
-
#password ⇒ String?
readonly
Password for password auth.
-
#token_id ⇒ String?
readonly
API token ID (e.g., “root@pam!tokenid”).
-
#token_secret ⇒ String?
readonly
API token secret (UUID format).
-
#username ⇒ String?
readonly
Username for password auth (e.g., “root@pam”).
Class Method Summary collapse
-
.from_hash(hash) ⇒ User
Creates a User from a kubeconfig-style hash structure.
Instance Method Summary collapse
-
#initialize(name:, token_id: nil, token_secret: nil, username: nil, password: nil) ⇒ User
constructor
Creates a new User instance.
-
#password_auth? ⇒ Boolean
Checks if this user is configured for password authentication.
-
#to_hash(mask_secrets: false) ⇒ Hash
Converts the user to a kubeconfig-style hash structure.
-
#token_auth? ⇒ Boolean
Checks if this user is configured for API token authentication.
-
#valid? ⇒ Boolean
Checks if this user has valid credentials for authentication.
Constructor Details
#initialize(name:, token_id: nil, token_secret: nil, username: nil, password: nil) ⇒ User
Creates a new User instance.
54 55 56 57 58 59 60 |
# File 'lib/pvectl/config/models/user.rb', line 54 def initialize(name:, token_id: nil, token_secret: nil, username: nil, password: nil) @name = name @token_id = token_id @token_secret = token_secret @username = username @password = password end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns unique name identifying this user.
33 34 35 |
# File 'lib/pvectl/config/models/user.rb', line 33 def name @name end |
#password ⇒ String? (readonly)
Returns password for password auth.
45 46 47 |
# File 'lib/pvectl/config/models/user.rb', line 45 def password @password end |
#token_id ⇒ String? (readonly)
Returns API token ID (e.g., “root@pam!tokenid”).
36 37 38 |
# File 'lib/pvectl/config/models/user.rb', line 36 def token_id @token_id end |
#token_secret ⇒ String? (readonly)
Returns API token secret (UUID format).
39 40 41 |
# File 'lib/pvectl/config/models/user.rb', line 39 def token_secret @token_secret end |
#username ⇒ String? (readonly)
Returns username for password auth (e.g., “root@pam”).
42 43 44 |
# File 'lib/pvectl/config/models/user.rb', line 42 def username @username end |
Class Method Details
.from_hash(hash) ⇒ User
Creates a User from a kubeconfig-style hash structure.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/pvectl/config/models/user.rb', line 96 def self.from_hash(hash) user_data = hash["user"] || {} new( name: hash["name"], token_id: user_data["token-id"], token_secret: user_data["token-secret"], username: user_data["username"], password: user_data["password"] ) end |
Instance Method Details
#password_auth? ⇒ Boolean
Checks if this user is configured for password authentication.
72 73 74 |
# File 'lib/pvectl/config/models/user.rb', line 72 def password_auth? !username.nil? && !username.empty? && !password.nil? && !password.empty? end |
#to_hash(mask_secrets: false) ⇒ Hash
Converts the user to a kubeconfig-style hash structure.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/pvectl/config/models/user.rb', line 112 def to_hash(mask_secrets: false) user_data = {} if token_auth? user_data["token-id"] = token_id user_data["token-secret"] = mask_secrets ? SECRET_MASK : token_secret end if password_auth? user_data["username"] = username user_data["password"] = mask_secrets ? SECRET_MASK : password end { "name" => name, "user" => user_data } end |
#token_auth? ⇒ Boolean
Checks if this user is configured for API token authentication.
65 66 67 |
# File 'lib/pvectl/config/models/user.rb', line 65 def token_auth? !token_id.nil? && !token_id.empty? && !token_secret.nil? && !token_secret.empty? end |
#valid? ⇒ Boolean
Checks if this user has valid credentials for authentication.
79 80 81 |
# File 'lib/pvectl/config/models/user.rb', line 79 def valid? token_auth? || password_auth? end |