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

Switch to new dashboard #477

Merged
merged 5 commits into from
Aug 28, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict';

const { urls } = require('@serverless/platform-sdk');
const dashboardUrl =
process.env.SERVERLESS_PLATFORM_STAGE === 'dev'
? 'https://app.serverless-dev.com/'
: 'https://app.serverless.com/';

module.exports.getDashboardUrl = (ctx) => {
let dashboardUrl = urls.frontendUrl;
if (ctx.sls.enterpriseEnabled) {
dashboardUrl += `tenants/${ctx.sls.service.org}/`;
dashboardUrl += `applications/${ctx.sls.service.app}/`;
dashboardUrl += `services/${ctx.sls.service.service}/`;
dashboardUrl += `stage/${ctx.provider.getStage()}/`;
dashboardUrl += `region/${ctx.provider.getRegion()}`;
}
return dashboardUrl;
if (!ctx.sls.enterpriseEnabled) return dashboardUrl;
const { service } = ctx.sls;
return `${dashboardUrl}${service.org}/apps/${service.app}/${
service.service
}/${ctx.provider.getStage()}/${ctx.provider.getRegion()}`;
};
5 changes: 3 additions & 2 deletions lib/deployment/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
* - This uses the new deployment data model.
*/

const { getDashboardUrl } = require('../dashboard');
const parseDeploymentData = require('./parse');

module.exports = async function (ctx, archived = false) {
ctx.sls.cli.log('Publishing service to the Serverless Dashboard...');

const deployment = await parseDeploymentData(ctx, undefined, undefined, archived);

const result = await deployment.save();
await deployment.save();

ctx.sls.cli.log(
`Successfully published your service to the Serverless Dashboard: ${result.dashboardUrl}`
`Successfully published your service to the Serverless Dashboard: ${getDashboardUrl(ctx)}`
);
};
6 changes: 3 additions & 3 deletions lib/deployment/save.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const sinon = require('sinon');
const proxyquire = require('proxyquire');

const parseSave = sinon.stub().resolves({ dashboardUrl: 'https://dashboard.serverless.com/foo' });
const parseSave = sinon.stub().resolves({});
const parseDeploymentData = sinon.stub().resolves({ save: parseSave });
const saveDeployment = proxyquire('./save', {
'./parse': parseDeploymentData,
Expand All @@ -21,8 +21,8 @@ describe('saveDeployment', () => {
await saveDeployment(ctx);
expect(parseDeploymentData.args[0]).to.deep.equal([ctx, undefined, undefined, false]);
expect(parseSave.calledOnce).to.be.true;
expect(log.lastCall.args[0]).to.equal(
'Successfully published your service to the Serverless Dashboard: https://dashboard.serverless.com/foo'
expect(log.lastCall.args[0]).includes(
'Successfully published your service to the Serverless Dashboard'
);
});
});
5 changes: 3 additions & 2 deletions lib/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

const serializeError = require('./serializeError');
const { getDashboardUrl } = require('./dashboard');
const { parseDeploymentData } = require('./deployment');

module.exports = function (ctx) {
Expand All @@ -18,10 +19,10 @@ module.exports = function (ctx) {

const deployment = await parseDeploymentData(ctx, 'error', serializeError(error));

const result = await deployment.save();
await deployment.save();

ctx.sls.cli.log(
`Successfully published your service to the Serverless Dashboard: ${result.dashboardUrl}`
`Successfully published your service to the Serverless Dashboard: ${getDashboardUrl(ctx)}`
);
if (!ctx.state.deployment) {
ctx.state.deployment = {};
Expand Down
8 changes: 3 additions & 5 deletions lib/errorHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ describe('errorHandler', () => {
expect(parseDeploymentData.args[0][1]).to.equal('error');
expect(ctx.sls.cli.log.calledWith('Publishing service to the Serverless Dashboard...')).to.be
.true;
expect(
ctx.sls.cli.log.calledWith(
'Successfully published your service to the Serverless Dashboard: URL'
)
).to.be.true;
expect(ctx.sls.cli.log.lastCall.args[0]).includes(
'Successfully published your service to the Serverless Dashboard'
);
});
});
52 changes: 38 additions & 14 deletions lib/login.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
'use strict';

const { login } = require('@serverless/platform-sdk');
const open = require('open');
const { ServerlessSDK } = require('@serverless/platform-client');
const { urls, readConfigFile, writeConfigFile } = require('@serverless/platform-sdk');

module.exports = async function (ctx) {
ctx.sls.cli.log('Logging you in via your default browser...');
// Include a "org" in "login()"...
// This will create a new accessKey for that org on every login.
try {
await login(ctx.sls.service.org);
} catch (err) {
if (err === 'Complete sign-up before logging in.') {
ctx.sls.cli.log(
"Please complete sign-up at dashboard.serverless.com, then run 'serverless' to configure your service"
);
process.exit(1);
}
}

const sdk = new ServerlessSDK();

const loginConfig = {
...urls,
};

const { loginUrl, loginData: loginDataDeferred } = await sdk.login(loginConfig);

open(loginUrl);

const loginData = await loginDataDeferred;

const configFile = readConfigFile();

// prepare login data to save it in the FS
configFile.userId = loginData.id;
configFile.users = configFile.users || {};
configFile.users[loginData.id] = {
userId: loginData.id,
name: loginData.name,
email: loginData.email,
username: loginData.username,
dashboard: {
refreshToken: loginData.refreshToken,
accessToken: loginData.accessToken,
idToken: loginData.idToken,
expiresAt: loginData.expiresAt,
username: loginData.username,
},
};

// save the login data in the rc file
writeConfigFile(configFile);

ctx.sls.cli.log('You sucessfully logged in to Serverless.');
if (!ctx.sls.service.org || !ctx.sls.service.app) {
ctx.sls.cli.log("Please run 'serverless' to configure your service");
}
process.exit(0);
};
64 changes: 0 additions & 64 deletions lib/login.test.js

This file was deleted.

15 changes: 10 additions & 5 deletions lib/logout.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
'use strict';

const { logout } = require('@serverless/platform-sdk');
const { getLoggedInUser, logout } = require('@serverless/platform-sdk');

module.exports = async function (ctx) {
return logout().then(() => {
ctx.sls.cli.log('You sucessfully logged out of Serverless.');
process.exit(0);
});
const user = getLoggedInUser();

if (!user) {
ctx.sls.cli.log('You are already logged out');
return;
}

await logout();
ctx.sls.cli.log('You sucessfully logged out of Serverless.');
};
4 changes: 2 additions & 2 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const _ = require('lodash');
const updateNotifier = require('update-notifier');
const {
configureFetchDefaults,
openBrowser,
getAccessKeyForTenant,
getMetadata,
} = require('@serverless/platform-sdk');
const open = require('open');
const sfePkgJson = require('../package');
const errorHandler = require('./errorHandler');
const logsCollection = require('./logsCollection');
Expand Down Expand Up @@ -471,7 +471,7 @@ class ServerlessEnterprisePlugin {
);
break;
case 'dashboard:dashboard':
openBrowser(getDashboardUrl(this));
open(getDashboardUrl(this));
break;
case 'before:logs:logs':
await getCredentials(this);
Expand Down
7 changes: 1 addition & 6 deletions lib/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const proxyquire = require('proxyquire');
const sinon = require('sinon');
const chalk = require('chalk');

const _ = require('lodash');

Expand Down Expand Up @@ -277,11 +276,7 @@ describe('plugin', () => {
expect(
// eslint-disable-next-line no-console
console.log.args[0][0]
).to.equal(
chalk.yellow(
'Run "serverless dashboard" to open the dashboard or visit https://dashboard/tenants/org/applications/app/services/service/stage/stage/region/region'
)
);
).to.include('Run "serverless dashboard" to open the dashboard or visit ');
});

it('sets app & org from CLI flags if not in interactive mode', async () => {
Expand Down
7 changes: 4 additions & 3 deletions lib/studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,17 @@ module.exports = async function (ctx) {
sls.cli.log(`Cleaning up stage "${deployToStage}"...`);
await serverlessExec.remove();
}

process.exit(0);
};

let filenameToFunctionsMapping = {};

/**
* Capture ctrl+c and remove the stage that we setup
*/
process.on('SIGINT', cleanup);
process.on('SIGINT', async () => {
await cleanup();
process.exit();
});
process.on('uncaughtException', disconnect);
process.on('exit', cleanup);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"ncjsm": "^4.1.0",
"node-dir": "^0.1.17",
"node-fetch": "^2.6.0",
"open": "^7.2.0",
"semver": "^6.3.0",
"simple-git": "^1.132.0",
"update-notifier": "^2.5.0",
Expand Down