Skip to content
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

Add/delete service commands and app use enhancements #368

Merged
merged 49 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f34acb4
Support for Prroject and Workspace creation on init
moritzraho Nov 5, 2020
d49270f
Support adding services on init
moritzraho Dec 17, 2020
2faa363
tests + error handling fix
moritzraho Dec 22, 2020
fb8e01b
revert error handling change - avoid breaking change
moritzraho Dec 22, 2020
4adfede
Support for Prroject and Workspace creation on init
moritzraho Nov 5, 2020
7eb4c5e
ongoing
moritzraho Jan 6, 2021
c469f57
add child cert folder
moritzraho Jan 6, 2021
36d7efe
first draft for add command
moritzraho Jan 6, 2021
ce6fb5b
Merge branch 'master' into support-console-add-services
moritzraho Jan 8, 2021
7b3a333
Merge branch 'support-console-add-services' into add-service-cmd
moritzraho Jan 12, 2021
dbfdcfc
Merge branch 'master' into add-service-cmd
moritzraho Jan 12, 2021
b2416d3
Merge branch 'support-console-add-services' into add-service-cmd
moritzraho Jan 12, 2021
219a554
add/delete cmd wip
moritzraho Jan 12, 2021
d4ce743
add missing changes
moritzraho Jan 12, 2021
574e204
fix erroneous change
moritzraho Jan 12, 2021
3247e97
missing header
moritzraho Jan 12, 2021
59e7312
prompt for delete services
moritzraho Jan 19, 2021
5eba4a6
on-going tests
moritzraho Jan 20, 2021
e35a6ff
save
moritzraho Jan 20, 2021
ae52b8f
delete tests
moritzraho Jan 20, 2021
6385c7c
tests for add/delete services
moritzraho Jan 20, 2021
028cef8
Merge branch 'master' into add-service-cmd
moritzraho Jan 21, 2021
5993828
fix weird chdir mock bug
moritzraho Jan 21, 2021
c1be63e
coverage fix
moritzraho Jan 21, 2021
67ae185
Merge branch 'master' into add-service-cmd
shazron Jan 22, 2021
4f9c3e3
bump
moritzraho Jan 22, 2021
3d94143
Merge branch 'master' into add-service-cmd
moritzraho Jan 22, 2021
81e940c
bump generator to fix tests
moritzraho Jan 22, 2021
6c66dc4
fix eslint
moritzraho Jan 22, 2021
f482b70
on going app use
moritzraho Jan 26, 2021
cb221ba
first version, support for service sync
moritzraho Jan 27, 2021
3dbb3ff
100% coverage
moritzraho Jan 28, 2021
24df5ae
Merge branch 'master' into app-use-enhancement
moritzraho Jan 28, 2021
aba8ad1
EOL on final log
moritzraho Jan 28, 2021
eec5e9d
Merge branch 'app-use-enhancement' of github.com:moritzraho/aio-cli-p…
moritzraho Jan 28, 2021
d5cf58b
attempt to fix win node 14 gh actioni
moritzraho Feb 1, 2021
370aa5f
rm uneeded test to fix gh actions
moritzraho Feb 1, 2021
ba6e79c
increase timieout to fix win tests
moritzraho Feb 1, 2021
0dd4c29
Fix messaging
moritzraho Feb 1, 2021
ac27bf5
fix production wkspce warning
moritzraho Feb 1, 2021
f070b42
add production wkspace warning to add/delete services + fixes to dele…
moritzraho Feb 2, 2021
205f159
Merge branch 'master' into app-use-enhancement
moritzraho Feb 2, 2021
9f9630b
fix local config services update
moritzraho Feb 2, 2021
4a5e589
fix some tests + change flags for app use
moritzraho Feb 2, 2021
3872ec6
npm run prepack
moritzraho Feb 2, 2021
cff1457
some little refactoriing
moritzraho Feb 3, 2021
d0098e1
resolve all
moritzraho Feb 3, 2021
b08db05
last wording
moritzraho Feb 3, 2021
2edbc03
fix last wording
moritzraho Feb 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 74 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ $ aio app --help
* [`aio app:add:action`](#aio-appaddaction)
* [`aio app:add:ci`](#aio-appaddci)
* [`aio app:add:event`](#aio-appaddevent)
* [`aio app:add:service`](#aio-appaddservice)
* [`aio app:add:web-assets`](#aio-appaddweb-assets)
* [`aio app:build`](#aio-appbuild)
* [`aio app:create [PATH]`](#aio-appcreate-path)
* [`aio app:delete`](#aio-appdelete)
* [`aio app:delete:action [ACTION-NAME]`](#aio-appdeleteaction-action-name)
* [`aio app:delete:ci`](#aio-appdeleteci)
* [`aio app:delete:event EVENT-ACTION-NAME`](#aio-appdeleteevent-event-action-name)
* [`aio app:delete:service`](#aio-appdeleteservice)
* [`aio app:delete:web-assets`](#aio-appdeleteweb-assets)
* [`aio app:deploy`](#aio-appdeploy)
* [`aio app:get-url [ACTION]`](#aio-appget-url-action)
Expand Down Expand Up @@ -140,6 +142,27 @@ OPTIONS

_See code: [src/commands/app/add/event.js](https://github.com/adobe/aio-cli-plugin-app/blob/5.4.0/src/commands/app/add/event.js)_

## `aio app:add:service`

Subscribe to services in the current Workspace

```
Subscribe to services in the current Workspace


USAGE
$ aio app:add:service

OPTIONS
-v, --verbose Verbose output
--version Show version

ALIASES
$ aio app:add:services
```

_See code: [src/commands/app/add/service.js](https://github.com/adobe/aio-cli-plugin-app/blob/5.4.0/src/commands/app/add/service.js)_

## `aio app:add:web-assets`

Add web assets support
Expand Down Expand Up @@ -167,7 +190,7 @@ Build an Adobe I/O App
```
Build an Adobe I/O App

This will always force a rebuild unless --no-force-build is set.
This will always force a rebuild unless --no-force-build is set.


USAGE
Expand Down Expand Up @@ -290,6 +313,27 @@ OPTIONS

_See code: [src/commands/app/delete/event.js](https://github.com/adobe/aio-cli-plugin-app/blob/5.4.0/src/commands/app/delete/event.js)_

## `aio app:delete:service`

Delete Services in the current Workspace

```
Delete Services in the current Workspace


USAGE
$ aio app:delete:service

OPTIONS
-v, --verbose Verbose output
--version Show version

ALIASES
$ aio app:delete:services
```

_See code: [src/commands/app/delete/service.js](https://github.com/adobe/aio-cli-plugin-app/blob/5.4.0/src/commands/app/delete/service.js)_

## `aio app:delete:web-assets`

Delete existing web assets
Expand Down Expand Up @@ -474,10 +518,10 @@ _See code: [src/commands/app/undeploy.js](https://github.com/adobe/aio-cli-plugi

## `aio app:use [CONFIG_FILE_PATH]`

Import an Adobe I/O Developer Console configuration file
Import an Adobe Developer Console configuration file

```
Import an Adobe I/O Developer Console configuration file
Import an Adobe Developer Console configuration file


USAGE
Expand All @@ -487,10 +531,33 @@ ARGUMENTS
CONFIG_FILE_PATH path to an Adobe I/O Developer Console configuration file

OPTIONS
-m, --merge Merge any .aio and .env files during import of the Adobe I/O Developer Console configuration file
-v, --verbose Verbose output
-w, --overwrite Overwrite any .aio and .env files during import of the Adobe I/O Developer Console configuration file
--version Show version
-g, --global Use the global Adobe Developer Console Org / Project / Workspace configuration,
which can be set via `aio console` commands

-v, --verbose Verbose output

-w, --workspace-name=workspace-name Specify the Adobe Developer Console Workspace name to import the configuration
from

--confirm-service-sync Skip the Service sync prompt and overwrite Service subscriptions in the new
Workspace with current subscriptions

--merge Merge any .aio and .env files during import of the Adobe Developer Console
configuration file

--no-input Skip user prompts by setting --no-service-sync and --merge. Requires one of
config_file_path or --global or --workspace-name

--no-service-sync Skip the Service sync prompt and do not attach current Service subscriptions to
the new Workspace

--overwrite Overwrite any .aio and .env files during import of the Adobe Developer Console
configuration file

--version Show version

--workspace Prompt for selection of a Workspace in the same Project, and import the
configuration for this Workspace
```

_See code: [src/commands/app/use.js](https://github.com/adobe/aio-cli-plugin-app/blob/5.4.0/src/commands/app/use.js)_
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@adobe/aio-lib-runtime": "^1.2.5",
"@adobe/aio-lib-web": "^4.0.0",
"@adobe/generator-aio-app": "^1.9.0",
"@adobe/generator-aio-console": "^2.0.1",
"@adobe/generator-aio-console": "^2.0.6",
"@oclif/command": "^1.5.11",
"@oclif/config": "^1.12.9",
"@oclif/plugin-help": "^2.2.3",
Expand Down
156 changes: 156 additions & 0 deletions src/commands/app/add/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
Copyright 2020 Adobe. 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 path = require('path')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:add:service', { provider: 'debug' })
const config = require('@adobe/aio-lib-core-config')
const chalk = require('chalk')

const {
getCliInfo,
setOrgServicesConfig,
setWorkspaceServicesConfig,
warnIfOverwriteServicesInProductionWorkspace
} = require('../../../lib/app-helper')

const BaseCommand = require('../../../BaseCommand')
const LibConsoleCLI = require('@adobe/generator-aio-console/lib/console-cli')

const { ENTP_INT_CERTS_FOLDER, CONSOLE_API_KEYS } = require('../../../lib/defaults')

class AddServiceCommand extends BaseCommand {
async run () {
const { flags } = this.parse(AddServiceCommand)

aioLogger.debug(`adding services to the current workspace, using flags: ${JSON.stringify(flags, null, 2)}`)

// login
const { accessToken, env } = await getCliInfo()
const consoleCLI = await LibConsoleCLI.init({ accessToken, env, apiKey: CONSOLE_API_KEYS[env] })

// load console configuration from .aio and .env files
const projectConfig = config.get('project')
if (!projectConfig) {
this.error('Incomplete .aio configuration, please import a valid Adobe Developer Console configuration via `aio app use` first.')
}
const orgId = projectConfig.org.id
const project = { name: projectConfig.name, id: projectConfig.id }
const workspace = { name: projectConfig.workspace.name, id: projectConfig.workspace.id }

// get latest support services
const supportedServices = await consoleCLI.getEnabledServicesForOrg(orgId)

// get current service properties
const currentServiceProperties = await consoleCLI.getServicePropertiesFromWorkspace(
orgId,
project.id,
workspace,
supportedServices
)

// update the service config, subscriptions and supported services
setOrgServicesConfig(supportedServices)
setWorkspaceServicesConfig(currentServiceProperties)

// log currently selected services (messages on stderr)
const currentServiceNames = currentServiceProperties.map(s => s.name)
console.error(`Workspace ${workspace.name} currently subscribes to the following services:\n${JSON.stringify(currentServiceNames, null, 2)}`)

// prompt user to decide on how to add services:
// - select service subscription manually
// - or clone from existing workspace
const op = await consoleCLI.promptForServiceSubscriptionsOperation(
workspace.name,
{ cloneChoice: true, nopChoice: true }
)

if (op === 'nop') {
return null
}

let newServiceProperties = []
if (op === 'select') {
// filter out already added services for selection
const currentServiceCodesSet = new Set(currentServiceProperties.map(s => s.sdkCode))
const filteredServices = supportedServices.filter(s => s.type === 'entp' && !currentServiceCodesSet.has(s.code))
if (filteredServices.length <= 0) {
LibConsoleCLI.cleanStdOut()
this.error(`All supported Services in the Organization have already been added to Workspace ${workspace.name}`)
}
// prompt to manually select services
newServiceProperties = await consoleCLI.promptForSelectServiceProperties(
workspace.name,
filteredServices
)
// now past services are appended to the selection for subscription
newServiceProperties.push(...currentServiceProperties)
}
if (op === 'clone') {
// get latest workspaces which are not the current
const otherWorkspaces = (
await consoleCLI.getWorkspaces(orgId, project.id)
).filter(w => w.id !== workspace.id)
// prompt to select one of those as a source for clone
const workspaceFrom = await consoleCLI.promptForSelectWorkspace(
otherWorkspaces,
{},
{ allowCreate: false }
)
// get serviceProperties from source workspace
newServiceProperties = await consoleCLI.getServicePropertiesFromWorkspace(
orgId,
project.id,
workspaceFrom,
supportedServices
)
if (currentServiceNames.length > 0) {
warnIfOverwriteServicesInProductionWorkspace(project.name, workspace.name)
if (workspace.name !== 'Production') {
console.error(chalk.yellow(`⚠ Service subscriptions in Workspace '${workspace.name}' will be overwritten.`))
}
}
}
// prompt confirm the new service subscription list
const confirm = await consoleCLI.confirmNewServiceSubscriptions(
workspace.name,
newServiceProperties
)
if (confirm) {
// if confirmed update the services
await consoleCLI.subscribeToServices(
orgId,
project,
workspace,
path.join(this.config.dataDir, ENTP_INT_CERTS_FOLDER),
newServiceProperties
)
// update the service configuration with the latest subscriptions
setWorkspaceServicesConfig(newServiceProperties)
// success !
this.log(chalk.green(chalk.bold(`Successfully updated Service Subscriptions in Workspace ${workspace.name}`)))
return newServiceProperties
}
// confirm == false, do nothing
return null
}
}

AddServiceCommand.description = `Subscribe to Services in the current Workspace
`

AddServiceCommand.flags = {
...BaseCommand.flags
}

AddServiceCommand.aliases = ['app:add:services']
AddServiceCommand.args = []

module.exports = AddServiceCommand
2 changes: 1 addition & 1 deletion src/commands/app/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Build extends BaseCommand {

Build.description = `Build an Adobe I/O App

This will always force a rebuild unless --no-force-build is set.
This will always force a rebuild unless --no-force-build is set.
`

Build.flags = {
Expand Down
Loading