-
Notifications
You must be signed in to change notification settings - Fork 36
CR-19944 -- assign and unassign sys re #841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,18 @@ | ||
const Command = require('../../Command'); | ||
|
||
const assign = new Command({ | ||
root: true, | ||
command: 'assign', | ||
description: 'Assign a resource', | ||
usage: 'codefresh assign --help', | ||
webDocs: { | ||
title: 'Assign', | ||
weight: 70, | ||
}, | ||
builder: (yargs) => { | ||
return yargs | ||
.demandCommand(1, 'You need at least one command before moving on'); | ||
}, | ||
}); | ||
|
||
module.exports = assign; |
This file contains hidden or 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,18 @@ | ||
const Command = require('../../Command'); | ||
|
||
const unassign = new Command({ | ||
root: true, | ||
command: 'unassign', | ||
description: 'Unassign a resource', | ||
usage: 'codefresh assign --help', | ||
webDocs: { | ||
title: 'Unassign', | ||
weight: 70, | ||
}, | ||
builder: (yargs) => { | ||
return yargs | ||
.demandCommand(1, 'You need at least one command before moving on'); | ||
}, | ||
}); | ||
|
||
module.exports = unassign; |
This file contains hidden or 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
51 changes: 51 additions & 0 deletions
51
lib/interface/cli/commands/systemRuntimeEnvironments/assign.cmd.js
This file contains hidden or 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,51 @@ | ||
const CFError = require('cf-errors'); | ||
const _ = require('lodash'); | ||
const Command = require('../../Command'); | ||
const assignRoot = require('../root/assign.cmd'); | ||
const { crudFilenameOption } = require('../../helpers/general'); | ||
const { sdk } = require('../../../../logic'); | ||
|
||
const command = new Command({ | ||
command: 'system-runtime-environments <name> <accounts..>', | ||
aliases: ['sys-re', 'system-runtime-environment'], | ||
parent: assignRoot, | ||
description: 'Assign system-runtime-environments to accounts', | ||
onPremCommand: true, | ||
usage: 'Use assign to add runtime environments to accounts by their name or id', | ||
webDocs: { | ||
title: 'Assign System Runtime-Environments', | ||
weight: 90, | ||
}, | ||
builder: (yargs) => { | ||
crudFilenameOption(yargs); | ||
return yargs | ||
.positional('name', { | ||
describe: 'Runtime environments name', | ||
required: true, | ||
}) | ||
.positional('accounts', { | ||
describe: 'Accounts names', | ||
type: Array, | ||
required: true, | ||
}) | ||
.example( | ||
'codefresh assign sys-re my-sys-re acc1 acc2', | ||
'Add system runtime enviroment "my-sys-re" to accounts acc1 and acc2' , | ||
); | ||
}, | ||
handler: async (argv) => { | ||
const { name, accounts: accountsNames } = argv; | ||
const accounts = await sdk.accounts.listAccounts({ name: accountsNames }); | ||
const nonExistentAccounts = _.difference(accountsNames, accounts.map((a) => a.name)); | ||
if (!_.isEmpty(nonExistentAccounts)) { | ||
throw new CFError({ | ||
message: `Accounts do not exist: ${nonExistentAccounts}`, | ||
}); | ||
} | ||
const accountIds = accounts.map((a) => a.id); | ||
await sdk.onPrem.runtimeEnvs.account.modify({ name }, { accounts: accountIds }); | ||
console.log(`Successfully assigned "${name}" to accounts: ${accountsNames}`); | ||
}, | ||
}); | ||
|
||
module.exports = command; |
51 changes: 51 additions & 0 deletions
51
lib/interface/cli/commands/systemRuntimeEnvironments/unassign.cmd.js
This file contains hidden or 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,51 @@ | ||
const CFError = require('cf-errors'); | ||
const _ = require('lodash'); | ||
const Command = require('../../Command'); | ||
const unassignRoot = require('../root/unassign.cmd'); | ||
const { crudFilenameOption } = require('../../helpers/general'); | ||
const { sdk } = require('../../../../logic'); | ||
|
||
const command = new Command({ | ||
command: 'system-runtime-environments <name> <accounts..>', | ||
aliases: ['sys-re', 'system-runtime-environment'], | ||
parent: unassignRoot, | ||
description: 'Unassign system-runtime-environments from accounts', | ||
onPremCommand: true, | ||
usage: 'Use unassign to remove runtime environments from accounts by their name or id', | ||
webDocs: { | ||
title: 'Unassign System Runtime-Environments', | ||
weight: 90, | ||
}, | ||
builder: (yargs) => { | ||
crudFilenameOption(yargs); | ||
return yargs | ||
.positional('name', { | ||
describe: 'Runtime environment name', | ||
required: true, | ||
}) | ||
.positional('accounts', { | ||
describe: 'Accounts names', | ||
type: Array, | ||
required: true, | ||
}) | ||
.example( | ||
'codefresh unassign sys-re my-sys-re acc1 acc2', | ||
'Remove system runtime enviroment "my-sys-re" from accounts acc1 and acc2', | ||
); | ||
}, | ||
handler: async (argv) => { | ||
const { name, accounts: accountsNames } = argv; | ||
const accounts = await sdk.accounts.listAccounts({ name: accountsNames }); | ||
const nonExistentAccounts = _.difference(accountsNames, accounts.map((a) => a.name)); | ||
if (!_.isEmpty(nonExistentAccounts)) { | ||
throw new CFError({ | ||
message: `Accounts do not exist: ${nonExistentAccounts}`, | ||
}); | ||
} | ||
const accountIds = accounts.map((a) => a.id); | ||
await sdk.onPrem.runtimeEnvs.account.delete({ name }, { accounts: accountIds }); | ||
console.log(`Successfully removed "${name}" from accounts: ${accountsNames}`); | ||
}, | ||
}); | ||
|
||
module.exports = command; |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.