letscert 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cfc8029c8899c6a18ee1c61144cbf6b5ed7abe1
4
- data.tar.gz: a3d1003fa3e102cbd986253947a3fd9df60d14ae
3
+ metadata.gz: 9713b8f8c57715a49c9a47ee496be861b140605e
4
+ data.tar.gz: b066af17d583c2a87e246729fe4ec52478b529b2
5
5
  SHA512:
6
- metadata.gz: 4dcc9323bc64e22f3268c3c16dd7958bf94c7a78612b6826b568b263994cc8659c681139fa87ceda200dc6d567d7df5455c192f1753b385ecc116ef0d4253696
7
- data.tar.gz: f6001ff81d51e9d3cc183bc1a4b2d737be4194c93a75788f7f53233d5e8f24a4b2f7165d1788a251570003b63756dafdaf7b4c5db07f9ce410276d7eca0d1d2b
6
+ metadata.gz: cf1ee72bfb5f7e348ab4dbe35a674e2c723e8004f241a28a705787d9947ab1d1abe1fd0b8788d84f3b7c8734ccd34f6cc6b44b1513f1f5c239b788506a757410
7
+ data.tar.gz: b2bf80554770b4545bf343b12676412b6074979dc92d6e9966ac7bdc9922bef503afa201dd538d20f187f7146f4388ff9ecadab073aec0019dcd824e4f6963bd
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rubocop', '~> 0.42.0', require: false
5
+ gem 'rubocop', '~> 0.45', require: false
data/letscert.gemspec CHANGED
@@ -23,7 +23,7 @@ EOF
23
23
 
24
24
  s.required_ruby_version = '>= 2.1.0'
25
25
 
26
- s.add_dependency 'acme-client', '~>0.4.0'
26
+ s.add_dependency 'acme-client', '~>0.5.0'
27
27
 
28
28
  s.add_development_dependency 'bundler', '~> 1.12'
29
29
  s.add_development_dependency 'rake', '~> 10.0'
@@ -201,6 +201,7 @@ module LetsCert
201
201
  def check_roots(roots)
202
202
  no_roots = roots.select { |_k, v| v.nil? }
203
203
 
204
+ # rubocop:disable Style/GuardClause
204
205
  unless no_roots.empty?
205
206
  raise Error, 'root for the following domain(s) are not specified: ' \
206
207
  "#{no_roots.keys.join(', ')}.\nTry --default_root or " \
@@ -288,10 +289,14 @@ module LetsCert
288
289
  def renewal_necessary?(valid_min)
289
290
  now = Time.now.utc
290
291
  diff = (@cert.not_after - now).to_i
291
- logger.debug { "Certificate expires in #{diff}s on #{@cert.not_after}" \
292
- " (relative to #{now})" }
293
292
 
294
- diff < valid_min
293
+ if diff < valid_min
294
+ true
295
+ else
296
+ logger.info { "Certificate expires in #{ValidTime.time_in_words diff}" \
297
+ " on #{@cert.not_after} (relative to #{now})" }
298
+ false
299
+ end
295
300
  end
296
301
 
297
302
  # Generate new certificate for given domains with existing private key
@@ -46,5 +46,5 @@ module LetsCert
46
46
 
47
47
  end
48
48
 
49
- IOPlugin.register(AccountKey, 'account_key.json')
49
+ IOPlugin.register(AccountKey, 'account_key.json'.freeze)
50
50
  end
@@ -45,6 +45,6 @@ module LetsCert
45
45
 
46
46
  end
47
47
 
48
- IOPlugin.register(CertFile, 'cert.pem', :pem)
49
- IOPlugin.register(CertFile, 'cert.der', :der)
48
+ IOPlugin.register(CertFile, 'cert.pem'.freeze, :pem)
49
+ IOPlugin.register(CertFile, 'cert.der'.freeze, :der)
50
50
  end
@@ -49,5 +49,5 @@ module LetsCert
49
49
 
50
50
  end
51
51
 
52
- IOPlugin.register(ChainFile, 'chain.pem', :pem)
52
+ IOPlugin.register(ChainFile, 'chain.pem'.freeze, :pem)
53
53
  end
@@ -54,5 +54,5 @@ module LetsCert
54
54
 
55
55
  end
56
56
 
57
- IOPlugin.register(FullChainFile, 'fullchain.pem', :pem)
57
+ IOPlugin.register(FullChainFile, 'fullchain.pem'.freeze, :pem)
58
58
  end
@@ -45,6 +45,6 @@ module LetsCert
45
45
 
46
46
  end
47
47
 
48
- IOPlugin.register(KeyFile, 'key.pem', :pem)
49
- IOPlugin.register(KeyFile, 'key.der', :der)
48
+ IOPlugin.register(KeyFile, 'key.pem'.freeze, :pem)
49
+ IOPlugin.register(KeyFile, 'key.der'.freeze, :der)
50
50
  end
@@ -32,10 +32,7 @@ module LetsCert
32
32
  # @param [:pem,:der] type
33
33
  # @raise [ArgumentError] unsupported type
34
34
  def initialize(name, type)
35
- case type
36
- when :pem
37
- when :der
38
- else
35
+ unless [:pem, :der].include? type
39
36
  raise ArgumentError, 'type should be :pem or :der'
40
37
  end
41
38
 
@@ -25,8 +25,8 @@ require 'fileutils'
25
25
 
26
26
  require_relative 'io_plugin'
27
27
  require_relative 'certificate'
28
+ require_relative 'valid_time'
28
29
  require_relative 'runner/logger_formatter'
29
- require_relative 'runner/valid_time'
30
30
 
31
31
  module LetsCert
32
32
 
@@ -105,6 +105,7 @@ module LetsCert
105
105
  # @raise [OptionParser::InvalidOption] on unrecognized or malformed option
106
106
  # @return [void]
107
107
  # rubocop:disable Metrics/MethodLength
108
+ # rubocop:disable Metrics/BlockLength
108
109
  def parse_options
109
110
  @opt_parser = OptionParser.new do |opts|
110
111
  opts.banner = 'Usage: lestcert [options]'
@@ -0,0 +1,88 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2016 Sylvain Daubert
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+ module LetsCert
23
+
24
+ # Class used to process validation time from String.
25
+ # @author Sylvain Daubert
26
+ class ValidTime
27
+
28
+ # Number of seconds in one minute
29
+ SECONDS_IN_ONE_MINUTE = 60
30
+ # Number of seconds in one hour
31
+ SECONDS_IN_ONE_HOUR = 60 * 60
32
+ # Number of seconds in one day
33
+ SECONDS_IN_ONE_DAY = 24 * 60 * 60
34
+
35
+ # Get time in words (e.g. xx days or xx hours)
36
+ # @param [Integer] seconds
37
+ # @return [String]
38
+ def self.time_in_words(seconds)
39
+ if seconds < SECONDS_IN_ONE_MINUTE
40
+ '%u seconds' % seconds
41
+ elsif seconds < SECONDS_IN_ONE_HOUR
42
+ 'about %u minutes' % (seconds / SECONDS_IN_ONE_MINUTE)
43
+ elsif seconds < SECONDS_IN_ONE_DAY
44
+ 'about %u hours' % (seconds / SECONDS_IN_ONE_HOUR)
45
+ else
46
+ 'about %u days' % (seconds / SECONDS_IN_ONE_DAY)
47
+ end
48
+ end
49
+
50
+ # @param [String] str time string. May be:
51
+ # * an integer -> time in seconds
52
+ # * an integer plus a letter:
53
+ # * 30m: 30 minutes,
54
+ # * 30h: 30 hours,
55
+ # * 30d: 30 days.
56
+ def initialize(str)
57
+ m = str.match(/^(\d+)([mhd])?$/)
58
+ if m
59
+ @seconds = case m[2]
60
+ when nil
61
+ m[1].to_i
62
+ when 'm'
63
+ m[1].to_i * SECONDS_IN_ONE_MINUTE
64
+ when 'h'
65
+ m[1].to_i * SECONDS_IN_ONE_HOUR
66
+ when 'd'
67
+ m[1].to_i * SECONDS_IN_ONE_DAY
68
+ end
69
+ else
70
+ raise OptionParser::InvalidArgument,
71
+ "invalid argument: valid-min #{str}"
72
+ end
73
+ @string = str
74
+ end
75
+
76
+ # Get time in seconds
77
+ # @return [Integer]
78
+ def to_seconds
79
+ @seconds
80
+ end
81
+
82
+ # Get time as string
83
+ # @return [String]
84
+ def to_s
85
+ @string
86
+ end
87
+ end
88
+ end
@@ -1,6 +1,6 @@
1
1
  module LetsCert
2
2
 
3
3
  # Letscert version number
4
- VERSION = '0.4.4'.freeze
4
+ VERSION = '0.4.5'.freeze
5
5
 
6
6
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letscert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Daubert
@@ -31,7 +31,7 @@ cert_chain:
31
31
  dMi8WSKt03lfzyxIqZseBwVYYn+XMlzCcJLXCUgZXHcBRRRDH5wGDqOqXjL25b2O
32
32
  6m3JJngqkCFrOw==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-11-01 00:00:00.000000000 Z
34
+ date: 2016-11-21 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: acme-client
@@ -39,14 +39,14 @@ dependencies:
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: 0.4.0
42
+ version: 0.5.0
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 0.4.0
49
+ version: 0.5.0
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: bundler
52
52
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +164,7 @@ files:
164
164
  - lib/letscert/loggable.rb
165
165
  - lib/letscert/runner.rb
166
166
  - lib/letscert/runner/logger_formatter.rb
167
- - lib/letscert/runner/valid_time.rb
167
+ - lib/letscert/valid_time.rb
168
168
  - lib/letscert/version.rb
169
169
  homepage: https://github.com/sdaubert/letscert
170
170
  licenses:
metadata.gz.sig CHANGED
Binary file
@@ -1,69 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2016 Sylvain Daubert
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
- module LetsCert
23
- class Runner
24
-
25
- # Class used to process validation time from String.
26
- # @author Sylvain Daubert
27
- class ValidTime
28
-
29
- # @param [String] str time string. May be:
30
- # * an integer -> time in seconds
31
- # * an integer plus a letter:
32
- # * 30m: 30 minutes,
33
- # * 30h: 30 hours,
34
- # * 30d: 30 days.
35
- def initialize(str)
36
- m = str.match(/^(\d+)([mhd])?$/)
37
- if m
38
- @seconds = case m[2]
39
- when nil
40
- m[1].to_i
41
- when 'm'
42
- m[1].to_i * 60
43
- when 'h'
44
- m[1].to_i * 60 * 60
45
- when 'd'
46
- m[1].to_i * 24 * 60 * 60
47
- end
48
- else
49
- raise OptionParser::InvalidArgument,
50
- "invalid argument: --valid-min #{str}"
51
- end
52
- @string = str
53
- end
54
-
55
- # Get time in seconds
56
- # @return [Integer]
57
- def to_seconds
58
- @seconds
59
- end
60
-
61
- # Get time as string
62
- # @return [String]
63
- def to_s
64
- @string
65
- end
66
- end
67
-
68
- end
69
- end