digicert-cli 0.4.2 → 0.5.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 +4 -4
- data/.rubocop.yml +21 -16
- data/CHANGELOG.md +7 -0
- data/Gemfile +3 -0
- data/digicert-cli.gemspec +2 -1
- data/lib/digicert/cli.rb +1 -1
- data/lib/digicert/cli/commands/certificate.rb +2 -0
- data/lib/digicert/cli/commands/csr.rb +4 -2
- data/lib/digicert/cli/commands/order.rb +51 -0
- data/lib/digicert/cli/csr.rb +21 -8
- data/lib/digicert/cli/order_creator.rb +58 -0
- data/lib/digicert/cli/order_duplicator.rb +62 -0
- data/lib/digicert/cli/order_reissuer.rb +0 -5
- data/lib/digicert/cli/util.rb +14 -0
- data/lib/digicert/cli/version.rb +1 -1
- data/spec/acceptance/certificate_spec.rb +4 -4
- data/spec/acceptance/config_spec.rb +2 -2
- data/spec/acceptance/csr_spec.rb +7 -7
- data/spec/acceptance/duplicating_order_spec.rb +22 -0
- data/spec/acceptance/order_spec.rb +38 -4
- data/spec/acceptance/reissuing_order_spec.rb +2 -2
- data/spec/digicert/cli/csr_spec.rb +6 -3
- data/spec/digicert/cli/order_creator_spec.rb +60 -0
- data/spec/digicert/cli/order_duplicator_spec.rb +75 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/console_helper.rb +29 -0
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1abbf50c6b8d9282270e6a7d0ac3612697960bad830a6e501e69f79a083a6306
|
4
|
+
data.tar.gz: a514f1d0cb523933312bae6ba79271ecda52037ef2f2cfb280ecda7e59c67dfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f629804e272191fd80d25fa901d8bb7aac958f2d7cf71589081b8e16cf5271916eb3d6d24362f6d0b766cf3e970af342255c559352548c61415c63c612ad203f
|
7
|
+
data.tar.gz: 8bd04d42035fe1acce5871813e23e8b085f23e415303ace19261787522dad5c7e9673215eb1e94fee637331d1a56f88ca9cce30ad19e24d9ea2d26f14f36ad81
|
data/.rubocop.yml
CHANGED
@@ -1,9 +1,4 @@
|
|
1
1
|
AllCops:
|
2
|
-
Include:
|
3
|
-
- "**/*.rake"
|
4
|
-
- "**/Gemfile"
|
5
|
-
- "**/Rakefile"
|
6
|
-
|
7
2
|
Exclude:
|
8
3
|
- db/schema.rb
|
9
4
|
|
@@ -357,8 +352,18 @@ Style/TrailingCommaInArguments:
|
|
357
352
|
- no_comma
|
358
353
|
Enabled: true
|
359
354
|
|
360
|
-
Style/
|
361
|
-
Description: 'Checks for trailing comma in array
|
355
|
+
Style/TrailingCommaInArrayLiteral:
|
356
|
+
Description: 'Checks for trailing comma in array literals.'
|
357
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
|
358
|
+
EnforcedStyleForMultiline: comma
|
359
|
+
SupportedStylesForMultiline:
|
360
|
+
- comma
|
361
|
+
- consistent_comma
|
362
|
+
- no_comma
|
363
|
+
Enabled: true
|
364
|
+
|
365
|
+
Style/TrailingCommaInHashLiteral:
|
366
|
+
Description: 'Checks for trailing comma in hash literals.'
|
362
367
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
|
363
368
|
EnforcedStyleForMultiline: comma
|
364
369
|
SupportedStylesForMultiline:
|
@@ -403,6 +408,13 @@ Layout/AlignParameters:
|
|
403
408
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-double-indent'
|
404
409
|
Enabled: false
|
405
410
|
|
411
|
+
Layout/ConditionPosition:
|
412
|
+
Description: >-
|
413
|
+
Checks for condition placed in a confusing position relative to
|
414
|
+
the keyword.
|
415
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#same-line-condition'
|
416
|
+
Enabled: false
|
417
|
+
|
406
418
|
Layout/DotPosition:
|
407
419
|
Description: 'Checks the position of the dot in multi-line method calls.'
|
408
420
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains'
|
@@ -455,13 +467,6 @@ Lint/CircularArgumentReference:
|
|
455
467
|
Description: "Don't refer to the keyword argument in the default value."
|
456
468
|
Enabled: false
|
457
469
|
|
458
|
-
Lint/ConditionPosition:
|
459
|
-
Description: >-
|
460
|
-
Checks for condition placed in a confusing position relative to
|
461
|
-
the keyword.
|
462
|
-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#same-line-condition'
|
463
|
-
Enabled: false
|
464
|
-
|
465
470
|
Lint/DeprecatedClassMethods:
|
466
471
|
Description: 'Check for deprecated class method calls.'
|
467
472
|
Enabled: false
|
@@ -487,7 +492,7 @@ Lint/HandleExceptions:
|
|
487
492
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions'
|
488
493
|
Enabled: false
|
489
494
|
|
490
|
-
Lint/
|
495
|
+
Lint/LiteralAsCondition:
|
491
496
|
Description: 'Checks of literals used in conditions.'
|
492
497
|
Enabled: false
|
493
498
|
|
@@ -528,7 +533,7 @@ Lint/UnderscorePrefixedVariableName:
|
|
528
533
|
Description: 'Do not use prefix `_` for a variable that is used.'
|
529
534
|
Enabled: false
|
530
535
|
|
531
|
-
Lint/
|
536
|
+
Lint/UnneededCopDisableDirective:
|
532
537
|
Description: >-
|
533
538
|
Checks for rubocop:disable comments that can be removed.
|
534
539
|
Note: this cop is not disabled when disabling all cops.
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.5.0 (2019-03-14)
|
2
|
+
|
3
|
+
* Change CSR's Order Id to be optional
|
4
|
+
* Add `--debug` flag with CLI commands
|
5
|
+
* Add order duplication support in CLI
|
6
|
+
* Add `order create` interface in the gem
|
7
|
+
|
1
8
|
## 0.4.1 (2018-07-18)
|
2
9
|
|
3
10
|
* Upgrade `digicert` gem to latest version
|
data/Gemfile
CHANGED
data/digicert-cli.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = "digicert"
|
22
22
|
|
23
23
|
spec.add_dependency "thor", "~> 0.19.4"
|
24
|
-
spec.add_dependency "digicert", "~> 0.
|
24
|
+
spec.add_dependency "digicert", "~> 0.4.0"
|
25
25
|
spec.add_dependency "openssl", ">= 2.0.3"
|
26
26
|
spec.add_dependency "terminal-table"
|
27
27
|
|
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
31
|
spec.add_development_dependency "webmock", "~> 2.0"
|
32
|
+
spec.add_development_dependency "pry", "~> 0.11.3"
|
32
33
|
end
|
data/lib/digicert/cli.rb
CHANGED
@@ -32,7 +32,7 @@ require "digicert/cli/command"
|
|
32
32
|
module Digicert
|
33
33
|
module CLI
|
34
34
|
def self.start(arguments)
|
35
|
-
Digicert::CLI::
|
35
|
+
Digicert::CLI::Util.run(arguments)
|
36
36
|
rescue Digicert::Errors::Forbidden, NoMethodError
|
37
37
|
Thor::Shell::Basic.new.say(
|
38
38
|
"Invalid: Missing API KEY\n\n" \
|
@@ -4,6 +4,8 @@ module Digicert
|
|
4
4
|
module CLI
|
5
5
|
module Commands
|
6
6
|
class Certificate < Thor
|
7
|
+
class_option :debug, type: "boolean", desc: "Enable debug mode"
|
8
|
+
|
7
9
|
desc "fetch ORDER_ID", "Find an order's certificate"
|
8
10
|
option :quiet, type: :boolean, aliases: "-q", desc: "Retrieve only id"
|
9
11
|
option :output, aliases: "-o", desc: "Path to download the certificate"
|
@@ -4,17 +4,19 @@ module Digicert
|
|
4
4
|
module CLI
|
5
5
|
module Commands
|
6
6
|
class Csr < Thor
|
7
|
-
|
7
|
+
class_option :debug, type: "boolean", desc: "Enable debug mode"
|
8
8
|
|
9
|
+
desc "fetch ORDER_ID", "Fetch an existing CSR"
|
9
10
|
def fetch(order_id)
|
10
11
|
say(csr_instance(order_id: order_id).fetch)
|
11
12
|
end
|
12
13
|
|
13
14
|
desc "generate", "Generate certificate CSR"
|
15
|
+
option :order_id, aliases: "-o", desc: "An Order ID"
|
14
16
|
option :common_name, aliases: "-c", desc: "The common name"
|
17
|
+
option :organization_id, desc: "Your digicert's organization ID"
|
15
18
|
option :san, type: :array, desc: "The subject alternative names"
|
16
19
|
option :key, aliases: "-k", desc: "Complete path to the rsa key file"
|
17
|
-
option :order_id, required: true, aliases: "-o", desc: "An Order ID"
|
18
20
|
|
19
21
|
def generate
|
20
22
|
say(csr_instance.generate)
|
@@ -1,10 +1,14 @@
|
|
1
1
|
require "digicert/cli/order"
|
2
2
|
require "digicert/cli/order_reissuer"
|
3
|
+
require "digicert/cli/order_creator"
|
4
|
+
require "digicert/cli/order_duplicator"
|
3
5
|
|
4
6
|
module Digicert
|
5
7
|
module CLI
|
6
8
|
module Commands
|
7
9
|
class Order < Thor
|
10
|
+
class_option :debug, type: "boolean", desc: "Enable debug mode"
|
11
|
+
|
8
12
|
desc "list", "List digicert orders"
|
9
13
|
method_option :filter, type: :hash, desc: "Specify filter options"
|
10
14
|
|
@@ -22,12 +26,49 @@ module Digicert
|
|
22
26
|
|
23
27
|
desc "reissue ORDER_ID", "Reissue digicert order"
|
24
28
|
option :csr, desc: "The CSR content from a file"
|
29
|
+
method_option :common_name, desc: "Certificate Common Name"
|
30
|
+
method_option :signature_hash, desc: "Certificate signature hash"
|
25
31
|
option :output, aliases: "-o", desc: "Path to download certificates"
|
26
32
|
|
27
33
|
def reissue(order_id)
|
28
34
|
say(reissue_an_order(order_id))
|
29
35
|
end
|
30
36
|
|
37
|
+
desc "create", "Create a new order"
|
38
|
+
method_option :csr, desc: "The CSR content from a file"
|
39
|
+
method_option :common_name, desc: "Certificate Common Name"
|
40
|
+
method_option :signature_hash, desc: "Certificate signature hash"
|
41
|
+
method_option :organization_id, desc: "The Organization ID"
|
42
|
+
method_option :validity_years, desc: "Validity years for certificate"
|
43
|
+
method_option :comments, desc: "Comments about the certificate order"
|
44
|
+
method_option :payment_method, desc: "Speicfy the payment method"
|
45
|
+
|
46
|
+
method_option :disable_renewal_notifications, type: :boolean
|
47
|
+
method_option :server_platform_id, desc: "Server Platform Id"
|
48
|
+
method_option :profile_option, desc: "Specify certificate profile"
|
49
|
+
method_option :organization_units, type: :array, desc: "organization_units"
|
50
|
+
method_option :custom_expiration_date, desc: "Expiry Date in YYY-MM-DD"
|
51
|
+
method_option :renewal_of_order_id, desc: "Id for renewalable Order"
|
52
|
+
method_option :disable_ct, type: :boolean, desc: "Disable CT logging"
|
53
|
+
|
54
|
+
def create(name_id)
|
55
|
+
order = create_new_order(name_id, options)
|
56
|
+
say("New Order Created! Oder Id: #{order.id}.")
|
57
|
+
|
58
|
+
rescue Digicert::Errors::RequestError => error
|
59
|
+
say("Request Error: #{error}.")
|
60
|
+
end
|
61
|
+
|
62
|
+
desc "duplicate ORDER_ID", "Duplicate digicert order"
|
63
|
+
option :csr, desc: "The CSR content from a file"
|
64
|
+
method_option :common_name, desc: "Certificate Common Name"
|
65
|
+
method_option :signature_hash, desc: "Certificate signature hash"
|
66
|
+
option :output, aliases: "-o", desc: "Path to download certificate"
|
67
|
+
|
68
|
+
def duplicate(order_id)
|
69
|
+
say(duplicate_an_order(order_id))
|
70
|
+
end
|
71
|
+
|
31
72
|
private
|
32
73
|
|
33
74
|
def order_instance
|
@@ -39,6 +80,16 @@ module Digicert
|
|
39
80
|
options.merge(order_id: order_id),
|
40
81
|
).create
|
41
82
|
end
|
83
|
+
|
84
|
+
def create_new_order(name_id, options)
|
85
|
+
Digicert::CLI::OrderCreator.create(name_id, options)
|
86
|
+
end
|
87
|
+
|
88
|
+
def duplicate_an_order(order_id)
|
89
|
+
Digicert::CLI::OrderDuplicator.new(
|
90
|
+
options.merge(order_id: order_id),
|
91
|
+
).create
|
92
|
+
end
|
42
93
|
end
|
43
94
|
end
|
44
95
|
end
|
data/lib/digicert/cli/csr.rb
CHANGED
@@ -8,24 +8,38 @@ module Digicert
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def generate
|
11
|
-
if order
|
12
|
-
|
11
|
+
if order || valid_data?
|
12
|
+
generate_new_csr
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
attr_reader :rsa_key
|
18
|
+
attr_reader :rsa_key, :organization_id, :common_name
|
19
19
|
|
20
20
|
def extract_local_attributes(options)
|
21
21
|
@rsa_key = options.fetch(:key, nil)
|
22
|
+
@common_name = options.fetch(:common_name, nil)
|
23
|
+
@organization_id = options.fetch(:organization_id, nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid_data?
|
27
|
+
!organization.nil? && !options[:common_name].nil?
|
22
28
|
end
|
23
29
|
|
24
30
|
def order
|
25
|
-
|
31
|
+
if order_id
|
32
|
+
@order ||= Digicert::Order.fetch(order_id)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def organization
|
37
|
+
if organization_id
|
38
|
+
@organization ||= Digicert::Organization.fetch(organization_id)
|
39
|
+
end
|
26
40
|
end
|
27
41
|
|
28
|
-
def
|
42
|
+
def generate_new_csr
|
29
43
|
if rsa_key && File.exists?(rsa_key)
|
30
44
|
Digicert::CSRGenerator.generate(csr_attributes(order))
|
31
45
|
end
|
@@ -34,9 +48,8 @@ module Digicert
|
|
34
48
|
def csr_attributes(order)
|
35
49
|
Hash.new.tap do |csr|
|
36
50
|
csr[:rsa_key] = File.read(rsa_key)
|
37
|
-
csr[:organization] = order.organization
|
38
|
-
csr[:common_name] =
|
39
|
-
options[:common_name] || order.certificate.common_name
|
51
|
+
csr[:organization] = organization || order.organization
|
52
|
+
csr[:common_name] = common_name || order.certificate.common_name
|
40
53
|
|
41
54
|
if options[:san]
|
42
55
|
csr[:san_names] = options[:san]
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Digicert
|
2
|
+
module CLI
|
3
|
+
class OrderCreator < Digicert::CLI::Base
|
4
|
+
def initialize(name_id, attributes)
|
5
|
+
@name_id = name_id
|
6
|
+
@attributes = attributes
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
create_order
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.create(name_id, attributes)
|
14
|
+
new(name_id, attributes).create
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :name_id, :attributes
|
20
|
+
|
21
|
+
def create_order
|
22
|
+
Digicert::Order.create(name_id, order_attributes)
|
23
|
+
end
|
24
|
+
|
25
|
+
def csr_file_content(csr_file)
|
26
|
+
if csr_file && File.exists?(csr_file)
|
27
|
+
File.read(csr_file)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def organization
|
32
|
+
Digicert::Organization.all.last
|
33
|
+
end
|
34
|
+
|
35
|
+
def order_attributes
|
36
|
+
{
|
37
|
+
certificate: {
|
38
|
+
common_name: attributes[:common_name],
|
39
|
+
csr: csr_file_content(attributes[:csr]),
|
40
|
+
signature_hash: attributes[:signature_hash],
|
41
|
+
organization_units: attributes[:organization_units],
|
42
|
+
server_platform: { id: attributes[:server_platform_id] },
|
43
|
+
profile_option: attributes[:profile_option],
|
44
|
+
},
|
45
|
+
|
46
|
+
organization: { id: attributes[:organization_id] || organization.id },
|
47
|
+
validity_years: attributes[:validity_years] || 3,
|
48
|
+
custom_expiration_date: attributes[:custom_expiration_date],
|
49
|
+
comments: attributes[:comments],
|
50
|
+
disable_renewal_notifications: attributes[:disable_renewal_notifications],
|
51
|
+
renewal_of_order_id: attributes[:renewal_of_order_id],
|
52
|
+
payment_method: attributes[:payment_method],
|
53
|
+
disable_ct: attributes[:disable_ct],
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Digicert
|
2
|
+
module CLI
|
3
|
+
class OrderDuplicator < Digicert::CLI::Base
|
4
|
+
def create
|
5
|
+
apply_output_options(duplicate_an_order)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
attr_reader :csr_file, :output_path
|
11
|
+
|
12
|
+
def extract_local_attributes(options)
|
13
|
+
@csr_file = options.fetch(:csr, nil)
|
14
|
+
@output_path = options.fetch(:output, "/tmp")
|
15
|
+
end
|
16
|
+
|
17
|
+
def duplicate_an_order
|
18
|
+
Digicert::OrderDuplicator.create(order_params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def order_params
|
22
|
+
Hash.new.tap do |order_params|
|
23
|
+
order_params[:order_id] = order_id
|
24
|
+
|
25
|
+
if csr_file && File.exists?(csr_file)
|
26
|
+
order_params[:csr] = File.read(csr_file)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def apply_output_options(duplicate)
|
32
|
+
if duplicate
|
33
|
+
print_request_details(duplicate.requests.first)
|
34
|
+
fetch_and_download_certificate(duplicate.requests.first.id)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def print_request_details(request)
|
39
|
+
Digicert::CLI::Util.say(
|
40
|
+
"Duplication request #{request.id} created for order - #{order_id}",
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def fetch_and_download_certificate(request_id)
|
45
|
+
if options[:output]
|
46
|
+
certificate = fetch_certificate(request_id)
|
47
|
+
download_certificate_order(certificate.id)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def fetch_certificate(request_id)
|
52
|
+
Digicert::DuplicateCertificateFinder.find_by(request_id: request_id)
|
53
|
+
end
|
54
|
+
|
55
|
+
def download_certificate_order(certificate_id)
|
56
|
+
Digicert::CLI::CertificateDownloader.download(
|
57
|
+
filename: order_id, path: output_path, certificate_id: certificate_id,
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/digicert/cli/util.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "digicert"
|
1
2
|
require "terminal-table"
|
2
3
|
|
3
4
|
module Digicert
|
@@ -13,6 +14,19 @@ module Digicert
|
|
13
14
|
def self.say(message, color = nil)
|
14
15
|
Thor::Shell::Basic.new.say(message, color)
|
15
16
|
end
|
17
|
+
|
18
|
+
def self.run(arguments)
|
19
|
+
if arguments.include?("--debug")
|
20
|
+
arguments.delete("--debug")
|
21
|
+
|
22
|
+
Digicert.configuration.debug_mode = true
|
23
|
+
Digicert::CLI::Command.start(arguments)
|
24
|
+
Digicert.configuration.debug_mode = true
|
25
|
+
else
|
26
|
+
|
27
|
+
Digicert::CLI::Command.start(arguments)
|
28
|
+
end
|
29
|
+
end
|
16
30
|
end
|
17
31
|
end
|
18
32
|
end
|
data/lib/digicert/cli/version.rb
CHANGED
@@ -6,7 +6,7 @@ RSpec.describe "Certificate" do
|
|
6
6
|
command = %w(certificate fetch 123456 --quiet)
|
7
7
|
allow(certificate_klass).to receive_message_chain(:new, :fetch)
|
8
8
|
|
9
|
-
Digicert::CLI.start(command)
|
9
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
10
10
|
|
11
11
|
expect(certificate_klass.new).to have_received(:fetch)
|
12
12
|
expect(certificate_klass).to have_received(:new).with(
|
@@ -20,7 +20,7 @@ RSpec.describe "Certificate" do
|
|
20
20
|
command = %w(certificate fetch 123456 --output /tmp/downloads)
|
21
21
|
allow(Digicert::CLI::Certificate).to receive_message_chain(:new, :fetch)
|
22
22
|
|
23
|
-
Digicert::CLI.start(command)
|
23
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
24
24
|
|
25
25
|
expect(Digicert::CLI::Certificate).to have_received(:new).with(
|
26
26
|
order_id: "123456", output: "/tmp/downloads"
|
@@ -36,7 +36,7 @@ RSpec.describe "Certificate" do
|
|
36
36
|
Digicert::CLI::Certificate,
|
37
37
|
).to receive_message_chain(:new, :duplicates)
|
38
38
|
|
39
|
-
Digicert::CLI.start(command)
|
39
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
40
40
|
|
41
41
|
expect(
|
42
42
|
Digicert::CLI::Certificate,
|
@@ -52,7 +52,7 @@ RSpec.describe "Certificate" do
|
|
52
52
|
Digicert::CLI::Certificate,
|
53
53
|
).to receive_message_chain(:new, :download)
|
54
54
|
|
55
|
-
Digicert::CLI.start(command)
|
55
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
56
56
|
|
57
57
|
expect(
|
58
58
|
Digicert::CLI::Certificate,
|
@@ -4,9 +4,9 @@ RSpec.describe "Config" do
|
|
4
4
|
describe "configuring key" do
|
5
5
|
it "stores the provided api key" do
|
6
6
|
command = %w(config api-key DIGICERT_SECRET_KEY)
|
7
|
-
allow(Digicert::CLI::RCFile).to receive(:set_key)
|
8
7
|
|
9
|
-
Digicert::CLI.
|
8
|
+
allow(Digicert::CLI::RCFile).to receive(:set_key)
|
9
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
10
10
|
|
11
11
|
expect(
|
12
12
|
Digicert::CLI::RCFile,
|
data/spec/acceptance/csr_spec.rb
CHANGED
@@ -6,7 +6,7 @@ RSpec.describe "CSR" do
|
|
6
6
|
command = %w(csr fetch 123456)
|
7
7
|
allow(Digicert::CLI::CSR).to receive_message_chain(:new, :fetch)
|
8
8
|
|
9
|
-
Digicert::CLI.start(command)
|
9
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
10
10
|
|
11
11
|
expect(Digicert::CLI::CSR).to have_received(:new).with(order_id: "123456")
|
12
12
|
end
|
@@ -18,29 +18,29 @@ RSpec.describe "CSR" do
|
|
18
18
|
allow(Digicert::CLI::CSR).to receive_message_chain(:new, :generate)
|
19
19
|
command = %w(csr generate -o 123456 --key ./spec/fixtures/rsa4096.key)
|
20
20
|
|
21
|
-
Digicert::CLI.start(command)
|
21
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
22
22
|
|
23
23
|
expect(Digicert::CLI::CSR).to have_received(:new).with(
|
24
24
|
order_id: "123456", key: "./spec/fixtures/rsa4096.key",
|
25
25
|
)
|
26
|
-
end
|
26
|
+
end
|
27
|
+
end
|
27
28
|
|
28
29
|
context "with provided details" do
|
29
30
|
it "generates a new CSR with the details" do
|
30
31
|
command = %w(
|
31
32
|
csr generate
|
32
|
-
--
|
33
|
+
--organization_id 1234
|
33
34
|
--common_name ribosetest.com
|
34
35
|
--key ./spec/fixtures/rsa4096.key
|
35
36
|
--san site1.ribosetest.com site2.ribosetest.com
|
36
37
|
)
|
37
38
|
|
38
39
|
allow(Digicert::CLI::CSR).to receive_message_chain(:new, :generate)
|
39
|
-
|
40
|
-
Digicert::CLI.start(command)
|
40
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
41
41
|
|
42
42
|
expect(Digicert::CLI::CSR).to have_received(:new).with(
|
43
|
-
|
43
|
+
organization_id: "1234",
|
44
44
|
common_name: "ribosetest.com",
|
45
45
|
key: "./spec/fixtures/rsa4096.key",
|
46
46
|
san: ["site1.ribosetest.com", "site2.ribosetest.com"],
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Order duplicating" do
|
4
|
+
describe "duplicate an order" do
|
5
|
+
context "duplicate with new csr" do
|
6
|
+
it "duplicate an order with provided csr" do
|
7
|
+
mock_digicert_order_duplication_message_chain
|
8
|
+
command = %w(order duplicate 123456 --csr ./spec/fixtures/rsa4096.csr)
|
9
|
+
|
10
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
11
|
+
|
12
|
+
expect(Digicert::CLI::OrderDuplicator).to have_received(:new).
|
13
|
+
with(order_id: "123456", csr: "./spec/fixtures/rsa4096.csr")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def mock_digicert_order_duplication_message_chain
|
19
|
+
allow(Digicert::CLI::OrderDuplicator).
|
20
|
+
to receive_message_chain(:new, :create)
|
21
|
+
end
|
22
|
+
end
|
@@ -4,9 +4,9 @@ RSpec.describe "Order" do
|
|
4
4
|
describe "listing orders" do
|
5
5
|
it "retrieves the list of the orders" do
|
6
6
|
command = %w(order list --filter common_name:*.ribostetest.com)
|
7
|
-
allow(Digicert::CLI::Order).to receive_message_chain(:new, :list)
|
8
7
|
|
9
|
-
Digicert::CLI.
|
8
|
+
allow(Digicert::CLI::Order).to receive_message_chain(:new, :list)
|
9
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
10
10
|
|
11
11
|
expect(Digicert::CLI::Order.new).to have_received(:list)
|
12
12
|
end
|
@@ -15,11 +15,45 @@ RSpec.describe "Order" do
|
|
15
15
|
describe "finding an order" do
|
16
16
|
it "finds a specific order based on the filters params" do
|
17
17
|
command = %w(order find --filter common_name:ribosetest.com)
|
18
|
-
allow(Digicert::CLI::Order).to receive_message_chain(:new, :find)
|
19
18
|
|
20
|
-
Digicert::CLI.
|
19
|
+
allow(Digicert::CLI::Order).to receive_message_chain(:new, :find)
|
20
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
21
21
|
|
22
22
|
expect(Digicert::CLI::Order.new).to have_received(:find)
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
describe "creating an order" do
|
27
|
+
context "with valid information" do
|
28
|
+
it "creates a new certificate order" do
|
29
|
+
allow(
|
30
|
+
Digicert::CLI::OrderCreator,
|
31
|
+
).to receive(:create).and_return(double("order", id: 123_456))
|
32
|
+
|
33
|
+
command = %w(
|
34
|
+
order create ssl_plus
|
35
|
+
--csr ./spec/fixtures/rsa4096.csr
|
36
|
+
--common-name ribosetest.com
|
37
|
+
--signature-hash sha512
|
38
|
+
--organization-id 123456
|
39
|
+
--validity-years 3
|
40
|
+
--payment-method card
|
41
|
+
)
|
42
|
+
|
43
|
+
output = capture_stdout { Digicert::CLI.start(command) }
|
44
|
+
|
45
|
+
expect(output).to include("New Order Created! Oder Id")
|
46
|
+
expect(Digicert::CLI::OrderCreator).to have_received(:create).
|
47
|
+
with(
|
48
|
+
"ssl_plus",
|
49
|
+
"csr" => "./spec/fixtures/rsa4096.csr",
|
50
|
+
"common_name" => "ribosetest.com",
|
51
|
+
"signature_hash" => "sha512",
|
52
|
+
"organization_id" => "123456",
|
53
|
+
"validity_years" => "3",
|
54
|
+
"payment_method" => "card",
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
25
59
|
end
|
@@ -7,7 +7,7 @@ RSpec.describe "Order reissuing" do
|
|
7
7
|
mock_digicert_order_reissuer_create_message_chain
|
8
8
|
command = %w(order reissue 123456 --csr ./spec/fixtures/rsa4096.csr)
|
9
9
|
|
10
|
-
Digicert::CLI.start(command)
|
10
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
11
11
|
|
12
12
|
expect(Digicert::CLI::OrderReissuer).to have_received(:new).
|
13
13
|
with(order_id: "123456", csr: "./spec/fixtures/rsa4096.csr")
|
@@ -19,7 +19,7 @@ RSpec.describe "Order reissuing" do
|
|
19
19
|
mock_digicert_order_reissuer_create_message_chain
|
20
20
|
command = %w(order reissue 123456 --output /tmp/downloads)
|
21
21
|
|
22
|
-
Digicert::CLI.start(command)
|
22
|
+
_output = capture_stdout { Digicert::CLI.start(command) }
|
23
23
|
|
24
24
|
expect(Digicert::CLI::OrderReissuer).to have_received(:new).
|
25
25
|
with(order_id: "123456", output: "/tmp/downloads")
|
@@ -29,14 +29,17 @@ RSpec.describe Digicert::CLI::CSR do
|
|
29
29
|
|
30
30
|
context "with custom details" do
|
31
31
|
it "generates a new csr using the provided details" do
|
32
|
-
|
32
|
+
organization_id = 123456
|
33
33
|
common_name = "ribosetest.com"
|
34
34
|
key_file = "./spec/fixtures/rsa4096.key"
|
35
35
|
san = ["site1.ribosetest.com", "site2.ribosetest.com"]
|
36
|
-
|
36
|
+
stub_digicert_organization_fetch_api(organization_id)
|
37
37
|
|
38
38
|
csr = Digicert::CLI::CSR.new(
|
39
|
-
|
39
|
+
san: san,
|
40
|
+
key: key_file,
|
41
|
+
common_name: common_name,
|
42
|
+
organization_id: organization_id,
|
40
43
|
).generate
|
41
44
|
|
42
45
|
expect(csr.start_with?("-----BEGIN CERTIFICATE REQUEST")).to be_truthy
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Digicert::CLI::OrderCreator do
|
4
|
+
describe ".create" do
|
5
|
+
context "with valid order information" do
|
6
|
+
it "creates a new digicert certificate order" do
|
7
|
+
name_id = "ssl_plus"
|
8
|
+
stub_digicert_order_create_api(
|
9
|
+
name_id, rest_order_attributes(order_attributes)
|
10
|
+
)
|
11
|
+
|
12
|
+
order = Digicert::CLI::OrderCreator.create(name_id, order_attributes)
|
13
|
+
|
14
|
+
expect(order.id).not_to be_nil
|
15
|
+
expect(order.requests.first.status).to eq("pending")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def order_attributes
|
21
|
+
@order_attributes ||= {
|
22
|
+
common_name: "ribosetest.com",
|
23
|
+
csr: "./spec/fixtures/rsa4096.csr",
|
24
|
+
signature_hash: "sha512",
|
25
|
+
organization_units: "Developer Units",
|
26
|
+
server_platform_id: "platform_id_101",
|
27
|
+
profile_option: "certificate-profile",
|
28
|
+
organization_id: "organization-id",
|
29
|
+
validity_years: 3,
|
30
|
+
custom_expiration_date: "11-11-2019",
|
31
|
+
comments: "Ordered using digicert CLI",
|
32
|
+
disable_renewal_notifications: false,
|
33
|
+
renewal_of_order_id: 123456,
|
34
|
+
payment_method: "balanace",
|
35
|
+
disable_ct: false,
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def rest_order_attributes(attributes)
|
40
|
+
{
|
41
|
+
certificate: {
|
42
|
+
organization_units: attributes[:organization_units],
|
43
|
+
server_platform: { id: attributes[:server_platform_id] },
|
44
|
+
profile_option: attributes[:profile_option],
|
45
|
+
csr: File.read(attributes[:csr]),
|
46
|
+
common_name: attributes[:common_name],
|
47
|
+
signature_hash: attributes[:signature_hash],
|
48
|
+
},
|
49
|
+
|
50
|
+
organization: { id: attributes[:organization_id] },
|
51
|
+
validity_years: attributes[:validity_years],
|
52
|
+
custom_expiration_date: attributes[:custom_expiration_date],
|
53
|
+
comments: attributes[:comments],
|
54
|
+
disable_renewal_notifications: attributes[:disable_renewal_notifications],
|
55
|
+
renewal_of_order_id: attributes[:renewal_of_order_id],
|
56
|
+
payment_method: attributes[:payment_method],
|
57
|
+
disable_ct: attributes[:disable_ct],
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Digicert::CLI::OrderDuplicator do
|
4
|
+
describe "#create" do
|
5
|
+
context "with a valid order id" do
|
6
|
+
it "sends create message to digicert order duplicator" do
|
7
|
+
order_id = 123_456
|
8
|
+
allow(Digicert::OrderDuplicator).to receive(:create)
|
9
|
+
|
10
|
+
Digicert::CLI::OrderDuplicator.new(order_id: order_id).create
|
11
|
+
|
12
|
+
expect(
|
13
|
+
Digicert::OrderDuplicator,
|
14
|
+
).to have_received(:create).with(order_id: order_id)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with order id and new csr" do
|
19
|
+
it "sends create message to duplicator with new csr" do
|
20
|
+
order_id = 123_456
|
21
|
+
csr_file = "./spec/fixtures/rsa4096.csr"
|
22
|
+
allow(Digicert::OrderDuplicator).to receive(:create)
|
23
|
+
|
24
|
+
Digicert::CLI::OrderDuplicator.new(
|
25
|
+
order_id: order_id, csr: csr_file,
|
26
|
+
).create
|
27
|
+
|
28
|
+
expect(Digicert::OrderDuplicator).to have_received(:create).with(
|
29
|
+
order_id: order_id, csr: File.read(csr_file),
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with order id and --fetch option" do
|
35
|
+
it "duplicates order and fetch the updated order" do
|
36
|
+
order_id = 456_789
|
37
|
+
|
38
|
+
mock_order_fetch_and_download_requests(order)
|
39
|
+
stub_digicert_order_duplicate_api(order_id, order_attributes(order))
|
40
|
+
allow(Digicert::CLI::CertificateDownloader).to receive(:download)
|
41
|
+
|
42
|
+
Digicert::CLI::OrderDuplicator.new(
|
43
|
+
order_id: order_id, output: "/tmp", number_of_times: 1, wait_time: 1,
|
44
|
+
).create
|
45
|
+
|
46
|
+
expect(Digicert::CLI::CertificateDownloader).
|
47
|
+
to have_received(:download).
|
48
|
+
with(hash_including(certificate_id: order.certificate.id))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def order(order_id = 123_456)
|
53
|
+
stub_digicert_order_fetch_api(order_id)
|
54
|
+
@order ||= Digicert::Order.fetch(order_id)
|
55
|
+
end
|
56
|
+
|
57
|
+
def order_attributes(order)
|
58
|
+
{
|
59
|
+
common_name: order.certificate.common_name,
|
60
|
+
dns_names: order.certificate.dns_names,
|
61
|
+
csr: order.certificate.csr,
|
62
|
+
signature_hash: order.certificate.signature_hash,
|
63
|
+
server_platform: { id: 45 },
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def mock_order_fetch_and_download_requests(order)
|
68
|
+
allow(Digicert::Order).to receive(:fetch).and_return(order)
|
69
|
+
|
70
|
+
allow(
|
71
|
+
Digicert::DuplicateCertificateFinder,
|
72
|
+
).to receive(:find_by).and_return(order.certificate)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,7 @@ Dir["./spec/support/**/*.rb"].sort.each { |file| require file }
|
|
7
7
|
RSpec.configure do |config|
|
8
8
|
# Enable flags like --only-failures and --next-failure
|
9
9
|
config.example_status_persistence_file_path = ".rspec_status"
|
10
|
+
config.include Digicert::ConsoleHelper
|
10
11
|
|
11
12
|
config.expect_with :rspec do |c|
|
12
13
|
c.syntax = :expect
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Digicert
|
2
|
+
module ConsoleHelper
|
3
|
+
def capture_stdout(&_block)
|
4
|
+
original_stdout = $stdout
|
5
|
+
$stdout = fake = StringIO.new
|
6
|
+
|
7
|
+
begin
|
8
|
+
yield
|
9
|
+
ensure
|
10
|
+
$stdout = original_stdout
|
11
|
+
end
|
12
|
+
|
13
|
+
fake.string
|
14
|
+
end
|
15
|
+
|
16
|
+
def capture_stderr(&_block)
|
17
|
+
original_stderr = $stderr
|
18
|
+
$stderr = fake = StringIO.new
|
19
|
+
|
20
|
+
begin
|
21
|
+
yield
|
22
|
+
ensure
|
23
|
+
$stderr = original_stderr
|
24
|
+
end
|
25
|
+
|
26
|
+
fake.string
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digicert-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.4.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.4.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: openssl
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '2.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.11.3
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.11.3
|
125
139
|
description: The CLI for digicert API
|
126
140
|
email:
|
127
141
|
- operations@ribose.com
|
@@ -156,6 +170,8 @@ files:
|
|
156
170
|
- lib/digicert/cli/csr.rb
|
157
171
|
- lib/digicert/cli/filter_builder.rb
|
158
172
|
- lib/digicert/cli/order.rb
|
173
|
+
- lib/digicert/cli/order_creator.rb
|
174
|
+
- lib/digicert/cli/order_duplicator.rb
|
159
175
|
- lib/digicert/cli/order_reissuer.rb
|
160
176
|
- lib/digicert/cli/order_retriever.rb
|
161
177
|
- lib/digicert/cli/rcfile.rb
|
@@ -164,12 +180,15 @@ files:
|
|
164
180
|
- spec/acceptance/certificate_spec.rb
|
165
181
|
- spec/acceptance/config_spec.rb
|
166
182
|
- spec/acceptance/csr_spec.rb
|
183
|
+
- spec/acceptance/duplicating_order_spec.rb
|
167
184
|
- spec/acceptance/order_spec.rb
|
168
185
|
- spec/acceptance/reissuing_order_spec.rb
|
169
186
|
- spec/digicert/cli/certificate_downloader_spec.rb
|
170
187
|
- spec/digicert/cli/certificate_spec.rb
|
171
188
|
- spec/digicert/cli/csr_spec.rb
|
172
189
|
- spec/digicert/cli/filter_builder_spec.rb
|
190
|
+
- spec/digicert/cli/order_creator_spec.rb
|
191
|
+
- spec/digicert/cli/order_duplicator_spec.rb
|
173
192
|
- spec/digicert/cli/order_reissuer_spec.rb
|
174
193
|
- spec/digicert/cli/order_retriever_spec.rb
|
175
194
|
- spec/digicert/cli/order_spec.rb
|
@@ -179,6 +198,7 @@ files:
|
|
179
198
|
- spec/fixtures/rsa4096.csr
|
180
199
|
- spec/fixtures/rsa4096.key
|
181
200
|
- spec/spec_helper.rb
|
201
|
+
- spec/support/console_helper.rb
|
182
202
|
- spec/support/disable-logging.rb
|
183
203
|
homepage: https://www.ribose.com
|
184
204
|
licenses: []
|