Skip to content

Commit

Permalink
fix: use management token as fallback (#1183)
Browse files Browse the repository at this point in the history
* fix: adjust tests to reflect new desired behavior

* fix: cli picks up managementToken as fallback after cmaToken
  • Loading branch information
ruderngespra authored Feb 24, 2023
1 parent 8d38ef4 commit bff3ffe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/bin/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ const configPath = path.resolve(homedir, '.contentfulrc.json')
function getFileConfig(): ClientConfig {
try {
const config = require(configPath)
return config.cmaToken ? { accessToken: config.cmaToken } : {}
if (config.cmaToken) {
return { accessToken: config.cmaToken }
}
if (config.managementToken) {
return { accessToken: config.managementToken }
}
return {}
} catch (e) {
return {}
}
Expand Down
6 changes: 2 additions & 4 deletions test/unit/bin/lib/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ describe('Config', function () {
expect(config.accessToken).to.eql('cmaToken')
})

// This behavior may be adjusted in the future as some tools which wrap contentful-migration use
// managementToken instead of cmaToken and we may want it to be picked up to ensure compatibility
it('does not pick up managementToken even if no cmaToken is provided', function () {
it('picks up managementToken if no cmaToken is provided', function () {
writeFileSync(
resolve('/tmp', '.contentfulrc.json'),
JSON.stringify({ managementToken: 'managementToken' })
)
const config = getConfig({})
expect(config.accessToken).to.eql(undefined)
expect(config.accessToken).to.eql('managementToken')
})

it('prefers env config over contentfulrc.json', function () {
Expand Down

0 comments on commit bff3ffe

Please sign in to comment.