Skip to content

Commit

Permalink
feat: Post deploy serverless dashboard integration (#12063)
Browse files Browse the repository at this point in the history
* feat: Post deploy serverless dashboard integration

* chore: Update unit test

* chore: Use pre integration endpoint

* chore: Updated async process

* chore: Added timeout on instrumentation call

* chore: Handle region configuration

* chore: Always send instruemntation

* chore: Updated instrumentation progress

* chore: Merge #12059
  • Loading branch information
Danwakeem committed Sep 5, 2023
1 parent b09d0d6 commit 66e3107
Show file tree
Hide file tree
Showing 8 changed files with 483 additions and 71 deletions.
19 changes: 5 additions & 14 deletions lib/cli/interactive-setup/aws-credentials.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

const { log, style, progress } = require('@serverless/utils/log');
const { dashboardFrontend } = require('@serverless/utils/lib/auth/urls');
const _ = require('lodash');
const inquirer = require('@serverless/utils/inquirer');
const promptWithHistory = require('@serverless/utils/inquirer/prompt-with-history');
const memoizee = require('memoizee');
const AWS = require('../../aws/sdk-v2');

const awsCredentials = require('../../plugins/aws/utils/credentials');
const { confirm, doesServiceInstanceHaveLinkedProvider } = require('./utils');
Expand Down Expand Up @@ -111,17 +111,16 @@ const awsSecretAccessKeyInput = async ({ stepHistory }) => {

const credentialsSetupChoice = async (context, providers) => {
let credentialsSetupChoices = [];
let message = 'No AWS credentials found, what credentials do you want to use?';
let message =
"No AWS credentials found. Serverless Framework needs these to automate deployment of infra & code.\n Choose which type of AWS credentials you would like to use, and we'll help you set them up:";

if (providers) {
// This is situation where we know that user has decided to link his service to an org
const hasExistingProviders = Boolean(providers.length);
if (hasExistingProviders) {
message = 'What credentials do you want to use?';
}
const createAccessRoleName = hasExistingProviders
? 'Create a new AWS Access Role provider'
: 'AWS Access Role (most secure)';
const createAccessRoleName = 'AWS Access Role (Easy & Most Secure)';

const formatProviderName = (provider) => {
if (provider.providerType === 'roleArn') {
Expand Down Expand Up @@ -198,7 +197,7 @@ const steps = {
);
},
handleProviderCreation: async ({ configuration: { org: orgName }, stepHistory }) => {
const providersUrl = `https://app.serverless.com/${orgName}/settings/providers?source=cli&providerId=new&provider=aws`;
const providersUrl = `${dashboardFrontend}/${orgName}/settings/providers?source=cli&providerId=new&provider=aws`;
openBrowser(providersUrl);
log.notice('To learn more about providers, visit: http://slss.io/add-providers-dashboard');

Expand Down Expand Up @@ -329,14 +328,6 @@ module.exports = {
context.inapplicabilityReasonCode = 'NON_AWS_PROVIDER';
return false;
}
if (new AWS.S3().config.credentials) {
context.inapplicabilityReasonCode = 'LOCAL_CREDENTIALS_CONFIGURED';
return false;
}
if ((await awsCredentials.resolveFileProfiles()).size) {
context.inapplicabilityReasonCode = 'LOCAL_CREDENTIAL_PROFILES_CONFIGURED';
return false;
}

if (configuration.org && configuration.app && isAuthenticated()) {
let providers;
Expand Down
3 changes: 1 addition & 2 deletions lib/cli/interactive-setup/console-dev-mode-feed.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const { writeText, style, log, progress } = require('@serverless/utils/log');
const { frontend } = require('@serverless/utils/lib/auth/urls');
const { frontend, devModeFeed } = require('@serverless/utils/lib/auth/urls');
const colorize = require('json-colorizer');
const WebSocket = require('ws');
const chalk = require('chalk');
const { devModeFeed } = require('@serverless/utils/lib/auth/urls');
const consoleUi = require('@serverless/utils/console-ui');
const streamBuffers = require('stream-buffers');
const apiRequest = require('@serverless/utils/api-request');
Expand Down
1 change: 1 addition & 0 deletions lib/config-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const schema = {
* The default is `warn`, and will be set to `error` in v2
*/
configValidationMode: { enum: ['error', 'warn', 'off'] },
monitor: { anyOf: [{ type: 'boolean' }] },
// Deprecated
console: { anyOf: [{ type: 'boolean' }, { type: 'object' }] },
custom: {
Expand Down
23 changes: 22 additions & 1 deletion lib/plugins/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

const ServerlessError = require('../serverless-error');
const cliCommandsSchema = require('../cli/commands-schema');
const { awsRequest } = require('./../cli/interactive-setup/utils');
const dashboardService = require('../utils/serverless-dashboard');

class Deploy {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options || {};

this.dashboard = dashboardService(serverless, options);
this.commands = {
deploy: {
...cliCommandsSchema.get('deploy'),
Expand All @@ -28,6 +30,14 @@ class Deploy {
},
};

this.resolveAwsAccountId = async (context) => {
try {
return (await awsRequest(context, 'STS', 'getCallerIdentity')).Account;
} catch (error) {
throw new Error('Could not determine AWS Account Id');
}
};

this.hooks = {
'before:deploy:deploy': async () => {
const provider = this.serverless.service.provider.name;
Expand All @@ -39,6 +49,17 @@ class Deploy {
if (!this.options.package && !this.serverless.service.package.path) {
await this.serverless.pluginManager.spawn('package');
}

if (this.serverless.configurationInput && this.serverless.configurationInput.org) {
await this.dashboard.configureIntegrationContext();
await this.dashboard.ensureIntegrationIsConfigured();
}
},
'after:deploy:deploy': async () => {
if (this.serverless.configurationInput && this.serverless.configurationInput.org) {
await this.dashboard.instrumentService();
}
return true;
},
};
}
Expand Down

0 comments on commit 66e3107

Please sign in to comment.