10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/ree/cli/licensing/renew_license.rb', line 10
def run(client_id:, expires_at:, output_path: nil, clients_dir: Dir.pwd, stdout: $stdout)
store = Ree::Licensing::ClientStore.new(clients_dir)
client = store.find_client(client_id)
raise Ree::Error.new("Client #{client_id} not found") unless client
last_license = store.last_license(client_id)
raise Ree::Error.new("No existing license found for #{client_id}") unless last_license
result = Ree::Licensing::LicenseGenerator.generate(
client_id: client_id,
private_key_pem: client['private_key_pem'],
public_key_pem: client['public_key_pem'],
aes_key_hex: last_license['aes_key_hex'],
iv_hex: last_license['iv_hex'],
expires_at: expires_at
)
store.add_license(client_id, result[:license_record])
output = output_path || File.join(clients_dir, "license_#{client_id}.json")
File.write(output, JSON.pretty_generate(result[:license_file]))
stdout.puts "License renewed successfully:"
stdout.puts " Client ID: #{client_id}"
stdout.puts " Expires at: #{expires_at}"
stdout.puts " License file: #{output}"
result
rescue Ree::Error => e
stdout.puts "Error: #{e.message}"
end
|