Class: Pvectl::Presenters::Subscription
- Defined in:
- lib/pvectl/presenters/subscription.rb
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 Method Summary collapse
-
#checktime_display ⇒ String
Formatted timestamp or “-”.
-
#columns ⇒ Array<String>
Standard column headers.
-
#extra_columns ⇒ Array<String>
Extra column headers for wide output.
- #extra_values(model, **_context) ⇒ Array<String>
-
#full_key_display ⇒ String
Full key or “-”.
- #level_display ⇒ String
-
#masked_key ⇒ String
Returns the license key with the middle masked.
- #message_display ⇒ String
- #nextduedate_display ⇒ String
- #node_display ⇒ String
- #product_display ⇒ String
- #regdate_display ⇒ String
- #serverid_display ⇒ String
- #sockets_display ⇒ String
- #status_display ⇒ String
-
#to_description(model) ⇒ Hash{String => Object}
Description-style hash for ‘pvectl describe subscription` future use.
-
#to_hash(model) ⇒ Hash{String => Object}
Hash representation for JSON/YAML output.
- #to_row(model, **_context) ⇒ Array<String>
-
#to_wide_row(model, **context) ⇒ Array<String>
Wide row exposes the full key (after PRODUCT/REGDATE/SERVERID extras).
Methods inherited from Base
#tags_array, #tags_display, #template_display, #uptime_human, #wide_columns
Instance Method Details
#checktime_display ⇒ String
Returns formatted timestamp or “-”.
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>
Returns standard column headers.
15 16 17 |
# File 'lib/pvectl/presenters/subscription.rb', line 15 def columns %w[NODE LEVEL STATUS NEXTDUEDATE KEY] end |
#extra_columns ⇒ Array<String>
Returns extra column headers for wide output.
20 21 22 |
# File 'lib/pvectl/presenters/subscription.rb', line 20 def extra_columns %w[PRODUCT REGDATE SERVERID] end |
#extra_values(model, **_context) ⇒ Array<String>
39 40 41 42 43 44 45 46 |
# File 'lib/pvectl/presenters/subscription.rb', line 39 def extra_values(model, **_context) @subscription = model [ product_display, regdate_display, serverid_display ] end |
#full_key_display ⇒ String
Returns full key or “-”.
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 subscription. || "-" 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" => } 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. } 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 + extra_values(model, **context) end |