digicert-cli 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound.yml +3 -0
- data/.rubocop.yml +637 -0
- data/.travis.yml +0 -1
- data/Gemfile +0 -2
- data/LICENSE.txt +21 -0
- data/README.md +218 -21
- data/bin/digicert +1 -2
- data/digicert-cli.gemspec +3 -12
- data/lib/digicert/cli.rb +33 -9
- data/lib/digicert/cli/auth.rb +6 -3
- data/lib/digicert/cli/base.rb +19 -0
- data/lib/digicert/cli/certificate.rb +75 -0
- data/lib/digicert/cli/certificate_downloader.rb +51 -0
- data/lib/digicert/cli/command.rb +14 -48
- data/lib/digicert/cli/commands/certificate.rb +37 -0
- data/lib/digicert/cli/commands/csr.rb +31 -0
- data/lib/digicert/cli/commands/order.rb +45 -0
- data/lib/digicert/cli/csr.rb +48 -0
- data/lib/digicert/cli/filter_builder.rb +54 -0
- data/lib/digicert/cli/order.rb +9 -23
- data/lib/digicert/cli/order_reissuer.rb +60 -11
- data/lib/digicert/cli/order_retriever.rb +48 -0
- data/lib/digicert/cli/rcfile.rb +48 -0
- data/lib/digicert/cli/util.rb +5 -1
- data/lib/digicert/cli/version.rb +23 -1
- data/spec/acceptance/certificate_spec.rb +66 -0
- data/spec/acceptance/config_spec.rb +16 -0
- data/spec/acceptance/csr_spec.rb +51 -0
- data/spec/acceptance/order_spec.rb +6 -21
- data/spec/acceptance/reissuing_order_spec.rb +33 -0
- data/spec/digicert/cli/certificate_downloader_spec.rb +30 -0
- data/spec/digicert/cli/certificate_spec.rb +104 -0
- data/spec/digicert/cli/csr_spec.rb +47 -0
- data/spec/digicert/cli/filter_builder_spec.rb +25 -0
- data/spec/digicert/cli/order_reissuer_spec.rb +74 -0
- data/spec/digicert/cli/order_retriever_spec.rb +23 -0
- data/spec/digicert/{order_spec.rb → cli/order_spec.rb} +2 -2
- data/spec/digicert/cli/rcfile_spec.rb +18 -0
- data/spec/digicert/cli_spec.rb +6 -5
- data/spec/fixtures/.digicertrc +2 -0
- data/spec/fixtures/rsa4096.csr +51 -0
- data/spec/fixtures/rsa4096.key +51 -0
- data/spec/spec_helper.rb +8 -1
- data/spec/support/disable-logging.rb +12 -0
- metadata +70 -22
- data/.sample.env +0 -1
- data/bin/console +0 -14
- data/legacy_cli.sh +0 -301
- data/lib/digicert/cli/command/order.rb +0 -50
- data/lib/digicert/cli/order_filterer.rb +0 -43
- data/spec/digicert/command_spec.rb +0 -16
- data/spec/digicert/order_filterer_spec.rb +0 -50
- data/spec/digicert/order_reissuer_spec.rb +0 -19
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Ribose Inc.
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -2,51 +2,245 @@
|
|
2
2
|
|
3
3
|
[![Build
|
4
4
|
Status](https://travis-ci.org/riboseinc/digicert-cli.svg?branch=master)](https://travis-ci.org/riboseinc/digicert-cli)
|
5
|
+
[![Code
|
6
|
+
Climate](https://codeclimate.com/github/riboseinc/digicert-cli/badges/gpa.svg)](https://codeclimate.com/github/riboseinc/digicert-cli)
|
7
|
+
[![Gem
|
8
|
+
Version](https://badge.fury.io/rb/digicert-cli.svg)](https://badge.fury.io/rb/digicert-cli)
|
5
9
|
|
6
|
-
The CLI
|
10
|
+
The [Digicert CLI] is a tool that allows us to manage Digicert orders,
|
11
|
+
certificates and etc using [Digicert Ruby Client].
|
12
|
+
|
13
|
+
## Configure
|
14
|
+
|
15
|
+
We need to setup our API key before we want to use the CLI. For simplicity we
|
16
|
+
have add an easier interface to setup the Digicert API KEY. To setup your key
|
17
|
+
please use the following interface.
|
18
|
+
|
19
|
+
```sh
|
20
|
+
digicert config DIGICERT_API_KEY
|
21
|
+
```
|
7
22
|
|
8
23
|
## Usages
|
9
24
|
|
25
|
+
### Getting Help
|
26
|
+
|
27
|
+
We have been trying to simplify the `CLI` with proper `help` documentation. Each
|
28
|
+
of the `command` and `subcommand` should provide you the basic usages guide with
|
29
|
+
the list of supported options.
|
30
|
+
|
31
|
+
Normally the parent command should fire up the `help` documentation, but if it
|
32
|
+
does not then you can explicitly call the `help` command or pass `-h` flags with
|
33
|
+
any of the action and that should fire up the documentation. For example
|
34
|
+
|
35
|
+
```sh
|
36
|
+
$ digicert help
|
37
|
+
```
|
38
|
+
|
39
|
+
```sh
|
40
|
+
Commands:
|
41
|
+
digicert certificate # Manage Digicert Certificates
|
42
|
+
digicert config API_KEY # Configure The CLI Client
|
43
|
+
digicert csr # Fetch/generate Certificate CSR
|
44
|
+
digicert help [COMMAND] # Describe available / One specific command
|
45
|
+
digicert order # Manage Digicert Orders
|
46
|
+
```
|
47
|
+
|
48
|
+
The above command lists the available commands with a basic description and as
|
49
|
+
you might have notice, it also ships with a `help` command which can be used to
|
50
|
+
up the usages documentation for it's nested command.
|
51
|
+
|
52
|
+
```sh
|
53
|
+
# digicert order -h
|
54
|
+
$ digicert help order
|
55
|
+
```
|
56
|
+
|
57
|
+
```sh
|
58
|
+
Commands:
|
59
|
+
digicert order find # Find a digicert order
|
60
|
+
digicert order help [COMMAND] # Describe subcommands or one specific
|
61
|
+
digicert order list # List digicert orders
|
62
|
+
digicert order reissue ORDER_ID # Reissue digicert order
|
63
|
+
```
|
64
|
+
|
65
|
+
Hopefully you get the idea, we will try our best to keep this guide up to date
|
66
|
+
but whenever you need some more information please add the `-h` flags with any
|
67
|
+
commands or subcommands and you should see what you need.
|
68
|
+
|
10
69
|
### Orders
|
11
70
|
|
12
|
-
|
13
|
-
|
71
|
+
#### Listing Orders
|
72
|
+
|
73
|
+
Listing orders is pretty simple with the CLI, once we have our API key
|
74
|
+
configured then we can list all of our orders using the `list` interface
|
75
|
+
|
76
|
+
```sh
|
77
|
+
$ digicert order list
|
78
|
+
```
|
14
79
|
|
15
80
|
```sh
|
16
|
-
|
81
|
+
+---------------+---------------+------------------+-------------+-------------+
|
82
|
+
| Id | Product Type | Common Name | Status | Expiry |
|
83
|
+
+---------------+---------------+------------------+-------------+-------------+
|
84
|
+
| xxxxx65 | ssl_wildcard | *.ribosetest.com | expired | 2018-06-25 |
|
85
|
+
| xxxxx20 | ssl_wildcard | *.ribosetest.com | issued | 2018-06-15 |
|
86
|
+
| xxxxx06 | ssl_wildcard | *.ribosetest.com | revoked | 2018-05-09 |
|
87
|
+
+---------------+---------------+------------------+-------------+-------------+
|
17
88
|
```
|
18
89
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
90
|
+
The above interface without any option will list out all of the orders we have
|
91
|
+
with Digicert, but sometime we might need to filter those listings, and that's
|
92
|
+
where can can use the filter options. This interface supports filter options
|
93
|
+
through the `--filter` option and expect the value to be in `key:value` format.
|
94
|
+
|
95
|
+
For example, if we want to retrieve all of the orders that has product type of
|
96
|
+
`ssl_wildcard` then we can use
|
23
97
|
|
24
98
|
```sh
|
25
|
-
digicert order list
|
99
|
+
$ digicert order list --filter 'product_name_id:ssl_wildcard'
|
26
100
|
```
|
27
101
|
|
28
|
-
|
102
|
+
It will only list the orders with the `ssl_wildcard` product type, Currently the
|
103
|
+
supported filters options are `date_created`, `valid_till`, `status`, `search`,
|
104
|
+
`common_name` and `product_name_id`. Please [check the wiki] for more up to date
|
105
|
+
supported filtering options.
|
106
|
+
|
107
|
+
#### Find an order
|
108
|
+
|
109
|
+
We can use the `find` interface to retrieve a single order, by default it will
|
110
|
+
print the details in the console. This interface also supports filter options.
|
111
|
+
|
112
|
+
One important thing to remember, it will only retrieve one single entry, so if
|
113
|
+
you have multiple orders in your specified terms then it will only retrieve the
|
114
|
+
most recent one form that list.
|
29
115
|
|
30
|
-
|
31
|
-
|
116
|
+
```sh
|
117
|
+
$ digicert order find --filter 'common_name:ribosetest.com' 'product_name_id:ssl_plus'
|
118
|
+
```
|
32
119
|
|
33
120
|
```sh
|
34
|
-
|
121
|
+
#<Digicert::ResponseObject id=xxx04, certificate=#<Digicert::ResponseObject
|
122
|
+
..........................id=xxxx08 price=xxxx, product_name_id="ssl_plus">
|
35
123
|
```
|
36
124
|
|
37
|
-
|
38
|
-
the `
|
125
|
+
But if you don't care about that much of data and only need the `ID` then you
|
126
|
+
can pass the `--quiet` flags to reduce the noises and retrieve only the id.
|
127
|
+
|
128
|
+
#### Reissue an order
|
129
|
+
|
130
|
+
To reissue a non-expired order we can use the `reissue` interface and pass the
|
131
|
+
order id to it. By default it will reissue the order using the existing details
|
132
|
+
but if we want to update the `CSR` then we can pass the certificate file as
|
133
|
+
`--crt`.
|
134
|
+
|
135
|
+
```sh
|
136
|
+
$ digicert order reissue 12345 --crt path_to_the_new_csr.csr
|
137
|
+
```
|
39
138
|
|
40
139
|
```sh
|
41
|
-
|
140
|
+
Reissue request xxxxx8 created for order - 123456
|
42
141
|
```
|
43
142
|
|
44
|
-
|
143
|
+
Pretty cool right? The above interface also support some other option that we
|
144
|
+
can use to download the recently reissued order. To download, all we need to do
|
145
|
+
is just provide a valid path and it will automatically download the certificates
|
146
|
+
|
147
|
+
```sh
|
148
|
+
$ digicert order reissue 123456 --output /path/to/downloads
|
149
|
+
```
|
150
|
+
|
151
|
+
```sh
|
152
|
+
Reissue request 1xxxxx created for order - 123456
|
153
|
+
|
154
|
+
Fetch attempt 1..
|
155
|
+
Downloaded certificate to:
|
156
|
+
|
157
|
+
/path/to/downloads/123456.root.crt
|
158
|
+
/path/to/downloads/123456.certificate.crt
|
159
|
+
/path/to/downloads/123456.intermediate.crt
|
160
|
+
```
|
161
|
+
|
162
|
+
### Certificate
|
163
|
+
|
164
|
+
#### Fetch a certificate
|
165
|
+
|
166
|
+
The `fetch` interface will retrieve the certificate for any specific orders, by
|
167
|
+
default it will print out the detail in the console but if we only want the `ID`
|
168
|
+
then we can pass the `--quiet` flags with it.
|
169
|
+
|
170
|
+
```sh
|
171
|
+
$ digicert certificate fetch 123456789 --quiet
|
172
|
+
```
|
173
|
+
|
174
|
+
#### Download a certificate
|
175
|
+
|
176
|
+
To download a certificate we can use the same `fetch` interface but with the
|
177
|
+
`--output` option. Based on the `--output` option `fetch` interface will fetch
|
178
|
+
the certificates and download the `root`, `intermediate` and `certificate` to
|
179
|
+
the output path, to download a certificate we can do
|
180
|
+
|
181
|
+
```sh
|
182
|
+
$ digicert certificate fetch 123456 --output /path/to/downloads
|
183
|
+
```
|
184
|
+
|
185
|
+
The above interface supports downloading a certificate and it expects us to
|
186
|
+
provide the `order-id`, but if we only care about download then we can also use
|
187
|
+
the `download` interface. It acts pretty much similar but it let's us specify
|
188
|
+
the `order-id` or `certificate-id`.
|
189
|
+
|
190
|
+
```sh
|
191
|
+
$ digicert certificate download --order-id 654321 --output /downloads
|
192
|
+
$ digicert certificate download --certificate-id 123456 --output /downloads
|
193
|
+
```
|
194
|
+
|
195
|
+
#### List duplicate certificates
|
196
|
+
|
197
|
+
Digicert allows us to duplicate a certificate and if we want to list all of the
|
198
|
+
duplicates then we can use the `duplicates` interface. This interface expects us
|
199
|
+
to provide the `order-id` to list the duplicates
|
200
|
+
|
201
|
+
```sh
|
202
|
+
$ digicert certificate duplicates 123456
|
203
|
+
```
|
204
|
+
|
205
|
+
```sh
|
206
|
+
+----------+-------------------+------------------+----------+--------------+
|
207
|
+
| Id | Common Name | SAN Names | Status | Validity |
|
208
|
+
+----------+-------------------+------------------+----------+--------------+
|
209
|
+
| xxxxx19 | *.ribosetest.com | *.ribosetest.com | approved | xxxxx-xxxxxx |
|
210
|
+
| | | ribosetest.com | | |
|
211
|
+
+----------+-------------------+------------------+----------+--------------+
|
212
|
+
```
|
213
|
+
|
214
|
+
### CSR
|
215
|
+
|
216
|
+
#### Fetch an order's CSR
|
217
|
+
|
218
|
+
Retrieving a `CSR` is pretty easy, if we have an order id and we want retrieve
|
219
|
+
it's `CSR` then we can use the `fetch` interface from `csr` command. And once we
|
220
|
+
passed it to the interface then it will retrieve and print it to the console.
|
221
|
+
|
222
|
+
```sh
|
223
|
+
$ digicert csr fetch 123456
|
224
|
+
```
|
225
|
+
|
226
|
+
#### Generate a new CSR
|
227
|
+
|
228
|
+
Digicert gem usages a third party library to generate a CSR, and we have also
|
229
|
+
included that in the CLI to make the `CSR` generation process simpler, so if we
|
230
|
+
need to generate a new `CSR` then we can use the `generate` interface and pass
|
231
|
+
the order id with the key file to generate the CSR
|
232
|
+
|
233
|
+
```sh
|
234
|
+
$ digicert csr generate --oreder-id 12345 --key /path/to/the/key-file.key
|
235
|
+
```
|
45
236
|
|
46
|
-
|
237
|
+
This interface also support custom details like `common-name` and `san`. We can
|
238
|
+
pass those as `--common-name` and `--san` and it will automatically use it to
|
239
|
+
generate the new `CSR`
|
47
240
|
|
48
241
|
```sh
|
49
|
-
digicert
|
242
|
+
$ digicert csr generate --common-name ribosetest.com --order-id 1234 \
|
243
|
+
--san test1.ribosetest.com test2.ribosetest.com --key path_to_key_file
|
50
244
|
```
|
51
245
|
|
52
246
|
## Development
|
@@ -61,7 +255,7 @@ should fix the violations as part of your contribution.
|
|
61
255
|
Clone the repository.
|
62
256
|
|
63
257
|
```sh
|
64
|
-
git clone https://github.com/
|
258
|
+
git clone https://github.com/riboseinc/digicert-cli
|
65
259
|
```
|
66
260
|
|
67
261
|
Setup your environment.
|
@@ -99,6 +293,9 @@ Here are a few technical guidelines to follow:
|
|
99
293
|
This gem is developed, maintained and funded by [Ribose Inc.][riboseinc]
|
100
294
|
|
101
295
|
[riboseinc]: https://www.ribose.com
|
102
|
-
[issues]: https://github.com/
|
296
|
+
[issues]: https://github.com/riboseinc/digicert-cli/issues
|
103
297
|
[squash]: https://github.com/thoughtbot/guides/tree/master/protocol/git#write-a-feature
|
104
298
|
[sandi-metz]: http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers
|
299
|
+
[Digicert CLI]: https://github.com/riboseinc/digicert-cli
|
300
|
+
[Digicert Ruby Client]: https://github.com/riboseinc/digicert
|
301
|
+
[check the wiki]: https://github.com/riboseinc/digicert-cli/wiki
|
data/bin/digicert
CHANGED
data/digicert-cli.gemspec
CHANGED
@@ -20,21 +20,12 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.bindir = "bin"
|
21
21
|
spec.executables = "digicert"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
# and we might not instantly push the digicert gems to rubygems while
|
27
|
-
# we are adding any new features. So let's use the one from our github
|
28
|
-
# and once we are close to finalize then we will switch to the actual
|
29
|
-
# digicert gem from rubygems.
|
30
|
-
#
|
31
|
-
# spec.add_dependency "digicert", "~> 0.1.1"
|
32
|
-
#
|
33
|
-
|
23
|
+
spec.add_dependency "thor", "~> 0.19.4"
|
24
|
+
spec.add_dependency "digicert", "~> 0.1.2"
|
25
|
+
spec.add_dependency "openssl", ">= 2.0.3"
|
34
26
|
spec.add_dependency "terminal-table"
|
35
27
|
|
36
28
|
spec.add_development_dependency "bundler", "~> 1.14"
|
37
|
-
spec.add_development_dependency "dotenv"
|
38
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
39
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
40
31
|
spec.add_development_dependency "webmock", "~> 2.0"
|
data/lib/digicert/cli.rb
CHANGED
@@ -1,20 +1,44 @@
|
|
1
|
-
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2017 Ribose Inc.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
# ++
|
22
|
+
|
23
|
+
require "thor"
|
24
|
+
require "openssl"
|
2
25
|
require "digicert"
|
3
26
|
|
4
27
|
require "digicert/cli/util"
|
5
28
|
require "digicert/cli/auth"
|
29
|
+
require "digicert/cli/base"
|
6
30
|
require "digicert/cli/command"
|
7
31
|
|
8
32
|
module Digicert
|
9
33
|
module CLI
|
10
|
-
def self.start(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
34
|
+
def self.start(arguments)
|
35
|
+
Digicert::CLI::Command.start(arguments)
|
36
|
+
rescue Digicert::Errors::Forbidden, NoMethodError
|
37
|
+
Thor::Shell::Basic.new.say(
|
38
|
+
"Invalid: Missing API KEY\n\n" \
|
39
|
+
"A valid Digicert API key is required for any of the CLI operation\n" \
|
40
|
+
"You can set your API Key using `digicert config DIGICERT_API_KEY`",
|
41
|
+
)
|
18
42
|
end
|
19
43
|
end
|
20
44
|
end
|
data/lib/digicert/cli/auth.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
require "
|
1
|
+
require "digicert"
|
2
|
+
require "digicert/cli/rcfile"
|
2
3
|
|
3
|
-
Digicert.
|
4
|
-
|
4
|
+
unless Digicert.configuration.api_key
|
5
|
+
Digicert.configure do |config|
|
6
|
+
config.api_key = Digicert::CLI::RCFile.api_key || ENV["DIGICERT_API_KEY"]
|
7
|
+
end
|
5
8
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Digicert
|
2
|
+
module CLI
|
3
|
+
class Base
|
4
|
+
attr_reader :order_id, :options
|
5
|
+
|
6
|
+
def initialize(attributes = {})
|
7
|
+
@options = attributes
|
8
|
+
@order_id = options.delete(:order_id)
|
9
|
+
|
10
|
+
extract_local_attributes(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def extract_local_attributes(options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Digicert
|
2
|
+
module CLI
|
3
|
+
class Certificate < Digicert::CLI::Base
|
4
|
+
def fetch
|
5
|
+
apply_option_flags(order.certificate)
|
6
|
+
end
|
7
|
+
|
8
|
+
def duplicates
|
9
|
+
if order_id && duplicate_certificates
|
10
|
+
display_in_table(duplicate_certificates)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def download
|
15
|
+
download_certificate(certificate_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :output_path
|
21
|
+
|
22
|
+
def extract_local_attributes(options)
|
23
|
+
@output_path = options.fetch(:output, nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
def order
|
27
|
+
@order ||= Digicert::Order.fetch(order_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
def certificate_id
|
31
|
+
@certificate_id ||= options[:certificate_id] || order.certificate.id
|
32
|
+
end
|
33
|
+
|
34
|
+
def duplicate_certificates
|
35
|
+
@certificates ||= Digicert::DuplicateCertificate.all(order_id: order_id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def apply_option_flags(certificate)
|
39
|
+
download_certificate(certificate.id) || apply_output_flag(certificate)
|
40
|
+
end
|
41
|
+
|
42
|
+
def download_certificate(certificate_id)
|
43
|
+
if output_path
|
44
|
+
Digicert::CLI::CertificateDownloader.download(
|
45
|
+
path: output_path,
|
46
|
+
certificate_id: certificate_id,
|
47
|
+
filename: order_id || certificate_id,
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def apply_output_flag(certificate)
|
53
|
+
options[:quiet] ? certificate.id : certificate
|
54
|
+
end
|
55
|
+
|
56
|
+
def display_in_table(certificates)
|
57
|
+
certificates_attributes = certificates.map do |certificate|
|
58
|
+
[
|
59
|
+
certificate.id,
|
60
|
+
certificate.common_name,
|
61
|
+
certificate.dns_names.join("\n"),
|
62
|
+
certificate.status,
|
63
|
+
[certificate.valid_from, certificate.valid_till].join(" - "),
|
64
|
+
]
|
65
|
+
end
|
66
|
+
|
67
|
+
Digicert::CLI::Util.make_it_pretty(
|
68
|
+
table_wdith: 100,
|
69
|
+
rows: certificates_attributes,
|
70
|
+
headings: ["Id", "Common Name", "SAN Names", "Status", "Validity"],
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|