Class: Acmesmith::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/acmesmith/command.rb

Instance Method Summary collapse

Instance Method Details

#add_san(name, *add_sans) ⇒ Object



163
164
165
# File 'lib/acmesmith/command.rb', line 163

def add_san(name, *add_sans)
  client.add_san(name, *add_sans)
end

#authorize(*domains) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/acmesmith/command.rb', line 20

def authorize(*domains)
  warn "! WARNING: 'acmesmith authorize' is not available"
  warn "!"
  warn "! TL;DR: Go ahead; Just run 'acmesmith order'."
  warn "!"
  warn "! Pre-authorization have not implemented yet in acme-client.gem (v2) library."
  warn "! But, required domain authorizations will be performed automatically when ordering a certificate."
  warn "!"
  warn "! Pro Tips: Let's encrypt doesn't provide pre-authorization as of May 18, 2018."
  warn "!"
  # client.authorize(*domains)
end

#autorenew(*names) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/acmesmith/command.rb', line 148

def autorenew(*names)
  remaining_life = case options[:remaining_life]
                   when %r{\A\d+/\d+\z}
                     Rational(options[:remaining_life])
                   when %r{\A([\d.]+)%\z}
                     Rational($1.to_f, 100)
                   when nil
                     nil
                   else
                     raise ArgumentError, "invalid format for --remaining-life: it must be in '..%' or '../..'"
                   end
  client.autorenew(days: options[:days], remaining_life: remaining_life, names: names.empty? ? nil : names)
end

#current(name) ⇒ Object



67
68
69
# File 'lib/acmesmith/command.rb', line 67

def current(name)
  puts client.current(name)
end

#list(name = nil) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/acmesmith/command.rb', line 58

def list(name = nil)
  if name
    puts client.certificate_versions(name)
  else
    puts client.certificates_list
  end
end

#new_account(contact) ⇒ Object



12
13
14
15
16
17
# File 'lib/acmesmith/command.rb', line 12

def (contact)
  puts "=> Creating an account ..."
  key = client.(contact)
  puts "=> Public Key:"
  puts "\n#{key.private_key.public_key.to_pem}"
end

#order(name, *sans) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/acmesmith/command.rb', line 38

def order(name, *sans)
  cert = client.order(
    name, *sans,
    key_type: options[:key_type],
    rsa_key_size: options[:rsa_key_size],
    elliptic_curve: options[:elliptic_curve],
  )
  if options[:show_certificate]
    puts cert.certificate.to_text
    puts cert.certificate.to_pem
  end
end

#post_issue_hooks(name) ⇒ Object



52
53
54
# File 'lib/acmesmith/command.rb', line 52

def post_issue_hooks(name)
  client.post_issue_hooks(name)
end

#register(contact) ⇒ Object



168
169
170
171
172
173
174
175
176
# File 'lib/acmesmith/command.rb', line 168

def register(contact)
  warn "!"
  warn "! DEPRECATION WARNING: Use 'acmesmith new-account' command"
  warn "! There is no user-facing breaking changes. It takes the same arguments with 'acmesmith register'."
  warn "!"
  warn "! This is due to change in semantics of ACME v2. ACME v2 defines 'new-account' instead of 'register' in v1."
  warn "!"
  (contact)
end

#request(name, *sans) ⇒ Object



180
181
182
183
184
185
186
187
188
# File 'lib/acmesmith/command.rb', line 180

def request(name, *sans)
  warn "!"
  warn "! DEPRECATION WARNING: Use 'acmesmith order' command"
  warn "! There is no user-facing breaking changes. It takes the same arguments with 'acmesmith request'."
  warn "!"
  warn "! This is due to change in semantics of ACME v2. ACME v2 defines 'order' instead of 'request' in v1."
  warn "!"
  order(name, *sans)
end

#save(name) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/acmesmith/command.rb', line 114

def save(name)
  client.save(
    name,
    version: options[:version],
    key_mode: options[:key_mode],
    certificate_mode: options[:certificate_mode],
    version_file: options[:version_file],
    key_file: options[:key_file],
    fullchain_file: options[:fullchain_file],
    chain_file: options[:chain_file],
    certificate_file: options[:certificate_file],
    atomic: options[:atomic],
    verbose: true,
  )
end

#save_certificate(name) ⇒ Object



85
86
87
# File 'lib/acmesmith/command.rb', line 85

def save_certificate(name)
  client.save_certificate(name, version: options[:version], mode: options[:mode], output: options[:output], type: options[:type])
end

#save_pkcs12(name) ⇒ Object

Raises:

  • (ArgumentError)


134
135
136
137
138
139
140
141
142
143
# File 'lib/acmesmith/command.rb', line 134

def save_pkcs12(name)
  print 'Passphrase: '
  passphrase = $stdin.noecho { $stdin.gets }.chomp
  print "\nPassphrase (confirm): "
  passphrase2 = $stdin.noecho { $stdin.gets }.chomp
  puts

  raise ArgumentError, "Passphrase doesn't match" if passphrase != passphrase2
  client.save_pkcs12(name, version: options[:version], mode: options[:mode], output: options[:output], passphrase: passphrase)
end

#save_private_key(name) ⇒ Object



100
101
102
# File 'lib/acmesmith/command.rb', line 100

def save_private_key(name)
  client.save_private_key(name, version: options[:version], mode: options[:mode], output: options[:output])
end

#show_certificate(name) ⇒ Object



74
75
76
77
# File 'lib/acmesmith/command.rb', line 74

def show_certificate(name)
  certs = client.get_certificate(name, version: options[:version], type: options[:type])
  puts certs
end

#show_private_key(name) ⇒ Object



91
92
93
# File 'lib/acmesmith/command.rb', line 91

def show_private_key(name)
  puts client.get_private_key(name, version: options[:version])
end