Skip to content
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

do not force login if deploy with --no-publish #819

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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