@adobe/aio-cli-plugin-app-storage 1.3.0-pre.2026-02-20.sha-df98265c → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +334 -338
- package/oclif.manifest.json +1600 -0
- package/package.json +5 -5
- package/src/DBBaseCommand.js +22 -14
- package/src/commands/app/db/status.js +4 -0
- package/src/constants/global.js +2 -0
- package/src/utils/authHelper.js +81 -0
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/aio-cli-plugin-app-storage",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@adobe/aio-lib-core-config": "^5",
|
|
6
6
|
"@adobe/aio-lib-core-logging": "^3",
|
|
7
|
-
"@adobe/aio-lib-db": "^
|
|
7
|
+
"@adobe/aio-lib-db": "^1.0.0",
|
|
8
8
|
"@adobe/aio-lib-env": "^3.0.1",
|
|
9
|
+
"@adobe/aio-lib-ims": "^8.0.0",
|
|
9
10
|
"@adobe/aio-lib-state": "^5.3.0",
|
|
10
11
|
"@inquirer/prompts": "^5",
|
|
11
12
|
"@oclif/core": "^4",
|
|
@@ -91,6 +92,5 @@
|
|
|
91
92
|
"setupFiles": [
|
|
92
93
|
"<rootDir>/test/jest.env.js"
|
|
93
94
|
]
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
95
|
+
}
|
|
96
|
+
}
|
package/src/DBBaseCommand.js
CHANGED
|
@@ -12,10 +12,11 @@ governing permissions and limitations under the License.
|
|
|
12
12
|
|
|
13
13
|
import { BaseCommand } from './BaseCommand.js'
|
|
14
14
|
import config from '@adobe/aio-lib-core-config'
|
|
15
|
-
import {
|
|
15
|
+
import { CONFIG_RUNTIME_NAMESPACE } from './constants/global.js'
|
|
16
16
|
import { AVAILABLE_REGIONS, CONFIG_DB_ENDPOINT, CONFIG_DB_REGION, DEFAULT_REGION } from './constants/db.js'
|
|
17
17
|
import { Flags } from '@oclif/core'
|
|
18
18
|
import { getCliEnv } from '@adobe/aio-lib-env'
|
|
19
|
+
import { getAccessToken } from './utils/authHelper.js'
|
|
19
20
|
|
|
20
21
|
export class DBBaseCommand extends BaseCommand {
|
|
21
22
|
async init () {
|
|
@@ -33,12 +34,27 @@ export class DBBaseCommand extends BaseCommand {
|
|
|
33
34
|
async initializeDBClient () {
|
|
34
35
|
try {
|
|
35
36
|
const region = this.flags?.region || config.get(CONFIG_DB_REGION) || DEFAULT_REGION
|
|
37
|
+
const runtimeNamespace = config.get(CONFIG_RUNTIME_NAMESPACE)
|
|
38
|
+
if (!runtimeNamespace) {
|
|
39
|
+
this.error(
|
|
40
|
+
`Database commands require App Builder project configuration.
|
|
41
|
+
Please make sure the 'AIO_RUNTIME_NAMESPACE' environment variable is configured`
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const authToken = await getAccessToken()
|
|
46
|
+
if (!authToken) {
|
|
47
|
+
this.error(
|
|
48
|
+
'Database commands require IMS token for authentication. Please make sure you have the required Ims credentials configured in environment variables.'
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
36
52
|
// Get database configuration
|
|
37
53
|
const dbConfig = {
|
|
38
54
|
ow: {
|
|
39
|
-
namespace:
|
|
40
|
-
auth: config.get(CONFIG_RUNTIME_AUTH)
|
|
55
|
+
namespace: runtimeNamespace
|
|
41
56
|
},
|
|
57
|
+
token: authToken,
|
|
42
58
|
region
|
|
43
59
|
}
|
|
44
60
|
|
|
@@ -48,14 +64,6 @@ export class DBBaseCommand extends BaseCommand {
|
|
|
48
64
|
this.error(`Invalid region '${region}' for the ${getCliEnv()} environment, must be one of: ${allowedRegions.join(', ')}`)
|
|
49
65
|
}
|
|
50
66
|
|
|
51
|
-
// Validate required configuration
|
|
52
|
-
if (!(dbConfig.ow.namespace && dbConfig.ow.auth)) {
|
|
53
|
-
this.error(
|
|
54
|
-
`Database commands require App Builder project configuration.
|
|
55
|
-
Please make sure the 'AIO_RUNTIME_NAMESPACE' and 'AIO_RUNTIME_AUTH' environment variables are configured.`
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
67
|
const endpointOverride = config.get(CONFIG_DB_ENDPOINT)
|
|
60
68
|
if (endpointOverride) {
|
|
61
69
|
process.env.AIO_DB_ENDPOINT = endpointOverride
|
|
@@ -70,7 +78,7 @@ Please make sure the 'AIO_RUNTIME_NAMESPACE' and 'AIO_RUNTIME_AUTH' environment
|
|
|
70
78
|
this.debugLogger?.info?.('Initializing DB client with config:', {
|
|
71
79
|
namespace: dbConfig.ow.namespace,
|
|
72
80
|
region: dbConfig.region,
|
|
73
|
-
|
|
81
|
+
hasToken: !!dbConfig.token
|
|
74
82
|
})
|
|
75
83
|
|
|
76
84
|
// Initialize the database client
|
|
@@ -97,12 +105,12 @@ Please make sure the 'AIO_RUNTIME_NAMESPACE' and 'AIO_RUNTIME_AUTH' environment
|
|
|
97
105
|
// Add json and region flags to GLOBAL FLAGS section in --help output
|
|
98
106
|
DBBaseCommand.flags = {
|
|
99
107
|
...BaseCommand.flags,
|
|
100
|
-
json: {
|
|
108
|
+
json: Flags.boolean({
|
|
101
109
|
description: 'Format output as json.',
|
|
102
110
|
default: false,
|
|
103
111
|
required: false,
|
|
104
112
|
helpGroup: 'GLOBAL'
|
|
105
|
-
},
|
|
113
|
+
}),
|
|
106
114
|
region: Flags.string({
|
|
107
115
|
description: `Database region. Defaults to 'AIO_DB_REGION' environment variable or '${DEFAULT_REGION}' if neither is set. Any database region set in 'app.config.yaml' takes precedence over all of these.\n<options: ${AVAILABLE_REGIONS.prod.join('|')}>`,
|
|
108
116
|
required: false,
|
|
@@ -111,6 +111,10 @@ export class Status extends DBBaseCommand {
|
|
|
111
111
|
this.log(chalk.dim(` Message: ${provisionStatusResponse.message}`))
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
if (provisionStatusResponse.region) {
|
|
115
|
+
this.log(chalk.dim(` Region: ${provisionStatusResponse.region}`))
|
|
116
|
+
}
|
|
117
|
+
|
|
114
118
|
if (provisionStatusResponse.submitted) {
|
|
115
119
|
this.log(chalk.dim(` Submitted: ${new Date(provisionStatusResponse.submitted).toLocaleString()}`))
|
|
116
120
|
}
|
package/src/constants/global.js
CHANGED
|
@@ -12,3 +12,5 @@ governing permissions and limitations under the License.
|
|
|
12
12
|
|
|
13
13
|
export const CONFIG_RUNTIME_NAMESPACE = 'runtime.namespace'
|
|
14
14
|
export const CONFIG_RUNTIME_AUTH = 'runtime.auth'
|
|
15
|
+
export const CONFIG_IMS_TECHNICAL_ACCOUNT_EMAIL_PLACEHOLDER = 'dummy@techacct.adobe.com'
|
|
16
|
+
export const CONFIG_IMS_TECHNICAL_ACCOUNT_ID_PLACEHOLDER = 'dummy@techacct.adobe.com'
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 Adobe. 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
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Helper to get the IMS access token using Adobe I/O SDK
|
|
15
|
+
* @returns {string} The IMS access token
|
|
16
|
+
*/
|
|
17
|
+
import aioLibIms from '@adobe/aio-lib-ims'
|
|
18
|
+
import { CONFIG_IMS_TECHNICAL_ACCOUNT_EMAIL_PLACEHOLDER, CONFIG_IMS_TECHNICAL_ACCOUNT_ID_PLACEHOLDER } from '../constants/global.js'
|
|
19
|
+
const normalizeArrayString = (value) => {
|
|
20
|
+
try {
|
|
21
|
+
const parsed = JSON.parse(value)
|
|
22
|
+
return Array.isArray(parsed) ? JSON.stringify(parsed) : '[]'
|
|
23
|
+
} catch {
|
|
24
|
+
const items = value.split(',').map((entry) => entry.trim()).filter(Boolean)
|
|
25
|
+
return JSON.stringify(items)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const buildAuthConfig = () => {
|
|
30
|
+
const clientId = process.env.IMS_OAUTH_S2S_CLIENT_ID
|
|
31
|
+
const clientSecret = process.env.IMS_OAUTH_S2S_CLIENT_SECRET
|
|
32
|
+
const orgId = process.env.IMS_OAUTH_S2S_ORG_ID
|
|
33
|
+
const scopes = process.env.IMS_OAUTH_S2S_SCOPES
|
|
34
|
+
const technicalAccountEmail = process.env.IMS_OAUTH_S2S_TECHNICAL_ACCOUNT_EMAIL || CONFIG_IMS_TECHNICAL_ACCOUNT_EMAIL_PLACEHOLDER
|
|
35
|
+
const technicalAccountId = process.env.IMS_OAUTH_S2S_TECHNICAL_ACCOUNT_ID || CONFIG_IMS_TECHNICAL_ACCOUNT_ID_PLACEHOLDER
|
|
36
|
+
|
|
37
|
+
if (!clientId || !clientSecret || !orgId || !scopes) {
|
|
38
|
+
throw new Error('Missing required credentials. Please set IMS_OAUTH_S2S_CLIENT_ID, IMS_OAUTH_S2S_CLIENT_SECRET, IMS_OAUTH_S2S_ORG_ID, and IMS_OAUTH_S2S_SCOPES environment variables.')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
client_id: clientId,
|
|
43
|
+
client_secrets: normalizeArrayString(clientSecret),
|
|
44
|
+
ims_org_id: orgId,
|
|
45
|
+
scopes: normalizeArrayString(scopes),
|
|
46
|
+
technical_account_email: technicalAccountEmail,
|
|
47
|
+
technical_account_id: technicalAccountId
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get or generate an IMS access token using OAuth Server-to-Server credentials.
|
|
53
|
+
* @returns {Promise<string>} The access token
|
|
54
|
+
*/
|
|
55
|
+
export async function getAccessToken () {
|
|
56
|
+
const runtimeNamespace = process.env.AIO_RUNTIME_NAMESPACE
|
|
57
|
+
|
|
58
|
+
if (!runtimeNamespace) {
|
|
59
|
+
throw new Error('Runtime namespace is required. Please set AIO_RUNTIME_NAMESPACE environment variable.')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const authConfig = buildAuthConfig()
|
|
64
|
+
const imsContextName = `oauth_s2s_${runtimeNamespace}`
|
|
65
|
+
|
|
66
|
+
const { context, getToken } = aioLibIms
|
|
67
|
+
await context.set(imsContextName, authConfig, true)
|
|
68
|
+
const accessToken = await getToken(imsContextName)
|
|
69
|
+
|
|
70
|
+
if (!accessToken) {
|
|
71
|
+
throw new Error('Failed to generate access token. Please verify your credentials.')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return accessToken
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error instanceof Error) {
|
|
77
|
+
throw error
|
|
78
|
+
}
|
|
79
|
+
throw new Error('Failed to retrieve access token: Unknown error')
|
|
80
|
+
}
|
|
81
|
+
}
|