Skip to content

Commit

Permalink
Merge pull request #25 from GlueOps/feat/add-aws
Browse files Browse the repository at this point in the history
Feat/add aws
  • Loading branch information
NichArchA82 authored Sep 30, 2024
2 parents da4a64f + 0903270 commit cf6b2c5
Show file tree
Hide file tree
Showing 11 changed files with 1,884 additions and 39 deletions.
1,315 changes: 1,315 additions & 0 deletions command-handler/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions command-handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "ISC",
"description": "",
"dependencies": {
"@aws-sdk/client-ec2": "^3.658.1",
"axios": "^1.7.7",
"dotenv": "^16.4.5",
"unique-names-generator": "^4.7.1",
Expand Down
9 changes: 5 additions & 4 deletions command-handler/src/cmd-handler/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ const registeredButtons = {
button_list_servers: {
command: 'vm',
},
button_create_vm: {
command: 'vm',
},
button_delete_vm: {
command: 'vm',
},
Expand All @@ -27,7 +24,11 @@ const registeredButtons = {
"^button_create_image_": {
command: 'vm',
isRegex: true,
}
},
"^button_create_vm": {
command: 'vm',
isRegex: true,
},
};

export default registeredButtons;
95 changes: 82 additions & 13 deletions command-handler/src/commands/vm.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,107 @@
import hetzner from '../util/hetzner-servers.js'
import hetzner from '../util/hetzner/hetzner-servers.js';
import aws from '../util/aws/aws-server.js';

export default {
description: 'Sets up vm options',

button: async ({ app, actionId, body, response }) => {
if (actionId === 'button_list_servers') {
//list hetzner servers
hetzner.listServers({ app, body })

await aws.listServers({ app, body });
await hetzner.listServers({ app, body })
} else if (actionId === 'button_create_vm') {
//select the hetzner server to create before calling the create server
hetzner.selectImage({ app, body });
app.client.chat.postEphemeral({
channel: `${body.channel.id}`,
user: `${body.user.id}`,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Select a platform to create the vm in:"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "aws"
},
"action_id": "button_create_vm_aws"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "hetzner"
},
"action_id": "button_create_vm_hetzner"
}
]
}
],
text: "VM options"
})

} else if (actionId.startsWith('button_start')) {
const vmid = actionId.split('_')[2];
} else if (actionId.startsWith('button_start_aws')) {
const instanceId = actionId.split('_')[3];

//start a hetzner server
aws.startServer({ app, body, instanceId });

} else if (actionId.startsWith('button_stop_aws')) {
const instanceId = actionId.split('_')[3];

//stop a hetzner server
aws.stopServer({ app, body, instanceId });

} else if (actionId.startsWith('button_delete_aws')) {
const instanceId = actionId.split('_')[3];
const serverName = actionId.split('_')[4];

//delete the server
aws.deleteServer({ app, body, instanceId, serverName })

} else if (actionId.startsWith('button_start_hetzner')) {
const vmid = actionId.split('_')[3];

//start a hetzner server
hetzner.startServer({ app, body, vmid });

} else if (actionId.startsWith('button_stop')) {
const vmid = actionId.split('_')[2];
} else if (actionId.startsWith('button_stop_hetzner')) {
const vmid = actionId.split('_')[3];

//stop a hetzner server
hetzner.stopServer({ app, body, vmid });

} else if (actionId.startsWith('button_delete')) {
const serverName = actionId.split('_')[2];
} else if (actionId.startsWith('button_delete_hetzner')) {
const serverName = actionId.split('_')[3];

//delete the server
hetzner.deleteServer({app, body, serverName})

} else if (actionId.startsWith('button_create_image')) {
const imageName = actionId.split('_')[3];
const imageID = actionId.split('_')[4];
} else if (actionId.startsWith('button_create_image_aws')) {
const imageName = actionId.split('_')[4];
const ami = actionId.split('_')[5];
aws.createServer({ app, body, imageName, ami });

} else if (actionId.startsWith('button_create_image_hetzner')) {
const imageName = actionId.split('_')[4];
const imageID = actionId.split('_')[5];
hetzner.createServer({ app, body, imageID, imageName });

} else if (actionId.startsWith('button_create_vm_hetzner')) {
//select the hetzner server to create before calling the create server
hetzner.selectImage({ app, body });

} else if (actionId.startsWith('button_create_vm_aws')) {
//select the asw server to create before calling the create server
aws.selectImage({ app, body });

} else {
response({
text: `This button is registered with the vm command, but does not have an action associated with it.`
Expand Down
Loading

0 comments on commit cf6b2c5

Please sign in to comment.