Skip to content

Commit

Permalink
do not force login if deploy with --no-publish (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage authored Nov 15, 2024
1 parent ad8192a commit 31b7a9e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/commands/app/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Deploy extends BuildCommand {

// if there are no extensions, then set publish to false
flags.publish = flags.publish && !isStandaloneApp

if (
(!flags.publish && !flags['web-assets'] && !flags.actions)
) {
Expand All @@ -53,7 +52,7 @@ class Deploy extends BuildCommand {

try {
const aioConfig = (await this.getFullConfig()).aio
const cliDetails = await getCliInfo()
const cliDetails = await getCliInfo(flags.publish)

// 1. update log forwarding configuration
// note: it is possible that .aio file does not exist, which means there is no local lg config
Expand Down
31 changes: 23 additions & 8 deletions src/lib/app-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,30 @@ function wrapError (err) {
return new Error(message)
}

/** @private */
async function getCliInfo () {
await context.setCli({ 'cli.bare-output': true }, false) // set this globally

/**
* getCliInfo
*
* @private
*
* @param {boolean} useForce - if true, user will be forced to login if not already logged in
* @returns {Promise<{accessToken: string, env: string}>} accessToken and env
*/
async function getCliInfo (useForce = true) {
const env = getCliEnv()

aioLogger.debug(`Retrieving CLI Token using env=${env}`)
const accessToken = await getToken(CLI)

let accessToken
await context.setCli({ 'cli.bare-output': true }, false) // set this globally
if (useForce) {
aioLogger.debug('Retrieving CLI Token using force=true')
accessToken = await getToken(CLI)
} else {
aioLogger.debug('Retrieving CLI Token using force=false')
// in this case, the user might be logged in, but we don't want to force them
// we just check the config for the token ( we still use the cli context so we don't need to know
// the inner workings of ims-lib and where it stores access tokens)
// todo: this is a workaround, we should have a better way to check if the user is logged in (in ims-lib)
const contextConfig = await context.getCli()
accessToken = contextConfig?.access_token?.token
}
return { accessToken, env }
}

Expand Down
7 changes: 7 additions & 0 deletions test/commands/lib/app-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,13 @@ describe('getCliInfo', () => {
{ accessToken: 'stoken', env: 'stage' }
)
})
test('useForceFalse', async () => {
libEnv.getCliEnv.mockReturnValue('prod')
libIms.getToken.mockResolvedValue('asdasd')
const res = await appHelper.getCliInfo(false)
expect(res).toEqual({ accessToken: undefined, env: 'prod' })
expect(libIms.getToken).toHaveBeenCalledTimes(0)
})
})

describe('createWebExportFilter', () => {
Expand Down

0 comments on commit 31b7a9e

Please sign in to comment.