Class: Pvectl::Presenters::Subscription

Inherits:
Base
  • Object
show all
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

Methods inherited from Base

#tags_array, #tags_display, #template_display, #uptime_human, #wide_columns

Instance Method Details

#checktime_displayString

Returns formatted timestamp or “-”.

Returns:

  • (String)

    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

#columnsArray<String>

Returns standard column headers.

Returns:

  • (Array<String>)

    standard column headers



15
16
17
# File 'lib/pvectl/presenters/subscription.rb', line 15

def columns
  %w[NODE LEVEL STATUS NEXTDUEDATE KEY]
end

#extra_columnsArray<String>

Returns extra column headers for wide output.

Returns:

  • (Array<String>)

    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>

Parameters:

Returns:

  • (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_displayString

Returns full key or “-”.

Returns:

  • (String)

    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_displayString

Returns:

  • (String)


116
117
118
# File 'lib/pvectl/presenters/subscription.rb', line 116

def level_display
  subscription.level || "-"
end

#masked_keyString

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).

Returns:

  • (String)


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_displayString

Returns:

  • (String)


146
147
148
# File 'lib/pvectl/presenters/subscription.rb', line 146

def message_display
  subscription.message || "-"
end

#nextduedate_displayString

Returns:

  • (String)


136
137
138
# File 'lib/pvectl/presenters/subscription.rb', line 136

def nextduedate_display
  subscription.nextduedate || "-"
end

#node_displayString

Returns:

  • (String)


106
107
108
# File 'lib/pvectl/presenters/subscription.rb', line 106

def node_display
  subscription.node || "-"
end

#product_displayString

Returns:

  • (String)


121
122
123
# File 'lib/pvectl/presenters/subscription.rb', line 121

def product_display
  subscription.productname || "-"
end

#regdate_displayString

Returns:

  • (String)


126
127
128
# File 'lib/pvectl/presenters/subscription.rb', line 126

def regdate_display
  subscription.regdate || "-"
end

#serverid_displayString

Returns:

  • (String)


131
132
133
# File 'lib/pvectl/presenters/subscription.rb', line 131

def serverid_display
  subscription.serverid || "-"
end

#sockets_displayString

Returns:

  • (String)


141
142
143
# File 'lib/pvectl/presenters/subscription.rb', line 141

def sockets_display
  subscription.sockets ? subscription.sockets.to_s : "-"
end

#status_displayString

Returns:

  • (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.

Parameters:

Returns:

  • (Hash{String => Object})


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.

Parameters:

Returns:

  • (Hash{String => Object})


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>

Parameters:

Returns:

  • (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`.

Parameters:

Returns:

  • (Array<String>)


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