-
Notifications
You must be signed in to change notification settings - Fork 35
ACNA-3275 point app plugin to deploy service #852
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
amulyakashyap09
merged 17 commits into
master
from
acna-3275-point-app-plugin-to-deploy-service
Mar 26, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
59be9e5
wip: use ims token to auth runtime deploy actions
MichaelGoberling ccce5b4
default values set
f8869e0
Merge branch 'master' of github.com:adobe/aio-cli-plugin-app into acn…
bcc640a
added test cases
2f2d7d6
fix: missed process env value
0f6ad0f
Updated code as per comments on PR
309da82
Updated code as per comments on PR
83c3bda
Updated code as per comments on PR
f4a3e56
Merge branch 'master' into acna-3275-point-app-plugin-to-deploy-service
shazron 53b94fe
Merge branch 'master' into acna-3275-point-app-plugin-to-deploy-service
shazron 0c57594
Updated code as per comments on PR
08c3058
Merge branch 'master' of github.com:adobe/aio-cli-plugin-app into acn…
f5e323c
Merge branch 'acna-3275-point-app-plugin-to-deploy-service' of github…
25e4553
feat: ACNA-3602 - Added the Feature Flag for Deploy Service
adf7115
Updated lib-runtime-dependency
9ca08ae
fixed default runtime url
69d131d
Fixed a scenario, where user does config api host and default runtime…
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| Copyright 2024 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 { getToken, context } = require('@adobe/aio-lib-ims') | ||
| const { CLI } = require('@adobe/aio-lib-ims/src/context') | ||
| const { getCliEnv } = require('@adobe/aio-lib-env') | ||
| const defaultRuntimeUrl = 'https://adobeioruntime.net' | ||
|
|
||
| /** | ||
| * For use with the openwhisk client js library to send a bearer token instead of basic | ||
| * auth to the openwhisk service. Set this to the auth_handler option when initializing | ||
| */ | ||
| const bearerAuthHandler = { | ||
| getAuthHeader: async () => { | ||
| await context.setCli({ 'cli.bare-output': true }, false) // set this globally | ||
|
|
||
| const env = getCliEnv() | ||
|
|
||
| console.debug(`Retrieving CLI Token using env=${env}`) | ||
| const accessToken = await getToken(CLI) | ||
|
|
||
| return `Bearer ${accessToken}` | ||
| } | ||
| } | ||
|
|
||
| const setRuntimeApiHostAndAuthHandler = (config) => { | ||
| // TODO: remove this check once the deploy service is enabled by default | ||
| if (process.env.IS_DEPLOY_SERVICE_ENABLED === 'true') { | ||
| const aioConfig = (config && 'runtime' in config) ? config : null | ||
| if (aioConfig) { | ||
| aioConfig.runtime.apihost = process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl | ||
| aioConfig.runtime.auth_handler = bearerAuthHandler | ||
| return aioConfig | ||
| } | ||
| const owConfig = (config && 'ow' in config) ? config : null | ||
| if (owConfig) { | ||
| owConfig.ow.apihost = process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl | ||
| owConfig.ow.auth_handler = bearerAuthHandler | ||
| return owConfig | ||
| } | ||
| } else { | ||
| if (config && config.runtime) { | ||
| config.runtime.apihost = process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl | ||
| } | ||
| if (config && config.ow) { | ||
| config.ow.apihost = process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl | ||
| } | ||
| } | ||
| return config | ||
| } | ||
|
|
||
| module.exports = { | ||
| bearerAuthHandler, | ||
| setRuntimeApiHostAndAuthHandler | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| const { bearerAuthHandler, setRuntimeApiHostAndAuthHandler } = require('../../../src/lib/auth-helper') | ||
| const { getToken, context } = require('@adobe/aio-lib-ims') | ||
| const { CLI } = require('@adobe/aio-lib-ims/src/context') | ||
| const { getCliEnv } = require('@adobe/aio-lib-env') | ||
|
|
||
| jest.mock('@adobe/aio-lib-ims') | ||
| jest.mock('@adobe/aio-lib-env') | ||
|
|
||
| describe('bearerAuthHandler', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| test('getAuthHeader should return a Bearer token', async () => { | ||
| const mockToken = 'mocked-token' | ||
| getToken.mockResolvedValue(mockToken) | ||
| getCliEnv.mockReturnValue('test-env') | ||
|
|
||
| const result = await bearerAuthHandler.getAuthHeader() | ||
|
|
||
| expect(context.setCli).toHaveBeenCalledWith({ 'cli.bare-output': true }, false) | ||
| expect(getCliEnv).toHaveBeenCalled() | ||
| expect(getToken).toHaveBeenCalledWith(CLI) | ||
| expect(result).toBe(`Bearer ${mockToken}`) | ||
| }) | ||
| }) | ||
|
|
||
| describe('setRuntimeApiHostAndAuthHandler', () => { | ||
| const defaultRuntimeUrl = 'https://adobeioruntime.net' | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| process.env.IS_DEPLOY_SERVICE_ENABLED = 'true' | ||
| }) | ||
|
|
||
| test('should set runtime.apihost and runtime.auth_handler when config has runtime', () => { | ||
| const config = { runtime: {} } | ||
| const result = setRuntimeApiHostAndAuthHandler(config) | ||
|
|
||
| expect(result.runtime.apihost).toBe(process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl) | ||
| expect(result.runtime.auth_handler).toBe(bearerAuthHandler) | ||
| }) | ||
|
|
||
| test('should set ow.apihost and ow.auth_handler when config has ow', () => { | ||
| const config = { ow: {} } | ||
| const result = setRuntimeApiHostAndAuthHandler(config) | ||
|
|
||
| expect(result.ow.apihost).toBe(process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl) | ||
| expect(result.ow.auth_handler).toBe(bearerAuthHandler) | ||
| }) | ||
|
|
||
| test('should return config unchanged when config has neither runtime nor ow', () => { | ||
| const config = { other: {} } | ||
| const result = setRuntimeApiHostAndAuthHandler(config) | ||
|
|
||
| expect(result).toBe(config) | ||
| }) | ||
|
|
||
| test('should return null when config is null', () => { | ||
| const result = setRuntimeApiHostAndAuthHandler(null) | ||
|
|
||
| expect(result).toBeNull() | ||
| }) | ||
|
|
||
| test('should set default runtime.apihost only config has runtime', () => { | ||
| process.env.IS_DEPLOY_SERVICE_ENABLED = 'false' | ||
| const config = { runtime: {} } | ||
| const result = setRuntimeApiHostAndAuthHandler(config) | ||
|
|
||
| expect(result.runtime.apihost).toBe(defaultRuntimeUrl) | ||
| expect(result.runtime.auth_handler).toBeUndefined() | ||
| }) | ||
|
|
||
| test('should set default ow.apihost only config has openwhisk', () => { | ||
| process.env.IS_DEPLOY_SERVICE_ENABLED = 'false' | ||
| const config = { ow: {} } | ||
| const result = setRuntimeApiHostAndAuthHandler(config) | ||
|
|
||
| expect(result.ow.apihost).toBe(defaultRuntimeUrl) | ||
| expect(result.ow.auth_handler).toBeUndefined() | ||
| }) | ||
| }) |
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.