varanus 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89ed4dafd7bacfa4ef69c04cb02511a32779cde9013a1448db944ba46465e823
4
- data.tar.gz: 3e04df3f49b583e88b653c0079a94b890bb139eddc5200ea80f61d8181f5d81a
3
+ metadata.gz: 72820b52f9184bfc3c35816e39b1c721d0e4eabf6c660b6c4da95d5cdb1bf025
4
+ data.tar.gz: 3cc5f9ac737e5c375027db08860443b6ece64dac58ad7cf7e515a9f6009e825a
5
5
  SHA512:
6
- metadata.gz: e48bee6b67a987b02228e60c38ef23e5aefbe948cf689db1523ba57b22cbc96d15a5c222c8f71419fa180feeb4aac4764512cea4c6056352bb1e80807ef28b3b
7
- data.tar.gz: '08972545063bcf545370cbf385c9fd60f8d61797de4f8423af3c61b1560b99346a7591f451371b59155661fc11741490bcbeab312ad51b7985926c94c81f6585'
6
+ metadata.gz: 614b412e36992ee4a7c99f06a26e7e5f3768960200e2d962e8ffd9d0aaf64502dc81643be9c038b151ca44de0dea84a952f8a58b1d67b1379f1cf0806a3fdbd5
7
+ data.tar.gz: 484a02bacc17c1b26ad7749d10142bf48570a6260b5557267318d25bb3d051ac3a19030f7522ef9684274424d4a7f25d2e863faedf6d64c75932eb1a9fd63af8
@@ -6,10 +6,9 @@ sudo: false
6
6
  language: ruby
7
7
  cache: bundler
8
8
  rvm:
9
- - 2.3
10
- - 2.4
11
9
  - 2.5
12
10
  - 2.6
11
+ - 2.7
13
12
  before_install: gem install bundler -v 1.16.5
14
13
  before_script:
15
14
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
@@ -1,3 +1,6 @@
1
+ ### 0.4.0 (2021-01-06)
2
+ * Add Varanus::DCV
3
+
1
4
  ### 0.3.1 (2020-10-14)
2
5
  * Fix issue when Sectigo reports two identical 'Short Life' certs
3
6
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- varanus (0.3.1)
4
+ varanus (0.4.0)
5
5
  faraday
6
6
  faraday_middleware
7
7
  savon (~> 2.0)
@@ -9,61 +9,61 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- addressable (2.5.2)
13
- public_suffix (>= 2.0.2, < 4.0)
12
+ addressable (2.7.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
14
  akami (1.3.1)
15
15
  gyoku (>= 0.4.0)
16
16
  nokogiri
17
17
  ast (2.4.1)
18
- builder (3.2.3)
19
- crack (0.4.3)
20
- safe_yaml (~> 1.0.0)
21
- docile (1.3.1)
22
- faraday (0.15.3)
18
+ builder (3.2.4)
19
+ crack (0.4.5)
20
+ rexml
21
+ docile (1.3.4)
22
+ faraday (1.3.0)
23
+ faraday-net_http (~> 1.0)
23
24
  multipart-post (>= 1.2, < 3)
24
- faraday_middleware (0.12.2)
25
- faraday (>= 0.7.4, < 1.0)
25
+ ruby2_keywords
26
+ faraday-net_http (1.0.0)
27
+ faraday_middleware (1.0.0)
28
+ faraday (~> 1.0)
26
29
  gyoku (1.3.1)
27
30
  builder (>= 2.1.2)
28
- hashdiff (0.3.7)
29
- httpi (2.4.4)
31
+ hashdiff (1.0.1)
32
+ httpi (2.4.5)
30
33
  rack
31
34
  socksify
32
- json (2.1.0)
33
- metaclass (0.0.4)
34
- mini_portile2 (2.3.0)
35
- minitest (5.11.3)
35
+ minitest (5.14.3)
36
36
  minitest-rg (5.2.0)
37
37
  minitest (~> 5.0)
38
- mocha (1.7.0)
39
- metaclass (~> 0.0.1)
40
- multipart-post (2.0.0)
41
- nokogiri (1.8.5)
42
- mini_portile2 (~> 2.3.0)
38
+ mocha (1.12.0)
39
+ multipart-post (2.1.1)
40
+ nokogiri (1.11.1-x86_64-linux)
41
+ racc (~> 1.4)
43
42
  nori (2.6.0)
44
- parallel (1.19.2)
45
- parser (2.7.1.4)
43
+ parallel (1.20.1)
44
+ parser (3.0.0.0)
46
45
  ast (~> 2.4.1)
47
- public_suffix (3.0.3)
48
- rack (2.0.6)
46
+ public_suffix (4.0.6)
47
+ racc (1.5.2)
48
+ rack (2.2.3)
49
49
  rainbow (3.0.0)
50
50
  rake (10.5.0)
51
- regexp_parser (1.7.1)
51
+ regexp_parser (2.0.3)
52
52
  rexml (3.2.4)
53
- rubocop (0.89.1)
53
+ rubocop (1.7.0)
54
54
  parallel (~> 1.10)
55
- parser (>= 2.7.1.1)
55
+ parser (>= 2.7.1.5)
56
56
  rainbow (>= 2.2.2, < 4.0)
57
- regexp_parser (>= 1.7)
57
+ regexp_parser (>= 1.8, < 3.0)
58
58
  rexml
59
- rubocop-ast (>= 0.3.0, < 1.0)
59
+ rubocop-ast (>= 1.2.0, < 2.0)
60
60
  ruby-progressbar (~> 1.7)
61
61
  unicode-display_width (>= 1.4.0, < 2.0)
62
- rubocop-ast (0.3.0)
63
- parser (>= 2.7.1.4)
64
- ruby-progressbar (1.10.1)
65
- safe_yaml (1.0.4)
66
- savon (2.12.0)
62
+ rubocop-ast (1.4.0)
63
+ parser (>= 2.7.1.5)
64
+ ruby-progressbar (1.11.0)
65
+ ruby2_keywords (0.0.2)
66
+ savon (2.12.1)
67
67
  akami (~> 1.2)
68
68
  builder (>= 2.1.2)
69
69
  gyoku (~> 1.2)
@@ -71,21 +71,23 @@ GEM
71
71
  nokogiri (>= 1.8.1)
72
72
  nori (~> 2.4)
73
73
  wasabi (~> 3.4)
74
- simplecov (0.16.1)
74
+ simplecov (0.21.1)
75
75
  docile (~> 1.1)
76
- json (>= 1.8, < 3)
77
- simplecov-html (~> 0.10.0)
78
- simplecov-html (0.10.2)
76
+ simplecov-html (~> 0.11)
77
+ simplecov_json_formatter (~> 0.1)
78
+ simplecov-html (0.12.3)
79
+ simplecov_json_formatter (0.1.2)
79
80
  socksify (1.7.1)
80
81
  unicode-display_width (1.7.0)
81
- wasabi (3.5.0)
82
+ wasabi (3.6.1)
83
+ addressable
82
84
  httpi (~> 2.0)
83
85
  nokogiri (>= 1.4.2)
84
- webmock (3.4.2)
86
+ webmock (3.11.0)
85
87
  addressable (>= 2.3.6)
86
88
  crack (>= 0.3.2)
87
- hashdiff
88
- yard (0.9.16)
89
+ hashdiff (>= 0.4.0, < 2.0.0)
90
+ yard (0.9.26)
89
91
 
90
92
  PLATFORMS
91
93
  ruby
@@ -14,6 +14,27 @@ class Varanus
14
14
  @password = password
15
15
  end
16
16
 
17
+ # :nodoc:
18
+ def connection
19
+ @connection ||= Faraday.new(url: 'https://cert-manager.com/api',
20
+ request: { timeout: 300 }) do |conn|
21
+ conn.request :json
22
+ conn.response :json, content_type: /\bjson$/
23
+
24
+ conn.headers['login'] = @username
25
+ conn.headers['password'] = @password
26
+ conn.headers['customerUri'] = @customer_uri
27
+
28
+ conn.adapter Faraday.default_adapter
29
+ end
30
+ end
31
+
32
+ # Retrive DCV instance
33
+ # @return [Varanus::DCV]
34
+ def dcv
35
+ @dcv ||= DCV.new(self)
36
+ end
37
+
17
38
  # Retrieve Reports instance
18
39
  # @return [Varanus::Reports]
19
40
  def reports
@@ -35,6 +56,8 @@ require 'savon'
35
56
 
36
57
  # Require other files in this gem
37
58
  require 'varanus/error'
59
+ require 'varanus/rest_resource'
60
+ require 'varanus/dcv'
38
61
  require 'varanus/reports'
39
62
  require 'varanus/ssl'
40
63
  require 'varanus/ssl/csr'
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ # An connection to the DCV API. This should not be initialized directly. Instead,
4
+ # use Varanus#dcv
5
+ class Varanus::DCV < Varanus::RestResource
6
+ # Returns an Array of DCV information about searched for domains.
7
+ # This method will automatically page through all results
8
+ # @param opts [Hash] - all opts are optional
9
+ # @option opts [String] :domain Domain to search for
10
+ # @option opts [Integer] :org ID of organization
11
+ # @option opts [Integer] :department ID of department
12
+ # @option opts [String] :dcvStatus
13
+ # @option opts [String] :orderStatus
14
+ # @option opts [Integer] :expiresIn Expires in (days)
15
+ #
16
+ # Results will included an extra 'expiration_date_obj' if 'expirationDate' is in the
17
+ # response
18
+ def search opts = {}
19
+ get_with_size_and_position('dcv/v2/validation', opts).map(&method(:_format_status))
20
+ end
21
+
22
+ # Start domain validation process. This must be called before #submit is called
23
+ # @option domain [String] domain to validate
24
+ # @option type [String] Type of validation. Must be one of 'http', 'https', 'cname',
25
+ # or 'email'
26
+ def start domain, type
27
+ post("dcv/v1/validation/start/domain/#{type}", domain: domain)
28
+ end
29
+
30
+ # Retrieve DCV status for a single domain
31
+ # Result will included an extra 'expiration_date_obj' if 'expirationDate' is in the
32
+ # response
33
+ def status domain
34
+ _format_status(post('dcv/v2/validation/status', domain: domain))
35
+ end
36
+
37
+ # Submit domain validation for verficiation. This must be called after #start
38
+ # @option domain [String] domain to validate
39
+ # @option type [String] Type of validation. Must be one of 'http', 'https', 'cname',
40
+ # or 'email'
41
+ # @option email_address [String] This is required of +type+ is 'email'. Otherwise, it is
42
+ # ignored.
43
+ def submit domain, type, email_address = nil
44
+ if type.to_s == 'email'
45
+ raise ArgumentError, 'email_address must be specified' if email_address.nil?
46
+
47
+ post('dcv/v1/validation/submit/domain/email', domain: domain,
48
+ email: email_address)
49
+ else
50
+ post("dcv/v1/validation/submit/domain/#{type}", domain: domain)
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def _format_status status
57
+ return status unless status['expirationDate']
58
+
59
+ status.merge('expiration_date_obj' =>
60
+ Date.strptime(status['expirationDate'], '%Y-%m-%d'))
61
+ end
62
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # An abstract class for rest resources
4
+ # Rest resources should not be initialized directly. They should be created by methods
5
+ # on Varanus
6
+ class Varanus::RestResource
7
+ # :nodoc:
8
+ def initialize varanus
9
+ @varanus = varanus
10
+ end
11
+
12
+ private
13
+
14
+ def check_result result
15
+ body = result.body
16
+ return unless body.is_a?(Hash)
17
+ return if body['code'].nil?
18
+
19
+ klass = Varanus::Error
20
+ if body['code'] == 0 && body['description'] =~ /process/
21
+ klass = Varanus::Error::StillProcessing
22
+ end
23
+
24
+ raise klass.new(body['code'], body['description'])
25
+ end
26
+
27
+ def get path, *args
28
+ result = @varanus.connection.get(path, *args)
29
+ check_result result
30
+ result.body
31
+ end
32
+
33
+ # Performs multiple GETs with varying positions to ensure all results are returned.
34
+ def get_with_size_and_position path, opts = {}
35
+ size = opts[:size] || 200
36
+ position = opts[:position] || 0
37
+
38
+ results = []
39
+ loop do
40
+ params = { size: size, position: position }.merge(opts)
41
+ new_results = get(path, params)
42
+ results += new_results
43
+ break if new_results.length < size
44
+
45
+ position += size
46
+ end
47
+
48
+ results
49
+ end
50
+
51
+ def post path, *args
52
+ result = @varanus.connection.post(path, *args)
53
+ check_result result
54
+ result.body
55
+ end
56
+ end
@@ -2,12 +2,7 @@
2
2
 
3
3
  # An connection to the SSL/TSL API. This should not be initialized directly. Instead,
4
4
  # use Varanus#ssl
5
- class Varanus::SSL
6
- # @note Do not call this directly. Use {Varanus#ssl} to initialize
7
- def initialize varanus
8
- @varanus = varanus
9
- end
10
-
5
+ class Varanus::SSL < Varanus::RestResource
11
6
  # Returns the option from #certificate_types that best matches the csr.
12
7
  # @param csr [Varanus::SSL::CSR]
13
8
  # @return [Hash] The option from {#certificate_types} that best matches the csr
@@ -27,7 +22,7 @@ class Varanus::SSL
27
22
  # Certificate types that can be used to sign a cert
28
23
  # @return [Array<Hash>]
29
24
  def certificate_types
30
- @certificate_types ||= get('types')
25
+ @certificate_types ||= get('ssl/v1/types')
31
26
  end
32
27
 
33
28
  # Return Array of certificate types based on standard sorting.
@@ -57,7 +52,7 @@ class Varanus::SSL
57
52
  # @raise [Varanus::Error::StillProcessing] Cert is still being signed
58
53
  # @return [String] Certificate
59
54
  def collect id, type = 'x509'
60
- get("collect/#{id}/#{type}")
55
+ get("ssl/v1/collect/#{id}/#{type}")
61
56
  end
62
57
 
63
58
  # Revoke an ssl cert
@@ -65,7 +60,7 @@ class Varanus::SSL
65
60
  # @param reason [String] Reason for revoking. Sectigo's API will return an error if it
66
61
  # is blank.
67
62
  def revoke id, reason
68
- post("revoke/#{id}", reason: reason)
63
+ post("ssl/v1/revoke/#{id}", reason: reason)
69
64
  nil
70
65
  end
71
66
 
@@ -97,7 +92,7 @@ class Varanus::SSL
97
92
  comments: opts[:comments].to_s[0, 1024],
98
93
  externalRequester: opts[:external_requester].to_s[0, 512]
99
94
  }
100
- post('enroll', args)['sslId']
95
+ post('ssl/v1/enroll', args)['sslId']
101
96
  end
102
97
 
103
98
  private
@@ -110,39 +105,6 @@ class Varanus::SSL
110
105
  nil
111
106
  end
112
107
 
113
- def check_result result
114
- body = result.body
115
- return unless body.is_a?(Hash)
116
- return if body['code'].nil?
117
-
118
- klass = Varanus::Error
119
- if body['code'] == 0 && body['description'] =~ /process/
120
- klass = Varanus::Error::StillProcessing
121
- end
122
-
123
- raise klass.new(body['code'], body['description'])
124
- end
125
-
126
- def connection
127
- @connection ||= Faraday.new(url: 'https://cert-manager.com/api/ssl/v1',
128
- request: { timeout: 300 }) do |conn|
129
- conn.request :json
130
- conn.response :json, content_type: /\bjson$/
131
-
132
- conn.headers['login'] = @varanus.username
133
- conn.headers['password'] = @varanus.password
134
- conn.headers['customerUri'] = @varanus.customer_uri
135
-
136
- conn.adapter Faraday.default_adapter
137
- end
138
- end
139
-
140
- def get path
141
- result = connection.get(path)
142
- check_result result
143
- result.body
144
- end
145
-
146
108
  def opts_to_cert_type_id opts, csr
147
109
  case opts[:cert_type]
148
110
  when Integer
@@ -154,12 +116,6 @@ class Varanus::SSL
154
116
  end
155
117
  end
156
118
 
157
- def post path, *args
158
- result = connection.post(path, *args)
159
- check_result result
160
- result.body
161
- end
162
-
163
119
  def opts_to_term opts, cert_type_id
164
120
  term = opts[:days]
165
121
  term ||= certificate_types.find { |ct| ct['id'] == cert_type_id }['terms'].min
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Varanus
4
- VERSION = '0.3.1'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: varanus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Dilda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -204,8 +204,10 @@ files:
204
204
  - bin/setup
205
205
  - docker-compose.yml
206
206
  - lib/varanus.rb
207
+ - lib/varanus/dcv.rb
207
208
  - lib/varanus/error.rb
208
209
  - lib/varanus/reports.rb
210
+ - lib/varanus/rest_resource.rb
209
211
  - lib/varanus/ssl.rb
210
212
  - lib/varanus/ssl/csr.rb
211
213
  - lib/varanus/version.rb