Skip to content

Commit 7c9060c

Browse files
committed
change flag useRuntimeAuth from camelCase to kebabCase use-runtime-auth, add undeploy as a DeployServiceCommand
1 parent 6898463 commit 7c9060c

File tree

7 files changed

+28
-20
lines changed

7 files changed

+28
-20
lines changed

src/DeployServiceCommand.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class DeployServiceCommand extends RuntimeBaseCommand {
6969

7070
async setRuntimeApiHostAndAuthHandler (options) {
7171
let _options = structuredClone(options)
72-
if (!_options?.useRuntimeAuth) {
72+
if (!_options?.['use-runtime-auth']) {
7373
const endpoint = process.env.AIO_DEPLOY_SERVICE_URL ?? PropertyDefault.DEPLOYSERVICEURL
7474
_options = _options ?? {}
7575
_options.apihost = `${endpoint}/runtime`
@@ -91,7 +91,7 @@ class DeployServiceCommand extends RuntimeBaseCommand {
9191

9292
DeployServiceCommand.flags = {
9393
...RuntimeBaseCommand.flags,
94-
useRuntimeAuth: Flags.boolean({ char: 'r', description: 'use Runtime auth [default: false]', default: false })
94+
'use-runtime-auth': Flags.boolean({ char: 'r', description: 'use Runtime auth [default: false]', default: false })
9595
}
9696

9797
module.exports = DeployServiceCommand

src/RuntimeBaseCommand.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ const http = require('http')
1919
const runtimeLib = require('@adobe/aio-lib-runtime')
2020
const config = require('@adobe/aio-lib-core-config')
2121

22-
/**
23-
* @typedef {object} WskCreateOptions
24-
* @property {boolean} [useRuntimeAuth=false] - Whether to use Runtime authentication
25-
* @property {object} [wskClientOptions] - The options to pass to the wsk client. If not provided, will be generated from getOptions()
26-
*/
27-
2822
class RuntimeBaseCommand extends Command {
2923
async getOptions () {
3024
const { flags } = await this.parse(this.constructor)
@@ -38,7 +32,7 @@ class RuntimeBaseCommand extends Command {
3832
namespace: config.get('runtime.namespace') || properties.get('NAMESPACE'),
3933
api_key: flags.auth || config.get('runtime.auth') || properties.get('AUTH'),
4034
ignore_certs: flags.insecure || config.get('runtime.insecure'),
41-
useRuntimeAuth: process.env.USE_RUNTIME_AUTH || flags.useRuntimeAuth
35+
'use-runtime-auth': process.env.USE_RUNTIME_AUTH || flags['use-runtime-auth']
4236
}
4337

4438
// remove any null or undefined keys

src/commands/runtime/deploy/sync.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class DeploySync extends DeployServiceCommand {
2828
}
2929
const params = {}
3030
const options = await this.getOptions()
31+
delete options['use-runtime-auth']
3132
const entities = processPackage(packages, deploymentPackages, deploymentTriggers, params, false, options)
3233
const ow = await this.wsk()
3334
const logger = this.log

src/commands/runtime/deploy/undeploy.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ OF ANY KIND, either express or implied. See the License for the specific languag
1010
governing permissions and limitations under the License.
1111
*/
1212

13-
const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
13+
const DeployServiceCommand = require('../../../DeployServiceCommand')
1414
const { getProjectEntities, undeployPackage, processPackage, setPaths } = require('@adobe/aio-lib-runtime').utils
1515
const { Flags } = require('@oclif/core')
1616

17-
class DeployUndeploy extends RuntimeBaseCommand {
17+
class DeployUndeploy extends DeployServiceCommand {
1818
async run () {
1919
const { flags } = await this.parse(DeployUndeploy)
2020
try {
2121
const options = await this.getOptions()
22+
delete options['use-runtime-auth']
2223
const ow = await this.wsk()
2324
const logger = this.log
2425

@@ -44,7 +45,7 @@ class DeployUndeploy extends RuntimeBaseCommand {
4445
}
4546

4647
DeployUndeploy.flags = {
47-
...RuntimeBaseCommand.flags,
48+
...DeployServiceCommand.flags,
4849
manifest: Flags.string({
4950
char: 'm',
5051
description: 'the manifest file location' // help description for flag

test/DeployServiceCommand.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('DeployServiceCommand', () => {
5050

5151
test('flags', async () => {
5252
expect(Object.keys(TheCommand.flags)).toEqual(expect.arrayContaining([
53-
'useRuntimeAuth'
53+
'use-runtime-auth'
5454
]))
5555
})
5656

@@ -134,16 +134,16 @@ describe('DeployServiceCommand', () => {
134134
expect(result.auth_handler).toBeDefined()
135135
})
136136

137-
test('should set runtime API host and auth handler when useRuntimeAuth is false', async () => {
137+
test('should set runtime API host and auth handler when use-runtime-auth is false', async () => {
138138
const mockOptions = { someOption: 'value' }
139139
const result = await command.setRuntimeApiHostAndAuthHandler(mockOptions)
140140

141141
expect(result.apihost).toBe(`${PropertyDefault.DEPLOYSERVICEURL}/runtime`)
142142
expect(result.auth_handler).toBeDefined()
143143
})
144144

145-
test('should not modify options when useRuntimeAuth is true', async () => {
146-
const mockOptions = { useRuntimeAuth: true, someOption: 'value' }
145+
test('should not modify options when use-runtime-auth is true', async () => {
146+
const mockOptions = { 'use-runtime-auth': true, someOption: 'value' }
147147
const result = await command.setRuntimeApiHostAndAuthHandler(mockOptions)
148148

149149
expect(result).toEqual(mockOptions)

test/RuntimeBaseCommand.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ describe('instance methods', () => {
238238

239239
test('returns a promise (pass options)', () => {
240240
RuntimeLib.init.mockReturnValue({})
241-
const options = { useRuntimeAuth: true }
241+
const options = {}
242242
return command.wsk(options).then((ow) => {
243243
expect(ow).toBeDefined()
244244
})

test/commands/runtime/deploy/undeploy.test.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ test('flags', async () => {
4141
// some expected fake values
4242
const expectedEntities = { fake: 'entities' }
4343
const expectedEntitiesFromGet = { fakeGet: 'getentities' }
44-
const expectedOWOptions = { api_key: 'some-gibberish-not-a-real-key', apihost: 'some.host', apiversion: 'v1', namespace: 'some_namespace' }
44+
const expectedOWOptions = {
45+
api_key: 'some-gibberish-not-a-real-key',
46+
apihost: 'some.host',
47+
apiversion: 'v1',
48+
namespace: 'some_namespace'
49+
}
4550
const expectedDepPackages = { fake: 'dep-packages' }
4651
const expectedDepTriggers = [{ fake: 'dep-triggers' }]
4752
const expectedPackages = { fake: 'packages' }
@@ -75,7 +80,10 @@ describe('instance methods', () => {
7580
test('run with no flags', async () => {
7681
command.argv = []
7782
await command.run()
78-
expect(utils.setPaths).toHaveBeenCalledWith({ useragent: pkgNameVersion })
83+
expect(utils.setPaths).toHaveBeenCalledWith({
84+
'use-runtime-auth': false,
85+
useragent: pkgNameVersion
86+
})
7987

8088
expect(utils.processPackage).toHaveBeenCalledWith(expectedPackages, {}, {}, {}, true, expectedOWOptions)
8189
expect(utils.getProjectEntities).not.toHaveBeenCalled()
@@ -88,7 +96,11 @@ describe('instance methods', () => {
8896
test('run with manifest flag', async () => {
8997
command.argv = ['-m', 'fake-manifest.yml']
9098
await command.run()
91-
expect(utils.setPaths).toHaveBeenCalledWith({ manifest: 'fake-manifest.yml', useragent: pkgNameVersion })
99+
expect(utils.setPaths).toHaveBeenCalledWith({
100+
'use-runtime-auth': false,
101+
manifest: 'fake-manifest.yml',
102+
useragent: pkgNameVersion
103+
})
92104

93105
expect(utils.processPackage).toHaveBeenCalledWith(expectedPackages, {}, {}, {}, true, expectedOWOptions)
94106
expect(utils.getProjectEntities).not.toHaveBeenCalled()

0 commit comments

Comments
 (0)