Skip to content

Commit 53b13ba

Browse files
shazronJesse MacFadyen
authored andcommitted
fix: ACNA-3928 - AIO_CLI_ENV not respected for deploy service URL (#875)
1 parent 219e948 commit 53b13ba

3 files changed

Lines changed: 44 additions & 11 deletions

File tree

src/lib/auth-helper.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ governing permissions and limitations under the License.
1212
const { getToken, context } = require('@adobe/aio-lib-ims')
1313
const { CLI } = require('@adobe/aio-lib-ims/src/context')
1414
const { getCliEnv } = require('@adobe/aio-lib-env')
15-
const defaultDeployServiceUrl = 'https://deploy-service.app-builder.adp.adobe.io'
1615
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:auth-helper', { provider: 'debug' })
1716

17+
const DEPLOY_SERVICE_ENDPOINTS = {
18+
stage: 'https://deploy-service.stg.app-builder.corp.adp.adobe.io',
19+
prod: 'https://deploy-service.app-builder.adp.adobe.io'
20+
}
21+
1822
/**
1923
* Retrieves an access token for Adobe I/O CLI authentication.
2024
* This function handles both CLI and custom contexts, setting up the appropriate
@@ -65,17 +69,21 @@ const bearerAuthHandler = {
6569
}
6670

6771
const setRuntimeApiHostAndAuthHandler = (_config) => {
72+
const env = getCliEnv()
73+
let apiEndpoint = DEPLOY_SERVICE_ENDPOINTS[env] ?? DEPLOY_SERVICE_ENDPOINTS.prod
74+
if (process.env.AIO_DEPLOY_SERVICE_URL) {
75+
apiEndpoint = process.env.AIO_DEPLOY_SERVICE_URL
76+
}
77+
6878
const config = structuredClone(_config)
6979
const aioConfig = (config && 'runtime' in config) ? config : null
7080
if (aioConfig) {
71-
const apiEndpoint = process.env.AIO_DEPLOY_SERVICE_URL ?? defaultDeployServiceUrl
7281
aioConfig.runtime.apihost = `${apiEndpoint}/runtime`
7382
aioConfig.runtime.auth_handler = bearerAuthHandler
7483
return aioConfig
7584
}
7685
const owConfig = (config && 'ow' in config) ? config : null
7786
if (owConfig) {
78-
const apiEndpoint = process.env.AIO_DEPLOY_SERVICE_URL ?? defaultDeployServiceUrl
7987
owConfig.ow.apihost = `${apiEndpoint}/runtime`
8088
owConfig.ow.auth_handler = bearerAuthHandler
8189
return owConfig

test/commands/app/config/get/log-forwarding.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test('get log forwarding settings (expect init to be passed a config)', async ()
5454
await command.run()
5555
// config should be deploy service settings
5656
const modifiedConfig = structuredClone(command.appConfig.aio)
57-
modifiedConfig.runtime.apihost = 'https://deploy-service.app-builder.adp.adobe.io/runtime'
57+
modifiedConfig.runtime.apihost = 'https://deploy-service.stg.app-builder.corp.adp.adobe.io/runtime' // aio-lib-env is mocked to return 'stage'
5858
modifiedConfig.runtime.auth_handler = {
5959
getAuthHeader: expect.any(Function)
6060
}

test/commands/lib/auth-helper.test.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,55 @@ describe('bearerAuthHandler', () => {
7575
})
7676

7777
describe('setRuntimeApiHostAndAuthHandler', () => {
78-
const defaultDeployServiceUrl = 'https://deploy-service.app-builder.adp.adobe.io'
78+
const DEPLOY_SERVICE_ENDPOINTS = {
79+
prod: 'https://deploy-service.app-builder.adp.adobe.io',
80+
stage: 'https://deploy-service.stg.app-builder.corp.adp.adobe.io'
81+
}
7982

8083
beforeEach(() => {
8184
jest.clearAllMocks()
8285
delete process.env.AIO_DEPLOY_SERVICE_URL
8386
})
8487

8588
test('should set runtime.apihost and runtime.auth_handler when config has runtime', () => {
86-
const config = { runtime: {} }
87-
const result = setRuntimeApiHostAndAuthHandler(config)
88-
89-
expect(result.runtime.apihost).toBe(`${defaultDeployServiceUrl}/runtime`)
90-
expect(result.runtime.auth_handler).toBe(bearerAuthHandler)
89+
// test both envs
90+
{
91+
const mockEnv = 'prod'
92+
getCliEnv.mockReturnValue(mockEnv)
93+
94+
const config = { runtime: {} }
95+
const result = setRuntimeApiHostAndAuthHandler(config)
96+
97+
expect(result.runtime.apihost).toBe(`${DEPLOY_SERVICE_ENDPOINTS[mockEnv]}/runtime`)
98+
expect(result.runtime.auth_handler).toBe(bearerAuthHandler)
99+
}
100+
{
101+
const mockEnv = 'stage'
102+
getCliEnv.mockReturnValue(mockEnv)
103+
104+
const config = { runtime: {} }
105+
const result = setRuntimeApiHostAndAuthHandler(config)
106+
107+
expect(result.runtime.apihost).toBe(`${DEPLOY_SERVICE_ENDPOINTS[mockEnv]}/runtime`)
108+
expect(result.runtime.auth_handler).toBe(bearerAuthHandler)
109+
}
91110
})
92111

93112
test('should set ow.apihost and ow.auth_handler when config has ow', () => {
113+
const mockEnv = 'unknown-env-should-use-prod'
114+
getCliEnv.mockReturnValue(mockEnv)
115+
94116
const config = { ow: {} }
95117
const result = setRuntimeApiHostAndAuthHandler(config)
96118

97-
expect(result.ow.apihost).toBe(`${defaultDeployServiceUrl}/runtime`)
119+
expect(result.ow.apihost).toBe(`${DEPLOY_SERVICE_ENDPOINTS.prod}/runtime`)
98120
expect(result.ow.auth_handler).toBe(bearerAuthHandler)
99121
})
100122

101123
test('should use custom deploy service URL from environment', () => {
124+
const mockEnv = 'prod'
125+
getCliEnv.mockReturnValue(mockEnv)
126+
102127
const customUrl = 'https://custom-deploy-service.example.com'
103128
process.env.AIO_DEPLOY_SERVICE_URL = customUrl
104129
const config = { runtime: {} }

0 commit comments

Comments
 (0)