Skip to content

Commit 2da62f4

Browse files
committed
Added EC2 provider
1 parent dfa2990 commit 2da62f4

File tree

3 files changed

+152
-1
lines changed

3 files changed

+152
-1
lines changed

app/server.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ async def post_exit(request):
107107
)
108108
return web.json_response(response)
109109

110+
@routes.post('/ec2_regions')
111+
async def post_exit(request):
112+
data = await request.json()
113+
client = boto3.client(
114+
'ec2',
115+
aws_access_key_id=data.get('aws_access_key'),
116+
aws_secret_access_key=data.get('aws_secret_key')
117+
)
118+
response = client.describe_regions()['Regions']
119+
return web.json_response(response)
120+
110121

111122
app = web.Application()
112123
app.router.add_routes(routes)

app/static/provider-ec2.vue

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<template>
2+
<div>
3+
<div class="form-group">
4+
<label>
5+
Enter your AWS Access Key
6+
<a
7+
href="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html"
8+
title="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html"
9+
target="_blank"
10+
rel="noreferrer noopener"
11+
class="badge bagde-pill badge-primary"
12+
>?</a
13+
>
14+
<br />
15+
Note: Make sure to use an IAM user with an acceptable policy attached
16+
(see
17+
<a
18+
href="https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md"
19+
target="_blank"
20+
rel="noreferrer noopener"
21+
>docs</a
22+
>)
23+
</label>
24+
<input
25+
type="text"
26+
class="form-control"
27+
name="aws_access_key"
28+
v-on:blur="load_regions"
29+
v-model="aws_access_key"
30+
/>
31+
</div>
32+
<div class="form-group">
33+
<label
34+
>Enter your AWS Secret Key
35+
<a
36+
href="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html"
37+
title="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html"
38+
target="_blank"
39+
rel="noreferrer noopener"
40+
class="badge bagde-pill badge-primary"
41+
>?</a
42+
></label
43+
>
44+
<input
45+
type="password"
46+
class="form-control"
47+
name="aws_secret_key"
48+
v-on:blur="load_regions"
49+
v-model="aws_secret_key"
50+
/>
51+
</div>
52+
<div class="form-group">
53+
<label v-if="region_options.length === 0"
54+
>Please enter Access key and Secret key to select region</label
55+
>
56+
<label v-if="is_loading">Loading regions...</label>
57+
<label v-if="region_options.length > 0"
58+
>What region should the server be located in?</label
59+
>
60+
<select
61+
name="region"
62+
class="form-control"
63+
v-model="region"
64+
v-bind:disabled="is_region_disabled"
65+
>
66+
<option value disabled>Select region</option>
67+
<option
68+
v-for="(region, i) in region_options"
69+
v-bind:key="i"
70+
v-bind:value="region.RegionName"
71+
>{{ region.RegionName }}</option
72+
>
73+
</select>
74+
</div>
75+
<button
76+
class="btn btn-primary"
77+
type="button"
78+
v-on:click="submit"
79+
v-bind:disabled="!is_valid"
80+
>
81+
Next
82+
</button>
83+
</div>
84+
</template>
85+
86+
<script>
87+
module.exports = {
88+
data: function() {
89+
return {
90+
// options for
91+
aws_access_key: null,
92+
aws_secret_key: null,
93+
region: null,
94+
// helper variables
95+
region_options: [],
96+
is_loading: false
97+
};
98+
},
99+
computed: {
100+
is_valid() {
101+
return this.aws_access_key && this.aws_secret_key && this.region;
102+
},
103+
is_region_disabled() {
104+
return !(this.aws_access_key && this.aws_secret_key) || this.is_loading;
105+
}
106+
},
107+
methods: {
108+
load_regions() {
109+
if (this.aws_access_key && this.aws_secret_key && this.region_options.length === 0) {
110+
this.is_loading = true;
111+
fetch('/ec2_regions', {
112+
method: 'post',
113+
headers: {
114+
'Content-Type': 'application/json'
115+
},
116+
body: JSON.stringify({
117+
aws_access_key: this.aws_access_key,
118+
aws_secret_key: this.aws_secret_key
119+
})
120+
})
121+
.then(r => r.json())
122+
.then(data => {
123+
this.region_options = data;
124+
})
125+
.finally(() => {
126+
this.is_loading = false;
127+
});
128+
}
129+
},
130+
submit() {
131+
this.$emit('submit', {
132+
aws_access_key: this.aws_access_key,
133+
aws_secret_key: this.aws_secret_key,
134+
region: this.region
135+
});
136+
}
137+
}
138+
};
139+
</script>

app/static/provider-setup.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ module.exports = {
5858
},
5959
components: {
6060
'digitalocean': window.httpVueLoader('/static/provider-do.vue'),
61-
'lightsail': window.httpVueLoader('/static/provider-lightsail.vue')
61+
'lightsail': window.httpVueLoader('/static/provider-lightsail.vue'),
62+
'ec2': window.httpVueLoader('/static/provider-ec2.vue')
6263
}
6364
};
6465
</script>

0 commit comments

Comments
 (0)