Skip to content

Commit aae28ca

Browse files
authored
feat: assets-11322. add aio-cli console support for public key rotation (#173)
* feat: assets-11322. add aio-cli console support for public key rotation * calculate cert fingerprint and check for existence before upload * ASSETS-11385 add fingerprint logic to aio-cli-plugin-certificate * ASSETS-11322 complete test coverage * ASSETS-11322 renamed arg for delete command to be more readable * ASSETS-11322 cleaned up help strings * ASSETS-11322 update readme using oclif-dev and fix ts exts to js * ASSETS-11322 simplify publickey command help
1 parent 31fe67f commit aae28ca

16 files changed

Lines changed: 1275 additions & 24 deletions

File tree

README.md

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ $ aio console --help
4444
* [`aio console:project`](#aio-consoleproject)
4545
* [`aio console:project:list`](#aio-consoleprojectlist)
4646
* [`aio console:project:select [PROJECTIDORNAME]`](#aio-consoleprojectselect-projectidorname)
47+
* [`aio console:publickey`](#aio-consolepublickey)
48+
* [`aio console:publickey:delete IDORFINGERPRINT`](#aio-consolepublickeydelete-idorfingerprint)
49+
* [`aio console:publickey:list`](#aio-consolepublickeylist)
50+
* [`aio console:publickey:upload FILE`](#aio-consolepublickeyupload-file)
4751
* [`aio console:where`](#aio-consolewhere)
4852
* [`aio console:workspace`](#aio-consoleworkspace)
4953
* [`aio console:workspace:download [DESTINATION]`](#aio-consoleworkspacedownload-destination)
@@ -55,8 +59,6 @@ $ aio console --help
5559
Console plugin for the Adobe I/O CLI
5660

5761
```
58-
Console plugin for the Adobe I/O CLI
59-
6062
USAGE
6163
$ aio console
6264
@@ -71,8 +73,6 @@ _See code: [src/commands/console/index.js](https://github.com/adobe/aio-cli-plug
7173
Manage your Adobe I/O Console Organizations
7274

7375
```
74-
Manage your Adobe I/O Console Organizations
75-
7676
USAGE
7777
$ aio console:org
7878
@@ -87,8 +87,6 @@ _See code: [src/commands/console/org/index.js](https://github.com/adobe/aio-cli-
8787
List your Organizations
8888

8989
```
90-
List your Organizations
91-
9290
USAGE
9391
$ aio console:org:list
9492
@@ -108,8 +106,6 @@ _See code: [src/commands/console/org/list.js](https://github.com/adobe/aio-cli-p
108106
Select an Organization
109107

110108
```
111-
Select an Organization
112-
113109
USAGE
114110
$ aio console:org:select [ORGCODE]
115111
@@ -130,8 +126,6 @@ _See code: [src/commands/console/org/select.js](https://github.com/adobe/aio-cli
130126
Manage your Adobe I/O Console Projects
131127

132128
```
133-
Manage your Adobe I/O Console Projects
134-
135129
USAGE
136130
$ aio console:project
137131
@@ -146,8 +140,6 @@ _See code: [src/commands/console/project/index.js](https://github.com/adobe/aio-
146140
List your Projects for the selected Organization
147141

148142
```
149-
List your Projects for the selected Organization
150-
151143
USAGE
152144
$ aio console:project:list
153145
@@ -168,8 +160,6 @@ _See code: [src/commands/console/project/list.js](https://github.com/adobe/aio-c
168160
Select a Project for the selected Organization
169161

170162
```
171-
Select a Project for the selected Organization
172-
173163
USAGE
174164
$ aio console:project:select [PROJECTIDORNAME]
175165
@@ -186,13 +176,86 @@ ALIASES
186176

187177
_See code: [src/commands/console/project/select.js](https://github.com/adobe/aio-cli-plugin-console/blob/3.4.2/src/commands/console/project/select.js)_
188178

189-
## `aio console:where`
179+
## `aio console:publickey`
190180

191-
Show the currently selected Organization, Project and Workspace
181+
Manage Public Key Bindings for your Adobe I/O Console Workspaces
182+
183+
```
184+
USAGE
185+
$ aio console:publickey
186+
187+
OPTIONS
188+
--help Show help
189+
```
190+
191+
_See code: [src/commands/console/publickey/index.js](https://github.com/adobe/aio-cli-plugin-console/blob/3.4.2/src/commands/console/publickey/index.js)_
192+
193+
## `aio console:publickey:delete IDORFINGERPRINT`
194+
195+
Delete a public key certificate from the selected Workspace
196+
197+
```
198+
USAGE
199+
$ aio console:publickey:delete IDORFINGERPRINT
200+
201+
ARGUMENTS
202+
IDORFINGERPRINT The bindingId or the fingerprint of the public key binding to delete
203+
204+
OPTIONS
205+
--help Show help
206+
--orgId=orgId Organization id of the Console Workspace to delete the public key certificate from
207+
--projectId=projectId Project id of the Console Workspace to delete the public key certificate from
208+
--workspaceId=workspaceId Workspace id of the Console Workspace to delete the public key certificate from
209+
```
210+
211+
_See code: [src/commands/console/publickey/delete.js](https://github.com/adobe/aio-cli-plugin-console/blob/3.4.2/src/commands/console/publickey/delete.js)_
212+
213+
## `aio console:publickey:list`
214+
215+
List the public key certificates bound to the selected Workspace
216+
217+
```
218+
USAGE
219+
$ aio console:publickey:list
220+
221+
OPTIONS
222+
-j, --json Output json
223+
-y, --yml Output yml
224+
--help Show help
225+
--orgId=orgId Organization id of the Console Workspace to list the public key certificates for
226+
--projectId=projectId Project id of the Console Workspace to list the public key certificate for
227+
--workspaceId=workspaceId Workspace id of the Console Workspace to list the public key certificate for
228+
```
229+
230+
_See code: [src/commands/console/publickey/list.js](https://github.com/adobe/aio-cli-plugin-console/blob/3.4.2/src/commands/console/publickey/list.js)_
231+
232+
## `aio console:publickey:upload FILE`
233+
234+
Upload a public key certificate to the selected Workspace
235+
236+
```
237+
USAGE
238+
$ aio console:publickey:upload FILE
192239
240+
ARGUMENTS
241+
FILE Path to public key certificate file in PEM format
242+
243+
OPTIONS
244+
-j, --json Output json
245+
-y, --yml Output yml
246+
--help Show help
247+
--orgId=orgId Organization id of the Console Workspace to upload the public key certificate to
248+
--projectId=projectId Project id of the Console Workspace to upload the public key certificate to
249+
--workspaceId=workspaceId Workspace id of the Console Workspace to upload the public key certificate to
193250
```
251+
252+
_See code: [src/commands/console/publickey/upload.js](https://github.com/adobe/aio-cli-plugin-console/blob/3.4.2/src/commands/console/publickey/upload.js)_
253+
254+
## `aio console:where`
255+
194256
Show the currently selected Organization, Project and Workspace
195257

258+
```
196259
USAGE
197260
$ aio console:where
198261
@@ -212,8 +275,6 @@ _See code: [src/commands/console/where/index.js](https://github.com/adobe/aio-cl
212275
Manage your Adobe I/O Console Workspaces
213276

214277
```
215-
Manage your Adobe I/O Console Workspaces
216-
217278
USAGE
218279
$ aio console:workspace
219280
@@ -231,8 +292,6 @@ _See code: [src/commands/console/workspace/index.js](https://github.com/adobe/ai
231292
Downloads the configuration for the selected Workspace
232293

233294
```
234-
Downloads the configuration for the selected Workspace
235-
236295
USAGE
237296
$ aio console:workspace:download [DESTINATION]
238297
@@ -258,8 +317,6 @@ _See code: [src/commands/console/workspace/download.js](https://github.com/adobe
258317
List your Workspaces for your selected Project
259318

260319
```
261-
List your Workspaces for your selected Project
262-
263320
USAGE
264321
$ aio console:workspace:list
265322
@@ -283,8 +340,6 @@ _See code: [src/commands/console/workspace/list.js](https://github.com/adobe/aio
283340
Select a Workspace for the selected Project
284341

285342
```
286-
Select a Workspace for the selected Project
287-
288343
USAGE
289344
$ aio console:workspace:select [WORKSPACEIDORNAME]
290345
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Copyright 2022 Adobe Inc. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
Unless required by applicable law or agreed to in writing, software distributed under
7+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8+
OF ANY KIND, either express or implied. See the License for the specific language
9+
governing permissions and limitations under the License.
10+
*/
11+
12+
const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:publickey:list', { provider: 'debug' })
13+
const { flags } = require('@oclif/command')
14+
const { CONFIG_KEYS } = require('../../../config')
15+
const ConsoleCommand = require('../index')
16+
17+
class DeleteCommand extends ConsoleCommand {
18+
async run () {
19+
const { args, flags } = this.parse(DeleteCommand)
20+
21+
const orgId = flags.orgId || this.getConfig(`${CONFIG_KEYS.ORG}.id`)
22+
if (!orgId) {
23+
this.log('You have not selected an Organization. Please select first.')
24+
this.printConsoleConfig()
25+
this.exit(1)
26+
}
27+
28+
const projectId = flags.projectId || this.getConfig(`${CONFIG_KEYS.PROJECT}.id`)
29+
if (!projectId) {
30+
this.log('You have not selected a Project. Please select first.')
31+
this.printConsoleConfig()
32+
this.exit(1)
33+
}
34+
35+
const workspaceId = flags.workspaceId || this.getConfig(`${CONFIG_KEYS.WORKSPACE}.id`)
36+
if (!workspaceId) {
37+
this.log('You have not selected a Workspace. Please select first.')
38+
this.printConsoleConfig()
39+
this.exit(1)
40+
}
41+
await this.initSdk()
42+
43+
try {
44+
const consoleConfig = await this.consoleCLI.getWorkspaceConfig(orgId, projectId, workspaceId)
45+
46+
const project = consoleConfig.project
47+
const workspace = project.workspace
48+
49+
const bindings = await this.consoleCLI.getBindingsForWorkspace(orgId, project, workspace)
50+
51+
const found = bindings.find((value) => value.bindingId === args.idOrFingerprint || value.certificateFingerprint === args.idOrFingerprint)
52+
if (found) {
53+
const deleted = await this.consoleCLI.deleteBindingFromWorkspace(orgId, project, workspace, found)
54+
if (deleted) {
55+
this.log(`Deleted binding ${found.bindingId} from workspace ${workspace.name}`)
56+
} else {
57+
this.error(`Failed to delete binding ${found.bindingId} from workspace ${workspace.name}`)
58+
}
59+
} else {
60+
this.error(`No binding found with bindingId or fingerprint ${args.idOrFingerprint}`)
61+
}
62+
} catch (err) {
63+
aioConsoleLogger.debug(err)
64+
this.error(err.message)
65+
} finally {
66+
this.cleanOutput()
67+
}
68+
}
69+
}
70+
71+
DeleteCommand.description = 'Delete a public key certificate from the selected Workspace'
72+
73+
DeleteCommand.flags = {
74+
...ConsoleCommand.flags,
75+
orgId: flags.string({
76+
description: 'Organization id of the Console Workspace to delete the public key certificate from'
77+
}),
78+
projectId: flags.string({
79+
description: 'Project id of the Console Workspace to delete the public key certificate from'
80+
}),
81+
workspaceId: flags.string({
82+
description: 'Workspace id of the Console Workspace to delete the public key certificate from'
83+
})
84+
}
85+
86+
DeleteCommand.args = [
87+
{
88+
name: 'idOrFingerprint',
89+
required: true,
90+
description: 'The bindingId or the fingerprint of the public key binding to delete'
91+
}
92+
]
93+
94+
DeleteCommand.aliases = []
95+
96+
module.exports = DeleteCommand
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2022 Adobe Inc. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
Unless required by applicable law or agreed to in writing, software distributed under
7+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8+
OF ANY KIND, either express or implied. See the License for the specific language
9+
governing permissions and limitations under the License.
10+
*/
11+
12+
const Help = require('@oclif/plugin-help').default
13+
const ConsoleCommand = require('..')
14+
const { cli } = require('cli-ux')
15+
16+
class IndexCommand extends ConsoleCommand {
17+
async run () {
18+
const help = new Help(this.config)
19+
help.showHelp(['console:publickey', '--help'])
20+
}
21+
}
22+
23+
/**
24+
* Pretty-print a table of public key certificate bindings.
25+
*
26+
* @param {{ bindingId: string,
27+
* orgId: string,
28+
* technicalAccountId: string,
29+
* certificateFingerprint: string,
30+
* notAfter: number }[]} bindings array of bindings results
31+
*/
32+
IndexCommand.printBindings = function (bindings) {
33+
const columns = {
34+
bindingId: {
35+
header: 'ID'
36+
},
37+
certificateFingerprint: {
38+
header: 'Fingerprint'
39+
},
40+
expiresString: {
41+
header: 'Expires'
42+
}
43+
}
44+
const decorateds = []
45+
bindings.forEach(binding => {
46+
const decorated = {}
47+
Object.assign(decorated, binding)
48+
decorated.expiresString = binding.notAfter ? this.formatExpiry(binding.notAfter) : ''
49+
decorateds.push(decorated)
50+
})
51+
cli.table(decorateds, columns)
52+
}
53+
54+
/**
55+
* Format the notAfter field for readability into YYYY-MM-DD. Make result a
56+
* little early by subtracting 1 day before truncating the time fields to
57+
* provide a small grace period to users with time zone differences or time blindness.
58+
*
59+
* @param {number} notAfter GMT epoch in nanoseconds
60+
* @returns {string} readable date
61+
*/
62+
IndexCommand.formatExpiry = function (notAfter) {
63+
const realDate = new Date(notAfter - (24 * 60 * 60 * 1000))
64+
return realDate.toISOString().substring(0, 10)
65+
}
66+
67+
IndexCommand.description = 'Manage Public Key Bindings for your Adobe I/O Console Workspaces'
68+
69+
IndexCommand.aliases = []
70+
71+
module.exports = IndexCommand

0 commit comments

Comments
 (0)