-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: assets-11322. add aio-cli console support for public key rotati…
…on (#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
- Loading branch information
Showing
16 changed files
with
1,275 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Copyright 2022 Adobe Inc. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:publickey:list', { provider: 'debug' }) | ||
const { flags } = require('@oclif/command') | ||
const { CONFIG_KEYS } = require('../../../config') | ||
const ConsoleCommand = require('../index') | ||
|
||
class DeleteCommand extends ConsoleCommand { | ||
async run () { | ||
const { args, flags } = this.parse(DeleteCommand) | ||
|
||
const orgId = flags.orgId || this.getConfig(`${CONFIG_KEYS.ORG}.id`) | ||
if (!orgId) { | ||
this.log('You have not selected an Organization. Please select first.') | ||
this.printConsoleConfig() | ||
this.exit(1) | ||
} | ||
|
||
const projectId = flags.projectId || this.getConfig(`${CONFIG_KEYS.PROJECT}.id`) | ||
if (!projectId) { | ||
this.log('You have not selected a Project. Please select first.') | ||
this.printConsoleConfig() | ||
this.exit(1) | ||
} | ||
|
||
const workspaceId = flags.workspaceId || this.getConfig(`${CONFIG_KEYS.WORKSPACE}.id`) | ||
if (!workspaceId) { | ||
this.log('You have not selected a Workspace. Please select first.') | ||
this.printConsoleConfig() | ||
this.exit(1) | ||
} | ||
await this.initSdk() | ||
|
||
try { | ||
const consoleConfig = await this.consoleCLI.getWorkspaceConfig(orgId, projectId, workspaceId) | ||
|
||
const project = consoleConfig.project | ||
const workspace = project.workspace | ||
|
||
const bindings = await this.consoleCLI.getBindingsForWorkspace(orgId, project, workspace) | ||
|
||
const found = bindings.find((value) => value.bindingId === args.idOrFingerprint || value.certificateFingerprint === args.idOrFingerprint) | ||
if (found) { | ||
const deleted = await this.consoleCLI.deleteBindingFromWorkspace(orgId, project, workspace, found) | ||
if (deleted) { | ||
this.log(`Deleted binding ${found.bindingId} from workspace ${workspace.name}`) | ||
} else { | ||
this.error(`Failed to delete binding ${found.bindingId} from workspace ${workspace.name}`) | ||
} | ||
} else { | ||
this.error(`No binding found with bindingId or fingerprint ${args.idOrFingerprint}`) | ||
} | ||
} catch (err) { | ||
aioConsoleLogger.debug(err) | ||
this.error(err.message) | ||
} finally { | ||
this.cleanOutput() | ||
} | ||
} | ||
} | ||
|
||
DeleteCommand.description = 'Delete a public key certificate from the selected Workspace' | ||
|
||
DeleteCommand.flags = { | ||
...ConsoleCommand.flags, | ||
orgId: flags.string({ | ||
description: 'Organization id of the Console Workspace to delete the public key certificate from' | ||
}), | ||
projectId: flags.string({ | ||
description: 'Project id of the Console Workspace to delete the public key certificate from' | ||
}), | ||
workspaceId: flags.string({ | ||
description: 'Workspace id of the Console Workspace to delete the public key certificate from' | ||
}) | ||
} | ||
|
||
DeleteCommand.args = [ | ||
{ | ||
name: 'idOrFingerprint', | ||
required: true, | ||
description: 'The bindingId or the fingerprint of the public key binding to delete' | ||
} | ||
] | ||
|
||
DeleteCommand.aliases = [] | ||
|
||
module.exports = DeleteCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright 2022 Adobe Inc. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
const Help = require('@oclif/plugin-help').default | ||
const ConsoleCommand = require('..') | ||
const { cli } = require('cli-ux') | ||
|
||
class IndexCommand extends ConsoleCommand { | ||
async run () { | ||
const help = new Help(this.config) | ||
help.showHelp(['console:publickey', '--help']) | ||
} | ||
} | ||
|
||
/** | ||
* Pretty-print a table of public key certificate bindings. | ||
* | ||
* @param {{ bindingId: string, | ||
* orgId: string, | ||
* technicalAccountId: string, | ||
* certificateFingerprint: string, | ||
* notAfter: number }[]} bindings array of bindings results | ||
*/ | ||
IndexCommand.printBindings = function (bindings) { | ||
const columns = { | ||
bindingId: { | ||
header: 'ID' | ||
}, | ||
certificateFingerprint: { | ||
header: 'Fingerprint' | ||
}, | ||
expiresString: { | ||
header: 'Expires' | ||
} | ||
} | ||
const decorateds = [] | ||
bindings.forEach(binding => { | ||
const decorated = {} | ||
Object.assign(decorated, binding) | ||
decorated.expiresString = binding.notAfter ? this.formatExpiry(binding.notAfter) : '' | ||
decorateds.push(decorated) | ||
}) | ||
cli.table(decorateds, columns) | ||
} | ||
|
||
/** | ||
* Format the notAfter field for readability into YYYY-MM-DD. Make result a | ||
* little early by subtracting 1 day before truncating the time fields to | ||
* provide a small grace period to users with time zone differences or time blindness. | ||
* | ||
* @param {number} notAfter GMT epoch in nanoseconds | ||
* @returns {string} readable date | ||
*/ | ||
IndexCommand.formatExpiry = function (notAfter) { | ||
const realDate = new Date(notAfter - (24 * 60 * 60 * 1000)) | ||
return realDate.toISOString().substring(0, 10) | ||
} | ||
|
||
IndexCommand.description = 'Manage Public Key Bindings for your Adobe I/O Console Workspaces' | ||
|
||
IndexCommand.aliases = [] | ||
|
||
module.exports = IndexCommand |
Oops, something went wrong.