Skip to content

Commit

Permalink
slave -> emissary renaming & upgrade axios
Browse files Browse the repository at this point in the history
  • Loading branch information
binarymist committed Jan 13, 2021
1 parent 62bdedb commit 71e9676
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 102 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.gitignore
.git/
cloud/app-slave-provisioner/node_modules/
cloud/app-emissary-provisioner/node_modules/
cloud/s2-deprovisioner/node_modules/
local/app-slave-provisioner/node_modules/
local/app-emissary-provisioner/node_modules/
local/selenium-standalone-provisioner/node_modules/
local/s2-deprovisioner/node_modules/
sam-app/
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"protocol": "inspector",
"stopOnEntry": false
}, {
"name": "app-slave-provisioner",
"name": "app-emissary-provisioner",
"type": "node",
"request": "attach",
"address": "localhost",
"port": 5858,
"localRoot": "${workspaceFolder}/local/app-slave-provisioner",
"localRoot": "${workspaceFolder}/local/app-emissary-provisioner",
"remoteRoot": "/var/task",
"protocol": "inspector",
"stopOnEntry": false
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ lambda functions of <a href="https://purpleteam-labs.com/" title="purpleteam">pu
<tr>
<td>Top Level</td>
<td>selenium<br>provisioner</td>
<td>app-slave<br>provisioner</td>
<td>app-emissary<br>provisioner</td>
<td>s2<br>deprovisioner</td>
<td>app-slave<br>provisioner</td>
<td>app-emissary<br>provisioner</td>
<td>s2<br>deprovisioner</td>
</tr>
<tr>
Expand All @@ -36,13 +36,13 @@ lambda functions of <a href="https://purpleteam-labs.com/" title="purpleteam">pu
<a href="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/local/selenium-standalone-provisioner/package.json"><img src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda/badge.svg?targetFile=/local/selenium-standalone-provisioner/package.json" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/local/selenium-standalone-provisioner/package.json" style="max-width:100%;"></a>
</td>
<td style="width:16.66%;">
<a href="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/local/app-slave-provisioner/package.json"><img src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda/badge.svg?targetFile=/local/app-slave-provisioner/package.json" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/local/app-slave-provisioner/package.json" style="max-width:100%;"></a>
<a href="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/local/app-emissary-provisioner/package.json"><img src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda/badge.svg?targetFile=/local/app-emissary-provisioner/package.json" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/local/app-emissary-provisioner/package.json" style="max-width:100%;"></a>
</td>
<td style="width:16.66%;">
<a href="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/local/s2-deprovisioner/package.json"><img src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda/badge.svg?targetFile=/local/s2-deprovisioner/package.json" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/local/s2-deprovisioner/package.json" style="max-width:100%;"></a>
</td>
<td style="width:16.66%;">
<a href="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/cloud/app-slave-provisioner/package.json"><img src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda/badge.svg?targetFile=/cloud/app-slave-provisioner/package.json" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/cloud/app-slave-provisioner/package.json" style="max-width:100%;"></a>
<a href="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/cloud/app-emissary-provisioner/package.json"><img src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda/badge.svg?targetFile=/cloud/app-emissary-provisioner/package.json" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/cloud/app-emissary-provisioner/package.json" style="max-width:100%;"></a>
</td>
<td style="width:16.66%;">
<a href="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/cloud/s2-deprovisioner/package.json"><img src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda/badge.svg?targetFile=/cloud/s2-deprovisioner/package.json" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/purpleteam-labs/purpleteam-lambda?targetFile=/cloud/s2-deprovisioner/package.json" style="max-width:100%;"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internals.promiseAllTimeout = async (promises, timeout, resolvePartial = true) =
}));


internals.deploySlaves = async (dTOItems, {
internals.deployEmissaries = async (dTOItems, {
invokedFunctionArn, clientContext: {
Custom: {
customer,
Expand All @@ -79,7 +79,7 @@ internals.deploySlaves = async (dTOItems, {
const { promiseAllTimeout, s2ProvisioningTimeout } = internals;
const result = { items: undefined, error: undefined };
// Doc: [Lambda Environment Variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html)
console.info(`provisionAppSlaves invoked for pt customer: ${customer}.`);
console.info(`provisionAppEmissaries invoked for pt customer: ${customer}.`);
console.info(`The customerClusterArn is: ${customerClusterArn}`);
console.info(`The Account Id is: ${invokedFunctionArn.split(':')[4]}`);
console.info(`The serviceDiscoveryServices are ${JSON.stringify(serviceDiscoveryServices)}`);
Expand All @@ -105,20 +105,20 @@ internals.deploySlaves = async (dTOItems, {
const itemClone = { ...cV };
const browserNumber = numberOfBrowsersToAdd[itemClone.browser] - (runningCountOfBrowsersLeftToAdd[itemClone.browser] - 1);
runningCountOfBrowsersLeftToAdd[itemClone.browser] -= 1;
itemClone.appSlaveContainerName = `appslave-zap-${itemClone.browser}-${browserNumber}`;
itemClone.appSlaveTaskDefinition = `s2_app_slave_zap_${itemClone.browser}_${browserNumber}`;
itemClone.appEcsServiceName = `s2_app_slave_zap_${itemClone.browser}_${browserNumber}_${customer}`;
itemClone.appServiceDiscoveryServiceArn = `${serviceDiscoveryServiceArnPrefix}${serviceDiscoveryServices[`s2_app_slave_zap_${itemClone.browser}_${browserNumber}`]}`;
itemClone.appEmissaryContainerName = `appemissary-zap-${itemClone.browser}-${browserNumber}`;
itemClone.appEmissaryTaskDefinition = `s2_app_emissary_zap_${itemClone.browser}_${browserNumber}`;
itemClone.appEcsServiceName = `s2_app_emissary_zap_${itemClone.browser}_${browserNumber}_${customer}`;
itemClone.appServiceDiscoveryServiceArn = `${serviceDiscoveryServiceArnPrefix}${serviceDiscoveryServices[`s2_app_emissary_zap_${itemClone.browser}_${browserNumber}`]}`;
itemClone.seleniumContainerName = `seleniumstandalone-${itemClone.browser}-${browserNumber}`;
itemClone.seleniumTaskDefinition = `s2_app_slave_selenium_${itemClone.browser}_${browserNumber}`;
itemClone.seleniumEcsServiceName = `s2_app_slave_selenium_${itemClone.browser}_${browserNumber}_${customer}`;
itemClone.seleniumServiceDiscoveryServiceArn = `${serviceDiscoveryServiceArnPrefix}${serviceDiscoveryServices[`s2_app_slave_selenium_${itemClone.browser}_${browserNumber}`]}`;
itemClone.seleniumTaskDefinition = `s2_app_emissary_selenium_${itemClone.browser}_${browserNumber}`;
itemClone.seleniumEcsServiceName = `s2_app_emissary_selenium_${itemClone.browser}_${browserNumber}_${customer}`;
itemClone.seleniumServiceDiscoveryServiceArn = `${serviceDiscoveryServiceArnPrefix}${serviceDiscoveryServices[`s2_app_emissary_selenium_${itemClone.browser}_${browserNumber}`]}`;
return itemClone;
});
console.info(`The value of itemsWithExtras is: ${JSON.stringify(itemsWithExtras)}`);
const appItemsWithExtras = itemsWithExtras.map((item) => ({
containerName: item.appSlaveContainerName,
taskDefinition: item.appSlaveTaskDefinition,
containerName: item.appEmissaryContainerName,
taskDefinition: item.appEmissaryTaskDefinition,
ecsServiceName: item.appEcsServiceName,
serviceDiscoveryServiceArn: item.appServiceDiscoveryServiceArn,
containerPort: 8080
Expand Down Expand Up @@ -149,7 +149,7 @@ internals.deploySlaves = async (dTOItems, {
try {
const resolved = await promiseAllTimeout(promisedResponses, s2ProvisioningTimeout);
console.info(`The data objects returned from calling ecs.createService were: ${JSON.stringify(resolved)}`);
resolved.every((e) => !e) && (result.error = 'Timeout exceeded: App Slave container(s) took too long to start. Although they timed out, they may have still started.');
resolved.every((e) => !e) && (result.error = 'Timeout exceeded: App Emissary container(s) took too long to start. Although they timed out, they may have still started.');
} catch (e) {
console.error('Exception occurred, details follow:');
console.error(e);
Expand All @@ -163,20 +163,20 @@ internals.deploySlaves = async (dTOItems, {
}

result.items = itemsWithExtras.map((testSession) => {
const { appSlaveTaskDefinition, seleniumTaskDefinition, ...itemsForConsumer } = testSession;
const { appEmissaryTaskDefinition, seleniumTaskDefinition, ...itemsForConsumer } = testSession;
return itemsForConsumer;
});

return result;
};

// Doc: context: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html
exports.provisionAppSlaves = async (event, context) => {
exports.provisionAppEmissaries = async (event, context) => {
internals.s2ProvisioningTimeout = process.env.S2_PROVISIONING_TIMEOUT * 1000;
const { provisionViaLambdaDto: { items } } = event;
const { deploySlaves, printEnv } = internals;
const { deployEmissaries, printEnv } = internals;
printEnv();
const result = await deploySlaves(items, context);
const result = await deployEmissaries(items, context);

console.info(`The resulting items were: ${JSON.stringify(result.items)}`);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "app-slave-provisioner",
"name": "app-emissary-provisioner",
"version": "0.1.0-alpha.1",
"description": "purpleteam app-slave provisioner for cloud environment",
"description": "purpleteam app-emissary provisioner for cloud environment",
"main": "index.js",
"repository": "https://github.com/purpleteam-labs/purpleteam-lambda",
"author": "Kim Carter",
Expand Down
8 changes: 4 additions & 4 deletions cloud/s2-deprovisioner/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,36 @@ internals.promiseAllTimeout = async (promises, timeout, resolvePartial = true) =
}));


internals.deploySlaves = async (dTOItems) => {
internals.deployEmissaries = async (dTOItems) => {
const { promiseAllTimeout, s2ProvisioningTimeout } = internals;
const numberOfRequestedSlaves = dTOItems.length;
const numberOfRequestedEmissaries = dTOItems.length;
const result = { items: undefined, error: undefined };

if (numberOfRequestedSlaves < 1 || numberOfRequestedSlaves > 12) throw new Error(`The number of app-slaves requested was: ${numberOfRequestedSlaves}. The supported number of Test Sessions is from 1-12 inclusive.`);
if (numberOfRequestedEmissaries < 1 || numberOfRequestedEmissaries > 12) throw new Error(`The number of app-emissaries requested was: ${numberOfRequestedEmissaries}. The supported number of Test Sessions is from 1-12 inclusive.`);

// timeout in axios is for response times only, if the end-point is down, it will still take a long time. So we just wrap the actual request.
const http = axios.create({ /* default is 0 (no timeout) */ baseURL: 'http://docker-compose-ui:5000/api/v1', headers: { 'Content-type': 'application/json' } });

const promisedResponse = http.put('/services', { service: 'zap', project: 'app-slave', num: numberOfRequestedSlaves });
const promisedResponse = http.put('/services', { service: 'zap', project: 'app-emissary', num: numberOfRequestedEmissaries });
const resolved = await promiseAllTimeout([promisedResponse], s2ProvisioningTimeout);

!resolved[0] && (result.error = 'Timeout exceeded: App Slave container(s) took too long to start. Although they timed out, they may have still started. Also check that docker-compose-ui is up.');
!resolved[0] && (result.error = 'Timeout exceeded: App Emissary container(s) took too long to start. Although they timed out, they may have still started. Also check that docker-compose-ui is up.');

result.items = dTOItems.map((cV, i) => {
const itemClone = { ...cV };
itemClone.appSlaveContainerName = `appslave_zap_${i + 1}`;
itemClone.appEmissaryContainerName = `appemissary_zap_${i + 1}`;
return itemClone;
});

return result;
};

exports.provisionAppSlaves = async (event, context) => { // eslint-disable-line no-unused-vars
exports.provisionAppEmissaries = async (event, context) => { // eslint-disable-line no-unused-vars
internals.s2ProvisioningTimeout = process.env.S2_PROVISIONING_TIMEOUT * 1000;
const { provisionViaLambdaDto: { items } } = event;
const { deploySlaves, printEnv } = internals;
const { deployEmissaries, printEnv } = internals;
printEnv();
const result = await deploySlaves(items);
const result = await deployEmissaries(items);

const response = {
// 'statusCode': 200,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "app-slave-provisioner",
"name": "app-emissary-provisioner",
"version": "0.1.0-alpha.1",
"description": "purpleteam app-slave provisioner for local environment",
"description": "purpleteam app-emissary provisioner for local environment",
"main": "index.js",
"repository": "https://github.com/purpleteam-labs/purpleteam-lambda",
"author": "Kim Carter",
"license": "AGPL-3.0-only",
"dependencies": {
"axios": "^0.21.0"
"axios": "^0.21.1"
},
"scripts": {
"deps": "npm-check",
Expand Down
2 changes: 1 addition & 1 deletion local/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"NODE_ENV": "local",
"S2_PROVISIONING_TIMEOUT": 4
},
"provisionAppSlaves": {
"provisionAppEmissaries": {
"NODE_ENV": "local",
"S2_PROVISIONING_TIMEOUT": 4
},
Expand Down
21 changes: 10 additions & 11 deletions local/s2-deprovisioner/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion local/s2-deprovisioner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Kim Carter",
"license": "AGPL-3.0-only",
"dependencies": {
"axios": "^0.21.0"
"axios": "^0.21.1"
},
"scripts": {
"deps": "npm-check",
Expand Down
Loading

1 comment on commit 71e9676

@binarymist
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.