mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Merge pull request #5687 from serverless/remove-platform-code
Remove platform code
This commit is contained in:
commit
d817ce08d4
@ -43,23 +43,25 @@ const invocationId = uuid.v4();
|
||||
return serverless.init()
|
||||
.then(() => serverless.run())
|
||||
.then(() => process.exit(0))
|
||||
.catch((e) => {
|
||||
if (serverless.service.deployment && serverless.service.deployment.deploymentId) {
|
||||
const deploymentData = {
|
||||
tenant: serverless.service.deployment.tenant,
|
||||
app: serverless.service.deployment.app,
|
||||
serviceName: serverless.service.deployment.serviceName,
|
||||
deploymentId: serverless.service.deployment.deploymentId,
|
||||
accessKey: serverless.service.deployment.accessKey,
|
||||
};
|
||||
deploymentData.status = 'Failed';
|
||||
return platform.updateDeployment(deploymentData)
|
||||
.then(() => {
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
.catch((err) => {
|
||||
// If Enterprise Plugin, capture error
|
||||
let enterpriseErrorHandler = null;
|
||||
serverless.pluginManager.plugins.forEach((p) => {
|
||||
if (p.enterprise && p.enterprise.errorHandler) {
|
||||
enterpriseErrorHandler = p.enterprise.errorHandler;
|
||||
}
|
||||
});
|
||||
if (!enterpriseErrorHandler) { throw err; }
|
||||
return enterpriseErrorHandler(err, invocationId)
|
||||
.catch((error) => {
|
||||
// if (process.env.SLS_DEBUG) {
|
||||
console.log(error)
|
||||
// }
|
||||
})
|
||||
.then(() => {
|
||||
throw err
|
||||
});
|
||||
})
|
||||
}).catch(e => {
|
||||
process.exitCode = 1;
|
||||
logError(e);
|
||||
|
||||
@ -3,7 +3,6 @@ title: Serverless Framework Documentation
|
||||
menuText: Docs
|
||||
layout: Doc
|
||||
menuItems:
|
||||
- {menuText: Getting Started, path: /framework/docs/getting-started/}
|
||||
- {menuText: Providers, path: /framework/docs/providers}
|
||||
- {menuText: "- AWS", path: /framework/docs/providers/aws/}
|
||||
- {menuText: "- Azure", path: /framework/docs/providers/azure/}
|
||||
@ -13,6 +12,7 @@ menuItems:
|
||||
- {menuText: "- Kubeless" , path: /framework/docs/providers/kubeless/}
|
||||
- {menuText: "- Spotinst" , path: /framework/docs/providers/spotinst/}
|
||||
- {menuText: "- Cloudflare" , path: /framework/docs/providers/cloudflare/}
|
||||
- {menuText: Enterprise, path: https://www.github.com/serverless/enterprise}
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
<!--
|
||||
title: Serverless - Platform Documentation
|
||||
menuText: Platform
|
||||
layout: Doc
|
||||
menuItems:
|
||||
- {menuText: emit, path: /framework/docs/platform/commands/emit/}
|
||||
- {menuText: login, path: /framework/docs/platform/commands/login/}
|
||||
- {menuText: logout, path: /framework/docs/platform/commands/logout/}
|
||||
- {menuText: run, path: /framework/docs/platform/commands/run/}
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/platform)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Serverless Platform (Beta)
|
||||
|
||||
The Serverless Platform is currently in experimental beta. If you'd like to participate in the beta, please refer to the [full platform docs.](https://github.com/serverless/platform)
|
||||
|
||||
## Beta CLI Commands
|
||||
|
||||
Logging in to the platform enables access to beta features of the Serverless framework.
|
||||
|
||||
### [`serverless emit`](./commands/emit.md)
|
||||
Emit an event to an event-gateway.
|
||||
|
||||
### [`serverless login`](./commands/login.md)
|
||||
Register or log in to the platform.
|
||||
|
||||
### [`serverless logout`](./commands/logout.md)
|
||||
Logout of the platform.
|
||||
@ -1,20 +0,0 @@
|
||||
<!--
|
||||
title: Serverless - Platform Documentation
|
||||
menuText: commands
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/platform)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
|
||||
## Beta CLI Commands
|
||||
|
||||
Logging in to the platform enables access to beta features of the Serverless framework.
|
||||
|
||||
### [`serverless login`](./login.md)
|
||||
Register or log in to the platform.
|
||||
|
||||
### [`serverless logout`](./logout.md)
|
||||
Logout of the platform.
|
||||
@ -1,26 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Login
|
||||
menuText: login
|
||||
menuOrder: 11
|
||||
description: Login to the serverless platform
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/platform/commands/login)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Login
|
||||
|
||||
The `login` command logs users into the serverless platform.
|
||||
|
||||
It will create a new serverless platform account if one doesn't already exist.
|
||||
|
||||
*This command opens a browser window*
|
||||
|
||||
```bash
|
||||
serverless login
|
||||
|
||||
# Shorthand
|
||||
sls login
|
||||
```
|
||||
@ -1,22 +0,0 @@
|
||||
<!--
|
||||
title: Serverless Framework Commands - Logout
|
||||
menuText: logout
|
||||
menuOrder: 11
|
||||
description: Logout to the serverless platform
|
||||
layout: Doc
|
||||
-->
|
||||
|
||||
<!-- DOCS-SITE-LINK:START automatically generated -->
|
||||
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/platform/commands/logout)
|
||||
<!-- DOCS-SITE-LINK:END -->
|
||||
|
||||
# Logout
|
||||
|
||||
The `logout` command logs users out the serverless platform.
|
||||
|
||||
```bash
|
||||
serverless logout
|
||||
|
||||
# Shorthand
|
||||
sls logout
|
||||
```
|
||||
@ -4,7 +4,6 @@ const path = require('path');
|
||||
const BbPromise = require('bluebird');
|
||||
const os = require('os');
|
||||
const updateNotifier = require('update-notifier');
|
||||
const platform = require('@serverless/platform-sdk');
|
||||
const pkg = require('../package.json');
|
||||
const CLI = require('./classes/CLI');
|
||||
const Config = require('./classes/Config');
|
||||
@ -15,8 +14,7 @@ const Service = require('./classes/Service');
|
||||
const Variables = require('./classes/Variables');
|
||||
const ServerlessError = require('./classes/Error').ServerlessError;
|
||||
const Version = require('./../package.json').version;
|
||||
const configUtils = require('./utils/config');
|
||||
const getUser = require('./utils/getUser');
|
||||
const _ = require('lodash');
|
||||
|
||||
class Serverless {
|
||||
constructor(config) {
|
||||
@ -78,25 +76,6 @@ class Serverless {
|
||||
}
|
||||
|
||||
run() {
|
||||
const config = configUtils.getConfig();
|
||||
const currentId = config.userId;
|
||||
const globalConfig = configUtils.getGlobalConfig();
|
||||
|
||||
let isTokenExpired = false;
|
||||
if (globalConfig
|
||||
&& globalConfig.users
|
||||
&& globalConfig.users[currentId]
|
||||
&& globalConfig.users[currentId].auth
|
||||
&& globalConfig.users[currentId].auth.id_token
|
||||
&& !globalConfig.users[currentId].dashboard) {
|
||||
isTokenExpired = true;
|
||||
}
|
||||
|
||||
if (isTokenExpired && !this.processedInput.commands[0] === 'login') {
|
||||
this.cli
|
||||
.log('WARNING: Your login token has expired. Please run "serverless login" to login.');
|
||||
}
|
||||
|
||||
this.utils.logStat(this).catch(() => BbPromise.resolve());
|
||||
|
||||
if (this.cli.displayHelp(this.processedInput)) {
|
||||
@ -108,40 +87,15 @@ class Serverless {
|
||||
|
||||
// populate variables after --help, otherwise help may fail to print
|
||||
// (https://github.com/serverless/serverless/issues/2041)
|
||||
return this.variables.populateService(this.pluginManager.cliOptions).then(() => {
|
||||
if ((!this.processedInput.commands.includes('deploy') &&
|
||||
!this.processedInput.commands.includes('remove')) || !this.config.servicePath) {
|
||||
return this.variables.populateService(this.pluginManager.cliOptions)
|
||||
.then(() => {
|
||||
if ((!_.includes(this.processedInput.commands, 'deploy') &&
|
||||
!_.includes(this.processedInput.commands, 'remove')) || !this.config.servicePath) {
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
|
||||
return getUser().then(user => {
|
||||
if (!user) return BbPromise.resolve();
|
||||
if (!this.service.tenant && !this.service.app) {
|
||||
this.cli.log('WARNING: Missing "tenant" and "app" properties in serverless.yml. Without these properties, you can not publish the service to the Serverless Platform.'); // eslint-disable-line
|
||||
return BbPromise.resolve();
|
||||
} else if (this.service.tenant && !this.service.app) {
|
||||
const errorMessage = ['Missing "app" property in serverless.yml'].join('');
|
||||
throw new this.classes.Error(errorMessage);
|
||||
} else if (!this.service.tenant && this.service.app) {
|
||||
const errorMessage = ['Missing "tenant" property in serverless.yml'].join('');
|
||||
throw new this.classes.Error(errorMessage);
|
||||
}
|
||||
|
||||
const listTenantsData = {
|
||||
idToken: user.idToken,
|
||||
username: user.username,
|
||||
};
|
||||
|
||||
return platform.listTenants(listTenantsData).then((tenants) => {
|
||||
const tenantsList = tenants.map(tenant => tenant.tenantName);
|
||||
if (!tenantsList.includes(this.service.tenant)) {
|
||||
const errorMessage = [`tenant "${this.service
|
||||
.tenant}" does not exist.`].join('');
|
||||
throw new this.classes.Error(errorMessage);
|
||||
}
|
||||
});
|
||||
});
|
||||
}).then(() => {
|
||||
return BbPromise.resolve();
|
||||
})
|
||||
.then(() => {
|
||||
// merge arrays after variables have been populated
|
||||
// (https://github.com/serverless/serverless/issues/3511)
|
||||
this.service.mergeArrays();
|
||||
|
||||
@ -158,21 +158,6 @@ class CLI {
|
||||
}
|
||||
|
||||
generateMainHelp() {
|
||||
let platformCommands;
|
||||
let frameworkCommands;
|
||||
if (this.loadedCommands) {
|
||||
const commandKeys = Object.keys(this.loadedCommands);
|
||||
const sortedCommandKeys = _.sortBy(commandKeys);
|
||||
const partitionedCommandKeys = _.partition(sortedCommandKeys,
|
||||
(key) => this.loadedCommands[key].platform);
|
||||
platformCommands = _.fromPairs(
|
||||
_.map(partitionedCommandKeys[0], key => [key, this.loadedCommands[key]])
|
||||
);
|
||||
frameworkCommands = _.fromPairs(
|
||||
_.map(partitionedCommandKeys[1], key => [key, this.loadedCommands[key]])
|
||||
);
|
||||
}
|
||||
|
||||
this.consoleLog('');
|
||||
|
||||
this.consoleLog(chalk.yellow.underline('Commands'));
|
||||
@ -187,25 +172,8 @@ class CLI {
|
||||
this.consoleLog(chalk.dim('* Documentation: https://serverless.com/framework/docs/'));
|
||||
|
||||
this.consoleLog('');
|
||||
if (!_.isEmpty(frameworkCommands)) {
|
||||
_.forEach(frameworkCommands, (details, command) => {
|
||||
this.displayCommandUsage(details, command);
|
||||
});
|
||||
} else {
|
||||
this.consoleLog('No commands found');
|
||||
}
|
||||
|
||||
this.consoleLog('');
|
||||
|
||||
this.consoleLog(chalk.yellow.underline('Platform (Beta)'));
|
||||
// eslint-disable-next-line max-len
|
||||
this.consoleLog(chalk.dim('* The Serverless Platform is currently in experimental beta. Follow the docs below to get started.'));
|
||||
this.consoleLog(chalk.dim('* Documentation: https://serverless.com/platform/docs/'));
|
||||
|
||||
this.consoleLog('');
|
||||
|
||||
if (!_.isEmpty(platformCommands)) {
|
||||
_.forEach(platformCommands, (details, command) => {
|
||||
if (!_.isEmpty(this.loadedCommands)) {
|
||||
_.forEach(this.loadedCommands, (details, command) => {
|
||||
this.displayCommandUsage(details, command);
|
||||
});
|
||||
} else {
|
||||
@ -329,8 +297,8 @@ class CLI {
|
||||
process.stdout.write(chalk.yellow('.'));
|
||||
}
|
||||
|
||||
log(message) {
|
||||
this.consoleLog(`Serverless: ${chalk.yellow(`${message}`)}`);
|
||||
log(message, entity) {
|
||||
this.consoleLog(`${entity || 'Serverless'}: ${chalk.yellow(`${message}`)}`);
|
||||
}
|
||||
|
||||
consoleLog(message) {
|
||||
|
||||
@ -8,8 +8,6 @@
|
||||
"./invoke/invoke.js",
|
||||
"./info/info.js",
|
||||
"./logs/logs.js",
|
||||
"./login/login.js",
|
||||
"./logout/logout.js",
|
||||
"./metrics/metrics.js",
|
||||
"./print/print.js",
|
||||
"./remove/remove.js",
|
||||
@ -48,7 +46,6 @@
|
||||
"./aws/package/compile/events/sqs/index.js",
|
||||
"./aws/deployFunction/index.js",
|
||||
"./aws/deployList/index.js",
|
||||
"./aws/invokeLocal/index.js",
|
||||
"./platform/platform.js"
|
||||
"./aws/invokeLocal/index.js"
|
||||
]
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ const createStack = require('./lib/createStack');
|
||||
const cleanupS3Bucket = require('./lib/cleanupS3Bucket');
|
||||
const uploadArtifacts = require('./lib/uploadArtifacts');
|
||||
const validateTemplate = require('./lib/validateTemplate');
|
||||
const createDeployment = require('./lib/createDeployment');
|
||||
const updateStack = require('../lib/updateStack');
|
||||
const existsDeploymentBucket = require('./lib/existsDeploymentBucket');
|
||||
const path = require('path');
|
||||
@ -33,7 +32,6 @@ class AwsDeploy {
|
||||
cleanupS3Bucket,
|
||||
uploadArtifacts,
|
||||
validateTemplate,
|
||||
createDeployment,
|
||||
updateStack,
|
||||
existsDeploymentBucket,
|
||||
monitorStack
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const platform = require('@serverless/platform-sdk');
|
||||
const BbPromise = require('bluebird');
|
||||
const getAccessKey = require('../../../../utils/getAccessKey');
|
||||
|
||||
module.exports = {
|
||||
createDeployment() {
|
||||
const serverlessStateFilePath = path.join(
|
||||
this.serverless.config.servicePath, '.serverless', 'serverless-state.json');
|
||||
const serverlessStateFileContent = JSON.parse(fs.readFileSync(serverlessStateFilePath, 'utf8'));
|
||||
|
||||
return getAccessKey(this.serverless.service.tenant).then(accessKey => {
|
||||
if (accessKey && this.serverless.service.app &&
|
||||
this.serverless.service.tenant &&
|
||||
!this.options.noDeploy) {
|
||||
const deploymentData = {
|
||||
tenant: this.serverless.service.tenant,
|
||||
app: this.serverless.service.app,
|
||||
accessKey,
|
||||
serviceName: this.serverless.service.service,
|
||||
files: {
|
||||
'serverless-state.json': serverlessStateFileContent,
|
||||
},
|
||||
};
|
||||
return platform.createDeployment(deploymentData)
|
||||
.then((res) => {
|
||||
this.serverless.service.deployment = {
|
||||
deploymentId: res.id,
|
||||
accessKey,
|
||||
tenant: this.serverless.service.tenant,
|
||||
app: this.serverless.service.app,
|
||||
serviceName: this.serverless.service.service,
|
||||
};
|
||||
return BbPromise.resolve();
|
||||
});
|
||||
}
|
||||
return BbPromise.resolve();
|
||||
});
|
||||
},
|
||||
};
|
||||
@ -36,12 +36,11 @@ module.exports = {
|
||||
params.NotificationARNs = this.serverless.service.provider.notificationArns;
|
||||
}
|
||||
|
||||
return this.createDeployment().then(() => this.provider.request(
|
||||
return this.provider.request(
|
||||
'CloudFormation',
|
||||
'createStack',
|
||||
params
|
||||
).then((cfData) => this.monitorStack('create', cfData))
|
||||
);
|
||||
).then((cfData) => this.monitorStack('create', cfData));
|
||||
},
|
||||
|
||||
createStack() {
|
||||
|
||||
@ -50,7 +50,6 @@ describe('createStack', () => {
|
||||
const createStackStub = sandbox
|
||||
.stub(awsDeploy.provider, 'request').resolves();
|
||||
sandbox.stub(awsDeploy, 'monitorStack').resolves();
|
||||
sandbox.stub(awsDeploy, 'createDeployment').resolves();
|
||||
|
||||
return awsDeploy.create().then(() => {
|
||||
expect(createStackStub.args[0][2].Tags)
|
||||
@ -67,7 +66,6 @@ describe('createStack', () => {
|
||||
const createStackStub = sandbox
|
||||
.stub(awsDeploy.provider, 'request').resolves();
|
||||
sandbox.stub(awsDeploy, 'monitorStack').resolves();
|
||||
sandbox.stub(awsDeploy, 'createDeployment').resolves();
|
||||
|
||||
return awsDeploy.create().then(() => {
|
||||
expect(createStackStub.args[0][2].RoleARN)
|
||||
@ -82,7 +80,6 @@ describe('createStack', () => {
|
||||
const createStackStub = sinon
|
||||
.stub(awsDeploy.provider, 'request').resolves();
|
||||
sinon.stub(awsDeploy, 'monitorStack').resolves();
|
||||
sinon.stub(awsDeploy, 'createDeployment').resolves();
|
||||
|
||||
return awsDeploy.create().then(() => {
|
||||
expect(createStackStub.args[0][2].NotificationARNs)
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
'use strict';
|
||||
const BbPromise = require('bluebird');
|
||||
const getS3EndpointForRegion = require('../../utils/getS3EndpointForRegion');
|
||||
|
||||
module.exports = {
|
||||
@ -23,13 +22,6 @@ module.exports = {
|
||||
` ${error.message}`,
|
||||
].join('');
|
||||
throw new Error(errorMessage);
|
||||
}).then(() => {
|
||||
if (!this.serverless.service.deployment || !this.serverless.service.deployment.deploymentId) {
|
||||
return this.createDeployment().catch((error) => {
|
||||
throw new Error(error);
|
||||
});
|
||||
}
|
||||
return BbPromise.resolve();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@ -35,7 +35,6 @@ describe('validateTemplate', () => {
|
||||
},
|
||||
};
|
||||
validateTemplateStub = sinon.stub(awsDeploy.provider, 'request');
|
||||
sinon.stub(awsDeploy, 'createDeployment').resolves();
|
||||
awsDeploy.serverless.cli = {
|
||||
log: sinon.spy(),
|
||||
};
|
||||
@ -43,7 +42,6 @@ describe('validateTemplate', () => {
|
||||
|
||||
afterEach(() => {
|
||||
awsDeploy.provider.request.restore();
|
||||
awsDeploy.createDeployment.restore();
|
||||
});
|
||||
|
||||
describe('#validateTemplate()', () => {
|
||||
|
||||
@ -135,7 +135,7 @@ class AwsInvokeLocal {
|
||||
this.options.context);
|
||||
}
|
||||
|
||||
if (['python2.7', 'python3.6', 'python3.7'].includes(runtime)) {
|
||||
if (_.includes(['python2.7', 'python3.6', 'python3.7'], runtime)) {
|
||||
const handlerComponents = handler.split(/\./);
|
||||
const handlerPath = handlerComponents.slice(0, -1).join('.');
|
||||
const handlerName = handlerComponents.pop();
|
||||
|
||||
@ -53,7 +53,7 @@ class AwsLogs {
|
||||
}
|
||||
|
||||
return _.chain(reply.logStreams)
|
||||
.filter(stream => stream.logStreamName.includes('[$LATEST]'))
|
||||
.filter(stream => _.includes(stream.logStreamName, '[$LATEST]'))
|
||||
.map('logStreamName')
|
||||
.value();
|
||||
});
|
||||
|
||||
@ -1,77 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
const jwtDecode = require('jwt-decode');
|
||||
const platform = require('@serverless/platform-sdk');
|
||||
const configUtils = require('../../utils/config');
|
||||
const userStats = require('../../utils/userStats');
|
||||
|
||||
class Login {
|
||||
constructor(serverless, options) {
|
||||
this.serverless = serverless;
|
||||
this.options = options;
|
||||
|
||||
this.commands = {
|
||||
login: {
|
||||
usage: 'Login or sign up for the Serverless Platform',
|
||||
lifecycleEvents: ['login'],
|
||||
platform: true,
|
||||
},
|
||||
};
|
||||
|
||||
this.hooks = {
|
||||
'login:login': () => BbPromise.bind(this).then(this.login),
|
||||
};
|
||||
}
|
||||
login() {
|
||||
this.serverless.cli.log('The Serverless login will open in your default browser...');
|
||||
const configuration = configUtils.getConfig();
|
||||
const frameworkId = configuration.frameworkId;
|
||||
|
||||
return platform.login().then(data => {
|
||||
const decoded = jwtDecode(data.idToken);
|
||||
// because platform only support github
|
||||
const id = decoded.tracking_id || decoded.sub;
|
||||
const userConfig = {
|
||||
userId: id,
|
||||
frameworkId,
|
||||
users: {},
|
||||
};
|
||||
// set user auth in global .serverlessrc file
|
||||
userConfig.users[id] = {
|
||||
userId: id,
|
||||
name: decoded.name,
|
||||
email: decoded.email,
|
||||
username: data.username,
|
||||
dashboard: data,
|
||||
};
|
||||
|
||||
// update .serverlessrc
|
||||
configUtils.set(userConfig);
|
||||
|
||||
// identify user for better onboarding
|
||||
userStats
|
||||
.identify({
|
||||
id,
|
||||
frameworkId,
|
||||
email: decoded.email,
|
||||
// unix timestamp
|
||||
created_at: Math.round(+new Date(decoded.createdAt) / 1000),
|
||||
trackingDisabled: configuration.trackingDisabled,
|
||||
force: true,
|
||||
})
|
||||
.then(() => {
|
||||
userStats
|
||||
.track('user_loggedIn', {
|
||||
id,
|
||||
email: decoded.email,
|
||||
force: true,
|
||||
});
|
||||
});
|
||||
this.serverless.cli.log('You are now logged in');
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Login;
|
||||
@ -1,19 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const expect = require('chai').expect;
|
||||
const Login = require('./login');
|
||||
const Serverless = require('../../Serverless');
|
||||
|
||||
describe('Login', () => {
|
||||
let login;
|
||||
let serverless;
|
||||
|
||||
beforeEach(() => {
|
||||
serverless = new Serverless();
|
||||
login = new Login(serverless);
|
||||
});
|
||||
|
||||
describe('#constructor()', () => {
|
||||
it('should have commands', () => expect(login.commands).to.be.not.empty);
|
||||
});
|
||||
});
|
||||
@ -1,57 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const userStats = require('../../utils/userStats');
|
||||
const configUtils = require('../../utils/config');
|
||||
|
||||
class Logout {
|
||||
constructor(serverless, options) {
|
||||
this.serverless = serverless;
|
||||
this.options = options;
|
||||
|
||||
this.commands = {
|
||||
logout: {
|
||||
usage: 'Logout from the Serverless Platform',
|
||||
lifecycleEvents: ['logout'],
|
||||
platform: true,
|
||||
},
|
||||
};
|
||||
|
||||
this.hooks = {
|
||||
'logout:logout': this.logout.bind(this),
|
||||
};
|
||||
}
|
||||
logout() {
|
||||
const config = configUtils.getConfig();
|
||||
const currentId = config.userId;
|
||||
const globalConfig = configUtils.getGlobalConfig();
|
||||
|
||||
try {
|
||||
// TODO Once we start using refresh tokens we also need to implement an API endpoint
|
||||
// that invalidate a refresh token in Auth0 (using the Auth0 Management API).
|
||||
|
||||
if (globalConfig && globalConfig.users && globalConfig.users[currentId]) {
|
||||
if (globalConfig.users[currentId].dashboard
|
||||
&& globalConfig.users[currentId].dashboard.idToken) {
|
||||
// remove auth tokens from user
|
||||
configUtils.set(`users.${currentId}.dashboard.accessToken`, null);
|
||||
configUtils.set(`users.${currentId}.dashboard.idToken`, null);
|
||||
configUtils.set(`users.${currentId}.dashboard.expiresAt`, null);
|
||||
// log stat
|
||||
userStats.track('user_loggedOut').then(() => {
|
||||
this.serverless.cli.consoleLog('Successfully logged out.');
|
||||
process.exit(0);
|
||||
});
|
||||
} else {
|
||||
this.serverless.cli.consoleLog('You are already logged out');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
this.serverless.cli.consoleLog(
|
||||
'Failed to logout. Please report bug in https://github.com/serverless/serverless/issues');
|
||||
// Note no need to wait for any connections e.g. segment to close
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Logout;
|
||||
@ -1,19 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const expect = require('chai').expect;
|
||||
const Logout = require('./logout');
|
||||
const Serverless = require('../../Serverless');
|
||||
|
||||
describe('Logout', () => {
|
||||
let logout;
|
||||
let serverless;
|
||||
|
||||
beforeEach(() => {
|
||||
serverless = new Serverless();
|
||||
logout = new Logout(serverless);
|
||||
});
|
||||
|
||||
describe('#constructor()', () => {
|
||||
it('should have commands', () => expect(logout.commands).to.be.not.empty);
|
||||
});
|
||||
});
|
||||
@ -204,7 +204,7 @@ module.exports = {
|
||||
filePathStates[key] = !exclude;
|
||||
});
|
||||
});
|
||||
const filePaths = Object.entries(filePathStates).filter(r => r[1] === true).map(r => r[0]);
|
||||
const filePaths = _.toPairs(filePathStates).filter(r => r[1] === true).map(r => r[0]);
|
||||
if (filePaths.length !== 0) return filePaths;
|
||||
throw new this.serverless.classes.Error('No file matches include / exclude patterns');
|
||||
});
|
||||
|
||||
@ -1,108 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const fsExtra = require('../../utils/fs/fse');
|
||||
const platform = require('@serverless/platform-sdk');
|
||||
const getAccessKey = require('../../utils/getAccessKey');
|
||||
const userStats = require('../../utils/userStats');
|
||||
|
||||
class Platform {
|
||||
constructor(serverless, options) {
|
||||
this.serverless = serverless;
|
||||
this.options = options;
|
||||
this.provider = this.serverless.getProvider('aws');
|
||||
// NOTE for the time being we only track services published to AWS
|
||||
if (this.provider) {
|
||||
this.hooks = {
|
||||
'after:deploy:finalize': this.publishService.bind(this),
|
||||
'after:remove:remove': this.archiveService.bind(this),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
getReadme() {
|
||||
const readmePath = path.join(this.serverless.config.servicePath, 'README.md');
|
||||
if (fs.existsSync(readmePath)) {
|
||||
return fsExtra.readFileSync(readmePath).toString('utf8');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
publishService() {
|
||||
if (!this.serverless.service.deployment || !this.serverless.service.deployment.deploymentId) {
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
this.serverless.cli.log('Publishing service to Serverless Platform...');
|
||||
|
||||
return this.provider.getStackResources().then(resources => {
|
||||
this.cfResources = resources;
|
||||
}).then(() => this.provider.getAccountId())
|
||||
.then(accountId => {
|
||||
const deploymentData = {
|
||||
tenant: this.serverless.service.deployment.tenant,
|
||||
app: this.serverless.service.deployment.app,
|
||||
serviceName: this.serverless.service.deployment.serviceName,
|
||||
accessKey: this.serverless.service.deployment.accessKey,
|
||||
deploymentId: this.serverless.service.deployment.deploymentId,
|
||||
status: 'success',
|
||||
computedData: {
|
||||
readme: this.getReadme(),
|
||||
accountId,
|
||||
apiId: this.serverless.service.deployment.apiId,
|
||||
physicalIds: this.cfResources.map(r => ({
|
||||
logicalId: r.LogicalResourceId,
|
||||
physicalId: r.PhysicalResourceId,
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
||||
return platform.updateDeployment(deploymentData)
|
||||
.then(() => {
|
||||
const trackingData = {
|
||||
tenant: deploymentData.tenant,
|
||||
app: deploymentData.app,
|
||||
};
|
||||
userStats.track('service_published', trackingData);
|
||||
const serviceUrlData = {
|
||||
tenant: deploymentData.tenant,
|
||||
app: deploymentData.app,
|
||||
name: deploymentData.serviceName,
|
||||
};
|
||||
const serviceUrl = platform.getServiceUrl(serviceUrlData);
|
||||
this.serverless.cli
|
||||
.log('Successfully published your service on the Serverless Platform');
|
||||
this.serverless.cli.log(`Service URL: ${serviceUrl}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
archiveService() {
|
||||
return getAccessKey(this.serverless.service.tenant).then(accessKey => {
|
||||
if (!accessKey || !this.serverless.service.app || !this.serverless.service.tenant) {
|
||||
return BbPromise.resolve();
|
||||
}
|
||||
const data = {
|
||||
name: this.serverless.service.service,
|
||||
tenant: this.serverless.service.tenant,
|
||||
app: this.serverless.service.app,
|
||||
provider: this.serverless.service.provider.name,
|
||||
region: this.serverless.service.provider.region,
|
||||
accessKey,
|
||||
};
|
||||
return platform.archiveService(data)
|
||||
.then(() => {
|
||||
this.serverless.cli.log('Successfully archived your service on the Serverless Platform');
|
||||
})
|
||||
.catch(err => {
|
||||
this.serverless.cli.log('Failed to archived your service on the Serverless Platform');
|
||||
throw new this.serverless.classes.Error(err.message);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Platform;
|
||||
@ -1,52 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const configUtils = require('./config');
|
||||
const platform = require('@serverless/platform-sdk');
|
||||
const BbPromise = require('bluebird');
|
||||
|
||||
function getAccessKey(tenant) {
|
||||
if (process.env.SERVERLESS_ACCESS_KEY) {
|
||||
return BbPromise.resolve(process.env.SERVERLESS_ACCESS_KEY);
|
||||
}
|
||||
if (!tenant) {
|
||||
return BbPromise.resolve(null);
|
||||
}
|
||||
const userConfig = configUtils.getConfig();
|
||||
const currentId = userConfig.userId;
|
||||
const globalConfig = configUtils.getGlobalConfig();
|
||||
if (globalConfig.users && globalConfig.users[currentId] &&
|
||||
globalConfig.users[currentId].dashboard) {
|
||||
if (!globalConfig.users[currentId].dashboard.accessKeys &&
|
||||
globalConfig.users[currentId].dashboard.accessKey) {
|
||||
// restructure for backward compatability
|
||||
globalConfig.users[currentId].dashboard.accessKeys = {};
|
||||
globalConfig.users[currentId].dashboard
|
||||
.accessKeys[tenant] = globalConfig.users[currentId].dashboard.accessKey;
|
||||
configUtils.set(globalConfig);
|
||||
return BbPromise.resolve(globalConfig.users[currentId].dashboard
|
||||
.accessKeys[tenant]);
|
||||
} else if (globalConfig.users[currentId].dashboard.accessKeys &&
|
||||
globalConfig.users[currentId].dashboard.accessKeys[tenant]) {
|
||||
return BbPromise.resolve(globalConfig.users[currentId].dashboard
|
||||
.accessKeys[tenant]);
|
||||
} else if (globalConfig.users[currentId].dashboard.idToken) {
|
||||
const data = {
|
||||
tenant,
|
||||
username: globalConfig.users[currentId].username,
|
||||
idToken: globalConfig.users[currentId].dashboard.idToken,
|
||||
title: 'Framework',
|
||||
};
|
||||
return platform.createAccessKey(data).then(res => {
|
||||
if (!globalConfig.users[currentId].dashboard.accessKeys) {
|
||||
globalConfig.users[currentId].dashboard.accessKeys = {};
|
||||
}
|
||||
globalConfig.users[currentId].dashboard.accessKeys[tenant] = res.secretAccessKey;
|
||||
configUtils.set(globalConfig);
|
||||
return res.secretAccessKey;
|
||||
});
|
||||
}
|
||||
}
|
||||
return BbPromise.resolve(null);
|
||||
}
|
||||
|
||||
module.exports = getAccessKey;
|
||||
@ -1,36 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const configUtils = require('./config');
|
||||
const platform = require('@serverless/platform-sdk');
|
||||
const BbPromise = require('bluebird');
|
||||
|
||||
function getUser() {
|
||||
const userConfig = configUtils.getConfig();
|
||||
const currentId = userConfig.userId;
|
||||
const globalConfig = configUtils.getGlobalConfig();
|
||||
let user = null;
|
||||
if (globalConfig
|
||||
&& globalConfig.users
|
||||
&& globalConfig.users[currentId]
|
||||
&& globalConfig.users[currentId].dashboard) {
|
||||
user = globalConfig.users[currentId].dashboard;
|
||||
}
|
||||
if (!user || !user.username || !user.idToken) { // user logged out
|
||||
return BbPromise.resolve(null);
|
||||
}
|
||||
|
||||
if (Number(user.expiresAt) - 43200000 < (new Date()).getTime()) {
|
||||
return platform.refreshToken(user.refreshToken).then(tokens => {
|
||||
const expiresAt = tokens.expires_in * 1000 + new Date().getTime(); // eslint-disable-line
|
||||
globalConfig.users[currentId].dashboard.idToken = tokens.id_token;
|
||||
globalConfig.users[currentId].dashboard.accessToken = tokens.access_token;
|
||||
globalConfig.users[currentId].dashboard.expiresAt = expiresAt;
|
||||
configUtils.set(globalConfig);
|
||||
return BbPromise.resolve({ idToken: tokens.id_token, username: user.username });
|
||||
});
|
||||
}
|
||||
|
||||
return BbPromise.resolve({ idToken: user.idToken, username: user.username });
|
||||
}
|
||||
|
||||
module.exports = getUser;
|
||||
@ -1,19 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const configUtils = require('./config');
|
||||
|
||||
function isLoggedIn() {
|
||||
const config = configUtils.getConfig();
|
||||
const currentId = config.userId;
|
||||
const globalConfig = configUtils.getGlobalConfig();
|
||||
if (globalConfig
|
||||
&& globalConfig.users
|
||||
&& globalConfig.users[currentId]
|
||||
&& globalConfig.users[currentId].dashboard
|
||||
&& globalConfig.users[currentId].dashboard.idToken) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = isLoggedIn;
|
||||
3400
package-lock.json
generated
3400
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user