Skip to content

Commit

Permalink
refactor: Migrate from platform-sdk refreshToken
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Jan 29, 2021
1 parent d5c7a93 commit bfb54ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/interactiveCli/set-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

const _ = require('lodash');
const chalk = require('chalk');
const accountUtils = require('@serverless/utils/account');
const configUtils = require('@serverless/utils/config');
const { ServerlessSDK } = require('@serverless/platform-client');
const {
createApp,
createDeployProfile,
getApps,
getDeployProfiles,
getMetadata,
listTenants,
refreshToken,
setDefaultDeploymentProfile,
} = require('@serverless/platform-sdk');
const enableConfirm = require('./enableConfirm');
Expand Down Expand Up @@ -144,7 +145,7 @@ const steps = {
// make a valid representation
for (const org of Object.keys(user.accessKeys)) orgs.add(org);
} else {
await refreshToken();
await accountUtils.refreshToken(new ServerlessSDK());
user = configUtils.getLoggedInUser();
orgs = new Set(
(await listTenants({ username: user.username, idToken: user.idToken })).map(
Expand Down
10 changes: 9 additions & 1 deletion lib/interactiveCli/set-app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const semver = require('semver');
const setupServerless = require('../../test/setupServerless');

const platformSdkPath = require.resolve('@serverless/platform-sdk');
const platformClientPath = require.resolve('@serverless/platform-client');

const lifecycleHookNamesBlacklist = [
'interactiveCli:initializeService',
'interactiveCli:setupAws',
Expand Down Expand Up @@ -69,14 +71,20 @@ describe('interactiveCli: set-app', function () {
}),
listTenants: async () => [{ tenantName: 'testinteractivecli' }, { tenantName: 'otherorg' }],
login: sinon.stub().resolves(),
refreshToken: async () => {},
setDefaultDeploymentProfile: setDefaultDeploymentProfileStub,
};
modulesCacheStub = {
[require.resolve(inquirerPath)]: inquirer,
[require.resolve('./utils')]: { resolveAccessKey: async () => 'token' },
[require.resolve('.//register')]: registerConfiguration,
[require.resolve('../deployProfile')]: { configureDeployProfile: async () => {} },
[platformClientPath]: {
ServerlessSDK: class ServerlessSDK {
async refreshToken() {
return {};
}
},
},
[platformSdkPath]: platformSdkStub,
};
sinon.stub(registerConfiguration, 'check').resolves(false);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "serverless/enterprise-plugin",
"dependencies": {
"@serverless/event-mocks": "^1.1.1",
"@serverless/platform-client": "^3.1.5",
"@serverless/platform-client": "^3.9.1",
"@serverless/platform-sdk": "^2.3.2",
"@serverless/utils": "^3.1.0",
"chalk": "^4.1.0",
Expand Down

0 comments on commit bfb54ec

Please sign in to comment.