-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
803 additions
and
805 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** @typedef {import('@aws-sdk/client-organizations').ListAccountsResponse} ListAccountsResponse */ | ||
/** @typedef {import('@aws-sdk/client-sts').AssumeRoleResponse} AssumeRoleResponse */ | ||
|
||
import { STSClient, AssumeRoleCommand } from "@aws-sdk/client-sts"; | ||
import { | ||
OrganizationsClient, | ||
ListAccountsCommand, | ||
} from "@aws-sdk/client-organizations"; | ||
|
||
const sts = new STSClient({ apiVersion: "2011-06-15" }); | ||
|
||
export function regions() { | ||
return ["us-east-1", "us-east-2", "us-west-2"]; | ||
} | ||
|
||
/** | ||
* Returns an assumed DevOps role from the given account | ||
* @param {string} awsAccountId | ||
* @returns {Promise<AssumeRoleResponse>} | ||
*/ | ||
export async function devopsRole(awsAccountId) { | ||
const roleArn = `arn:aws:iam::${awsAccountId}:role/${process.env.DEVOPS_CROSS_ACCOUNT_ACCESS_ROLE_NAME}`; | ||
|
||
return sts.send( | ||
new AssumeRoleCommand({ | ||
RoleArn: roleArn, | ||
RoleSessionName: "devops_slack_app", | ||
}), | ||
); | ||
} | ||
|
||
/** | ||
* Returns an assumed Organization data sharing role from the given account | ||
* @returns {Promise<AssumeRoleResponse>} | ||
*/ | ||
export async function orgSharingRole() { | ||
return sts.send( | ||
new AssumeRoleCommand({ | ||
RoleArn: process.env.AWS_ORGANIZATION_CROSS_ACCOUNT_SHARING_ROLE_ARN, | ||
RoleSessionName: "devops_slack_app", | ||
}), | ||
); | ||
} | ||
|
||
/** | ||
* Returns a list of all AWS accounts that exist in an organization | ||
* @returns {Promise<ListAccountsResponse>} | ||
*/ | ||
export async function orgAccounts() { | ||
// Assume a role within the Organization's management account that has | ||
// permission to `listAccounts` | ||
// This is NOT the DevOps shared access account, which exists in each account. | ||
// It's a different role that only exists in the management account. | ||
const role = await orgSharingRole(); | ||
|
||
// The organizations endpoint only exists in us-east-1 | ||
const organizations = new OrganizationsClient({ | ||
apiVersion: "2016-11-28", | ||
region: "us-east-1", | ||
credentials: { | ||
accessKeyId: role.Credentials.AccessKeyId, | ||
secretAccessKey: role.Credentials.SecretAccessKey, | ||
sessionToken: role.Credentials.SessionToken, | ||
}, | ||
}); | ||
|
||
const accounts = await organizations.send(new ListAccountsCommand({})); | ||
|
||
return accounts; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { handler as appHomeHandler } from "./app-home.mjs"; | ||
|
||
const SLACK_PAYLOAD_TYPE_EVENT_CALLBACK = "event_callback"; | ||
const SLACK_PAYLOAD_TYPE_URL_VERIFICATION = "url_verification"; | ||
|
||
// Handles API payloads coming from the Slack Events API for any events | ||
// the Botzee app has subscribed to. Must return an HTTP response object. | ||
// https://api.slack.com/events-api#event_types | ||
// https://api.slack.com/events | ||
// https://api.slack.com/events-api#receiving_events | ||
export async function handler(event, body) { | ||
const payload = JSON.parse(body); | ||
|
||
if (payload.type === SLACK_PAYLOAD_TYPE_URL_VERIFICATION) { | ||
console.log("Responding to event URL challenge"); | ||
return { | ||
statusCode: 200, | ||
headers: { "content-type": "application/json" }, | ||
body: JSON.stringify({ challenge: payload.challenge }), | ||
}; | ||
} | ||
|
||
if (payload.type === SLACK_PAYLOAD_TYPE_EVENT_CALLBACK) { | ||
// This should handle all event types that the app is subscribed | ||
// 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": | ||
appHomeHandler(payload); | ||
break; | ||
default: | ||
console.log("Unhandled Event API event type"); | ||
} | ||
} | ||
|
||
return { statusCode: 200, headers: {}, body: "" }; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { handler as reqHandler } from "./slack_request.mjs"; | ||
|
||
export const handler = async (event) => { | ||
return reqHandler(event); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.