Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
farski committed Apr 22, 2024
1 parent 4913b7e commit 56395b6
Show file tree
Hide file tree
Showing 15 changed files with 828 additions and 421 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"homepage": "https://github.com/PRX/slack-toolkit#readme",
"dependencies": {
"@aws-sdk/client-eventbridge": "*",
"@aws-sdk/client-organizations": "*",
"@aws-sdk/client-cloudfront": "*",
"@aws-sdk/client-codepipeline": "*",
"@aws-sdk/client-sts": "*",
"@slack/web-api": "*"
},
"devDependencies": {
Expand Down
16 changes: 8 additions & 8 deletions src/devops-app/access.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/** @typedef {import('@aws-sdk/client-organizations').ListAccountsResponse} ListAccountsResponse */
/** @typedef {import('@aws-sdk/client-sts').AssumeRoleResponse} AssumeRoleResponse */

const { STS } = require('@aws-sdk/client-sts');
const { Organizations } = require('@aws-sdk/client-organizations');
const { STS } = require("@aws-sdk/client-sts");
const { Organizations } = require("@aws-sdk/client-organizations");

const sts = new STS({ apiVersion: '2011-06-15' });
const sts = new STS({ apiVersion: "2011-06-15" });

module.exports = {
regions() {
return ['us-east-1', 'us-east-2', 'us-west-2'];
return ["us-east-1", "us-east-2", "us-west-2"];
},
/**
* Returns an assumed DevOps role from the given account
Expand All @@ -20,7 +20,7 @@ module.exports = {

return sts.assumeRole({
RoleArn: roleArn,
RoleSessionName: 'devops_slack_app',
RoleSessionName: "devops_slack_app",
});
},
/**
Expand All @@ -30,7 +30,7 @@ module.exports = {
async orgSharingRole() {
return sts.assumeRole({
RoleArn: process.env.AWS_ORGANIZATION_CROSS_ACCOUNT_SHARING_ROLE_ARN,
RoleSessionName: 'devops_slack_app',
RoleSessionName: "devops_slack_app",
});
},
/**
Expand All @@ -46,8 +46,8 @@ module.exports = {

// The organizations endpoint only exists in us-east-1
const organizations = new Organizations({
apiVersion: '2016-11-28',
region: 'us-east-1',
apiVersion: "2016-11-28",
region: "us-east-1",
credentials: {
accessKeyId: role.Credentials.AccessKeyId,
secretAccessKey: role.Credentials.SecretAccessKey,
Expand Down
86 changes: 43 additions & 43 deletions src/devops-app/app-home.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
const { WebClient } = require('@slack/web-api');
const { WebClient } = require("@slack/web-api");

async function publishOpsView(userId, hash) {
const web = new WebClient(process.env.SLACK_ACCESS_TOKEN);
await web.views.publish({
user_id: userId,
view: {
type: 'home',
type: "home",
blocks: [
// CloudFormation
{
type: 'header',
type: "header",
text: {
type: 'plain_text',
text: 'AWS CloudFormation',
type: "plain_text",
text: "AWS CloudFormation",
emoji: true,
},
},
{
type: 'section',
type: "section",
text: {
type: 'mrkdwn',
text: 'If you need to remove a file from CloudFront edge caches before it expires, you can manually <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html|invalidate> the file from edge caches.',
type: "mrkdwn",
text: "If you need to remove a file from CloudFront edge caches before it expires, you can manually <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html|invalidate> the file from edge caches.",
},
accessory: {
type: 'button',
style: 'primary',
type: "button",
style: "primary",
text: {
type: 'plain_text',
text: 'Create invalidation',
type: "plain_text",
text: "Create invalidation",
emoji: true,
},
action_id: 'cloudformation-invalidation_open-model',
action_id: "cloudformation-invalidation_open-model",
},
},

// CodePipeline
{ type: 'divider' },
{ type: "divider" },
{
type: 'header',
type: "header",
text: {
type: 'plain_text',
text: 'AWS CodePipeline',
type: "plain_text",
text: "AWS CodePipeline",
emoji: true,
},
},
{
type: 'section',
type: "section",
text: {
type: 'mrkdwn',
text: 'When a pipeline execution starts, it runs a revision through every stage and action in the pipeline. You can manually rerun the most recent revision through the pipeline.',
type: "mrkdwn",
text: "When a pipeline execution starts, it runs a revision through every stage and action in the pipeline. You can manually rerun the most recent revision through the pipeline.",
},
accessory: {
type: 'button',
style: 'primary',
type: "button",
style: "primary",
text: {
type: 'plain_text',
text: 'Start pipeline execution',
type: "plain_text",
text: "Start pipeline execution",
emoji: true,
},
action_id: 'codepipeline-execution_open-model',
action_id: "codepipeline-execution_open-model",
},
},
{
type: 'section',
type: "section",
text: {
type: 'mrkdwn',
text: 'Transitions are links between pipeline stages that can be disabled or enabled. They are enabled by default. When you re-enable a disabled transition, the latest revision runs through the remaining stages of the pipeline unless more than 30 days have passed. Pipeline execution won’t resume for a transition that has been disabled more than 30 days unless a new change is detected or you manually rerun the pipeline. ',
type: "mrkdwn",
text: "Transitions are links between pipeline stages that can be disabled or enabled. They are enabled by default. When you re-enable a disabled transition, the latest revision runs through the remaining stages of the pipeline unless more than 30 days have passed. Pipeline execution won’t resume for a transition that has been disabled more than 30 days unless a new change is detected or you manually rerun the pipeline. ",
},
accessory: {
type: 'button',
style: 'primary',
type: "button",
style: "primary",
text: {
type: 'plain_text',
text: 'Toggle pipeline transitions',
type: "plain_text",
text: "Toggle pipeline transitions",
emoji: true,
},
action_id: 'codepipeline-transitions_open-model',
action_id: "codepipeline-transitions_open-model",
},
},
],
Expand All @@ -91,16 +91,16 @@ async function publishDefaultView(userId, hash) {
await web.views.publish({
user_id: userId,
view: {
type: 'home',
type: "home",
blocks: [
{
type: 'header',
text: { type: 'plain_text', text: `PRX DevOps Dashboard` },
type: "header",
text: { type: "plain_text", text: `PRX DevOps Dashboard` },
},
{
type: 'section',
type: "section",
text: {
type: 'plain_text',
type: "plain_text",
text: ":lock: You don't have access to this app.",
},
},
Expand All @@ -115,21 +115,21 @@ module.exports = {
const userId = payload.event.user;
const { tab } = payload.event;

console.log('App Home opened');
console.log("App Home opened");

// No-op on messages
if (tab === 'messages') {
console.log('Ignore messages tab');
if (tab === "messages") {
console.log("Ignore messages tab");
return;
}

if (tab === 'home') {
if (tab === "home") {
let hash;
if (payload.event.view && payload.event.view.hash) {
hash = payload.event.view.hash;
}

if (process.env.DEVOPS_SLACK_USER_IDS.split(',').includes(userId)) {
if (process.env.DEVOPS_SLACK_USER_IDS.split(",").includes(userId)) {
await publishOpsView(userId, hash);
} else {
await publishDefaultView(userId, hash);
Expand Down
16 changes: 8 additions & 8 deletions src/devops-app/events.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const AppHome = require('./app-home');
const AppHome = require("./app-home.js");

const SLACK_PAYLOAD_TYPE_EVENT_CALLBACK = 'event_callback';
const SLACK_PAYLOAD_TYPE_URL_VERIFICATION = 'url_verification';
const SLACK_PAYLOAD_TYPE_EVENT_CALLBACK = "event_callback";
const SLACK_PAYLOAD_TYPE_URL_VERIFICATION = "url_verification";

module.exports = {
// Handles API payloads coming from the Slack Events API for any events
Expand All @@ -13,10 +13,10 @@ module.exports = {
const payload = JSON.parse(body);

if (payload.type === SLACK_PAYLOAD_TYPE_URL_VERIFICATION) {
console.log('Responding to event URL challenge');
console.log("Responding to event URL challenge");
return {
statusCode: 200,
headers: { 'content-type': 'application/json' },
headers: { "content-type": "application/json" },
body: JSON.stringify({ challenge: payload.challenge }),
};
}
Expand All @@ -26,14 +26,14 @@ module.exports = {
// to. Some discrete subscriptions share a type, e.g., message.im
// and message.mpim both have a `message` type.
switch (payload.event.type) {
case 'app_home_opened':
case "app_home_opened":
AppHome.handler(payload);
break;
default:
console.log('Unhandled Event API event type');
console.log("Unhandled Event API event type");
}
}

return { statusCode: 200, headers: {}, body: '' };
return { statusCode: 200, headers: {}, body: "" };
},
};
2 changes: 1 addition & 1 deletion src/devops-app/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// const { WebClient } = require('@slack/web-api');

const SlackRequest = require("./slack_request");
const SlackRequest = require("./slack_request.js");

// eslint-disable-next-line arrow-body-style
exports.handler = async (event) => {
Expand Down
42 changes: 21 additions & 21 deletions src/devops-app/interactivity.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const querystring = require('querystring');
const cfInvalidate = require('./things/cloudfront-invalidations');
const pipelineExec = require('./things/codepipeline-executions');
const pipelineTransitions = require('./things/codepipeline-transitions');
const pipelineApproval = require('./things/codepipeline-approval');
const querystring = require("querystring");
const cfInvalidate = require("./things/cloudfront-invalidations/index.js");
const pipelineExec = require("./things/codepipeline-executions/index.js");
const pipelineTransitions = require("./things/codepipeline-transitions/index.js");
const pipelineApproval = require("./things/codepipeline-approval/index.js");

const SLACK_PAYLOAD_TYPE_BLOCK_ACTIONS = 'block_actions';
const SLACK_PAYLOAD_TYPE_VIEW_SUBMISSION = 'view_submission';
const SLACK_PAYLOAD_TYPE_VIEW_CLOSED = 'view_closed';
const SLACK_PAYLOAD_TYPE_BLOCK_ACTIONS = "block_actions";
const SLACK_PAYLOAD_TYPE_VIEW_SUBMISSION = "view_submission";
const SLACK_PAYLOAD_TYPE_VIEW_CLOSED = "view_closed";

/**
* Block action payloads are always disambiguated by action_id`.
Expand All @@ -19,13 +19,13 @@ const SLACK_PAYLOAD_TYPE_VIEW_CLOSED = 'view_closed';
async function handleBlockActionPayload(payload) {
const actionId = payload.actions[0].action_id;

if (actionId.startsWith('cloudformation-invalidation_')) {
if (actionId.startsWith("cloudformation-invalidation_")) {
await cfInvalidate.handleBlockActionPayload(payload);
} else if (actionId.startsWith('codepipeline-execution_')) {
} else if (actionId.startsWith("codepipeline-execution_")) {
await pipelineExec.handleBlockActionPayload(payload);
} else if (actionId.startsWith('codepipeline-transitions_')) {
} else if (actionId.startsWith("codepipeline-transitions_")) {
await pipelineTransitions.handleBlockActionPayload(payload);
} else if (actionId.startsWith('codepipeline-approval_')) {
} else if (actionId.startsWith("codepipeline-approval_")) {
await pipelineApproval.handleBlockActionPayload(payload);
}
}
Expand All @@ -41,13 +41,13 @@ async function handleBlockActionPayload(payload) {
async function handleViewSubmissionPayload(payload) {
const callbackId = payload.view.callback_id;

if (callbackId.startsWith('cloudformation-invalidation_')) {
if (callbackId.startsWith("cloudformation-invalidation_")) {
await cfInvalidate.handleViewSubmissionPayload(payload);
} else if (callbackId.startsWith('codepipeline-execution_')) {
} else if (callbackId.startsWith("codepipeline-execution_")) {
await pipelineExec.handleViewSubmissionPayload(payload);
} else if (callbackId.startsWith('codepipeline-transitions_')) {
} else if (callbackId.startsWith("codepipeline-transitions_")) {
await pipelineTransitions.handleViewSubmissionPayload(payload);
} else if (callbackId.startsWith('codepipeline-approval_')) {
} else if (callbackId.startsWith("codepipeline-approval_")) {
await pipelineApproval.handleViewSubmissionPayload(payload);
}
}
Expand All @@ -64,15 +64,15 @@ module.exports = {
switch (payload.type) {
case SLACK_PAYLOAD_TYPE_BLOCK_ACTIONS:
await handleBlockActionPayload(payload);
return { statusCode: 200, headers: {}, body: '' };
return { statusCode: 200, headers: {}, body: "" };
case SLACK_PAYLOAD_TYPE_VIEW_SUBMISSION:
await handleViewSubmissionPayload(payload);
return { statusCode: 200, headers: {}, body: '' };
return { statusCode: 200, headers: {}, body: "" };
case SLACK_PAYLOAD_TYPE_VIEW_CLOSED:
console.log('SLACK_PAYLOAD_TYPE_VIEW_CLOSED');
return { statusCode: 200, headers: {}, body: '' };
console.log("SLACK_PAYLOAD_TYPE_VIEW_CLOSED");
return { statusCode: 200, headers: {}, body: "" };
default:
return { statusCode: 200, headers: {}, body: '' };
return { statusCode: 200, headers: {}, body: "" };
}
},
};
Loading

0 comments on commit 56395b6

Please sign in to comment.