Skip to content

Commit 56fbaea

Browse files
committed
Secrets from env for EC2 provider
1 parent 66aae38 commit 56fbaea

File tree

2 files changed

+137
-113
lines changed

2 files changed

+137
-113
lines changed

app/static/provider-do.vue

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
11
<template>
22
<div>
3-
<div class="form-group">
3+
<div v-if="ui_token_from_env">
4+
<div v-if="ui_token_from_env" class="form-text alert alert-success" role="alert">
5+
The token was read from the environment variable
6+
</div>
7+
</div>
8+
<div class="form-group" v-else>
49
<label for="id_do_token">
510
Enter your API token. The token must have read and write permissions
611
<a href="https://cloud.digitalocean.com/settings/api/tokens" title="https://cloud.digitalocean.com/settings/api/tokens" class="badge bagde-pill badge-primary" target="_blank" rel="noopener noreferrer">?</a>
712
</label>
8-
<div v-if="ui_token_from_env">
9-
<input
10-
type="password"
11-
class="form-control"
12-
v-bind:disabled="ui_loading_check"
13-
v-bind:value="'1234567890abcdef'"
14-
/>
15-
<div v-if="ui_token_from_env" class="form-text alert alert-success" role="alert">
16-
The token was read from the environment variable
17-
</div>
18-
</div>
19-
<div v-else>
20-
<input
21-
type="text"
22-
class="form-control"
23-
id="id_do_token"
24-
name="do_token"
25-
v-bind:disabled="ui_loading_check"
26-
v-model="do_token"
27-
@blur="load_regions"
28-
/>
29-
</div>
30-
13+
<input
14+
type="text"
15+
class="form-control"
16+
id="id_do_token"
17+
name="do_token"
18+
v-bind:disabled="ui_loading_check"
19+
v-model="do_token"
20+
@blur="load_regions"
21+
/>
3122
</div>
3223
<region-select v-model="region"
3324
v-bind:options="ui_region_options"

app/static/provider-ec2.vue

Lines changed: 122 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,67 @@
11
<template>
22
<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-
/>
3+
<div v-if="ui_config_error && ui_config_error === 'missing_boto'" class="form-text alert alert-danger" role="alert">
4+
Python module "boto3" is missing, please install it to proceed
315
</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-
/>
6+
<div v-if="ui_env_secrets" class="form-text alert alert-success" role="alert">
7+
AWS credentials were read from the environment variables
518
</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
9+
<div v-else>
10+
<div class="form-group">
11+
<label>
12+
Enter your AWS Access Key
13+
<a
14+
href="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html"
15+
title="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html"
16+
target="_blank"
17+
rel="noreferrer noopener"
18+
class="badge bagde-pill badge-primary"
19+
>?</a
20+
>
21+
<br />
22+
Note: Make sure to use an IAM user with an acceptable policy attached
23+
(see
24+
<a
25+
href="https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md"
26+
target="_blank"
27+
rel="noreferrer noopener"
28+
>docs</a
29+
>)
30+
</label>
31+
<input
32+
type="text"
33+
class="form-control"
34+
name="aws_access_key"
35+
v-on:blur="load_regions"
36+
v-model="aws_access_key"
37+
/>
38+
</div>
39+
<div class="form-group">
40+
<label
41+
>Enter your AWS Secret Key
42+
<a
43+
href="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html"
44+
title="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html"
45+
target="_blank"
46+
rel="noreferrer noopener"
47+
class="badge bagde-pill badge-primary"
48+
>?</a
49+
></label
7250
>
73-
</select>
51+
<input
52+
type="password"
53+
class="form-control"
54+
name="aws_secret_key"
55+
v-on:blur="load_regions"
56+
v-model="aws_secret_key"
57+
/>
58+
</div>
7459
</div>
60+
<region-select v-model="region"
61+
v-bind:options="ui_region_options"
62+
v-bind:loading="ui_loading_check || ui_loading_regions"
63+
v-bind:error="ui_region_error">
64+
</region-select>
7565
<button
7666
class="btn btn-primary"
7767
type="button"
@@ -87,53 +77,96 @@
8777
module.exports = {
8878
data: function() {
8979
return {
90-
// options for
9180
aws_access_key: null,
9281
aws_secret_key: null,
9382
region: null,
94-
// helper variables
95-
region_options: [],
96-
is_loading: false
83+
// ui helper variables
84+
ui_region_options: [],
85+
ui_env_secrets: null,
86+
ui_loading_check: false,
87+
ui_loading_regions: false,
88+
ui_config_error: null,
89+
ui_region_error: null
9790
};
9891
},
9992
computed: {
10093
is_valid() {
101-
return this.aws_access_key && this.aws_secret_key && this.region;
94+
return this.has_secrets && this.region;
10295
},
103-
is_region_disabled() {
104-
return !(this.aws_access_key && this.aws_secret_key) || this.is_loading;
105-
}
96+
has_secrets() {
97+
return this.ui_env_secrets || (this.aws_access_key && this.aws_secret_key);
98+
},
99+
},
100+
created: function() {
101+
this.check_config();
106102
},
107103
methods: {
104+
check_config() {
105+
this.ui_loading_check = true;
106+
fetch("/aws_config")
107+
.then(r => {
108+
if (r.status === 200 || r.status === 400) {
109+
return r.json();
110+
}
111+
throw new Error(r.status);
112+
})
113+
.then(response => {
114+
if (response.has_secret) {
115+
this.ui_env_secrets = true;
116+
this.load_regions();
117+
} else if (response.error) {
118+
this.ui_config_error = response.error;
119+
}
120+
})
121+
.finally(() => {
122+
this.ui_loading_check = false;
123+
});
124+
},
108125
load_regions() {
109-
if (this.aws_access_key && this.aws_secret_key && this.region_options.length === 0) {
110-
this.is_loading = true;
126+
if (this.has_secrets && this.ui_region_options.length === 0) {
127+
this.ui_loading_regions = true;
128+
this.ui_region_error = false;
129+
const payload = this.ui_env_secrets ? {} : {
130+
aws_access_key: this.aws_access_key,
131+
aws_secret_key: this.aws_secret_key
132+
}
111133
fetch('/ec2_regions', {
112134
method: 'post',
113135
headers: {
114136
'Content-Type': 'application/json'
115137
},
116-
body: JSON.stringify({
117-
aws_access_key: this.aws_access_key,
118-
aws_secret_key: this.aws_secret_key
119-
})
138+
body: JSON.stringify(payload)
139+
})
140+
.then((r) => {
141+
if (r.status === 200) {
142+
return r.json();
143+
}
144+
throw new Error(r.status);
120145
})
121-
.then(r => r.json())
122146
.then(data => {
123-
this.region_options = data;
147+
this.ui_region_options = data.map(i => ({key: i.RegionName, value: i.RegionName}));
148+
})
149+
.catch((err) => {
150+
this.ui_region_error = err;
124151
})
125152
.finally(() => {
126-
this.is_loading = false;
153+
this.ui_loading_regions = false;
127154
});
128155
}
129156
},
130157
submit() {
131-
this.$emit('submit', {
132-
aws_access_key: this.aws_access_key,
133-
aws_secret_key: this.aws_secret_key,
158+
let submit_value = {
134159
region: this.region
135-
});
160+
}
161+
if (!this.ui_env_secrets) {
162+
submit_value['aws_access_key'] = this.aws_access_key;
163+
submit_value['aws_secret_key'] = this.aws_secret_key;
164+
}
165+
this.$emit('submit', submit_value);
136166
}
167+
},
168+
components: {
169+
"region-select": window.httpVueLoader("/static/region-select.vue"),
137170
}
138171
};
139172
</script>

0 commit comments

Comments
 (0)