Class: Pvectl::Presenters::Subscription
- Inherits:
-
Base
- Object
- Base
- Pvectl::Presenters::Subscription
show all
- Defined in:
- lib/pvectl/presenters/subscription.rb,
sig/pvectl/presenters/subscription.rbs
Overview
Presenter for Proxmox subscription records.
Default table view masks the license key to avoid leaking it in shared
screenshots; the full key is only shown via -o wide, -o json, or
-o yaml so revealing it is an explicit user choice.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#format_bytes, #format_firewall, #format_firewall_rules, #format_task_history, #resource, #tags_array, #tags_display, #template_display, #uptime_human, #wide_columns
Instance Attribute Details
186
187
188
|
# File 'lib/pvectl/presenters/subscription.rb', line 186
def subscription
@subscription
end
|
Instance Method Details
#checktime_display ⇒ String
151
152
153
154
155
|
# File 'lib/pvectl/presenters/subscription.rb', line 151
def checktime_display
return "-" if subscription.checktime.nil? || subscription.checktime.to_i.zero?
Time.at(subscription.checktime.to_i).utc.strftime("%Y-%m-%d %H:%M:%S UTC")
end
|
#columns ⇒ Array<String>
15
16
17
|
# File 'lib/pvectl/presenters/subscription.rb', line 15
def columns
%w[NODE LEVEL STATUS NEXTDUEDATE KEY]
end
|
#extra_columns ⇒ Array<String>
20
21
22
|
# File 'lib/pvectl/presenters/subscription.rb', line 20
def extra_columns
%w[PRODUCT REGDATE SERVERID]
end
|
39
40
41
42
43
44
45
46
|
# File 'lib/pvectl/presenters/subscription.rb', line 39
def (model, **_context)
@subscription = model
[
product_display,
regdate_display,
serverid_display
]
end
|
#full_key_display ⇒ String
178
179
180
181
|
# File 'lib/pvectl/presenters/subscription.rb', line 178
def full_key_display
key = subscription.key
key.nil? || key.empty? ? "-" : key
end
|
#level_display ⇒ String
116
117
118
|
# File 'lib/pvectl/presenters/subscription.rb', line 116
def level_display
subscription.level || "-"
end
|
#masked_key ⇒ String
Returns the license key with the middle masked.
Proxmox keys look like pveXp-1234567890 (16 chars). We preserve the
6-char prefix (pveXp-) and the last 4 chars, masking the rest.
Returns "-" when no key is set (community node).
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/pvectl/presenters/subscription.rb', line 164
def masked_key
key = subscription.key
return "-" if key.nil? || key.empty?
if key.length <= 6
key
elsif key.length <= 10
"#{key[0, 4]}***#{key[-2..]}"
else
"#{key[0, 6]}****#{key[-4..]}"
end
end
|
#message_display ⇒ String
146
147
148
|
# File 'lib/pvectl/presenters/subscription.rb', line 146
def message_display
subscription.message || "-"
end
|
#nextduedate_display ⇒ String
136
137
138
|
# File 'lib/pvectl/presenters/subscription.rb', line 136
def nextduedate_display
subscription.nextduedate || "-"
end
|
#node_display ⇒ String
106
107
108
|
# File 'lib/pvectl/presenters/subscription.rb', line 106
def node_display
subscription.node || "-"
end
|
#product_display ⇒ String
121
122
123
|
# File 'lib/pvectl/presenters/subscription.rb', line 121
def product_display
subscription.productname || "-"
end
|
#regdate_display ⇒ String
126
127
128
|
# File 'lib/pvectl/presenters/subscription.rb', line 126
def regdate_display
subscription.regdate || "-"
end
|
#serverid_display ⇒ String
131
132
133
|
# File 'lib/pvectl/presenters/subscription.rb', line 131
def serverid_display
subscription.serverid || "-"
end
|
#sockets_display ⇒ String
141
142
143
|
# File 'lib/pvectl/presenters/subscription.rb', line 141
def sockets_display
subscription.sockets ? subscription.sockets.to_s : "-"
end
|
#status_display ⇒ String
111
112
113
|
# File 'lib/pvectl/presenters/subscription.rb', line 111
def status_display
subscription.status || "-"
end
|
#to_description(model) ⇒ Hash{String => Object}
Description-style hash for pvectl describe subscription future use.
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/pvectl/presenters/subscription.rb', line 88
def to_description(model)
@subscription = model
{
"Node" => node_display,
"Status" => status_display,
"Level" => level_display,
"Product" => product_display,
"Key" => masked_key,
"Next Due Date" => nextduedate_display,
"Registration Date" => regdate_display,
"Server ID" => serverid_display,
"Sockets" => sockets_display,
"Last Check" => checktime_display,
"Message" => message_display
}
end
|
#to_hash(model) ⇒ Hash{String => Object}
Hash representation for JSON/YAML output. Includes the full key —
JSON/YAML output is opt-in via -o, so the user already asked for
the raw data.
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/pvectl/presenters/subscription.rb', line 66
def to_hash(model)
@subscription = model
{
"node" => subscription.node,
"status" => subscription.status,
"level" => subscription.level,
"product" => subscription.productname,
"key" => subscription.key,
"next_due_date" => subscription.nextduedate,
"registration_date" => subscription.regdate,
"checktime" => subscription.checktime,
"server_id" => subscription.serverid,
"sockets" => subscription.sockets,
"url" => subscription.url,
"message" => subscription.message
}
end
|
#to_row(model, **_context) ⇒ Array<String>
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/pvectl/presenters/subscription.rb', line 26
def to_row(model, **_context)
@subscription = model
[
node_display,
level_display,
status_display,
nextduedate_display,
masked_key
]
end
|
#to_wide_row(model, **context) ⇒ Array<String>
Wide row exposes the full key (after PRODUCT/REGDATE/SERVERID extras).
We replace the masked KEY column with the full one to make -o wide
useful for copying the license out without re-running with -o json.
54
55
56
57
58
|
# File 'lib/pvectl/presenters/subscription.rb', line 54
def to_wide_row(model, **context)
row = to_row(model, **context).dup
row[columns.index("KEY")] = full_key_display
row + (model, **context)
end
|