Skip to content

Commit d860295

Browse files
committed
Added Vultr provider
1 parent 23a0583 commit d860295

File tree

3 files changed

+134
-3
lines changed

3 files changed

+134
-3
lines changed

app/server.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
import yaml
55
import boto3
6-
from os.path import join, dirname
7-
from aiohttp import web
6+
from os.path import join, dirname, expanduser
7+
from aiohttp import web, ClientSession
88
import concurrent.futures
99
import sys
10+
import os
1011

1112
from google.auth.transport.requests import AuthorizedSession
1213
from google.oauth2 import service_account
@@ -165,6 +166,32 @@ async def gce_regions(request):
165166
return web.json_response(json.loads(response.content))
166167

167168

169+
@routes.get('/vultr_config')
170+
async def check_vultr_config(request):
171+
default_path = expanduser(join('~', '.vultr.ini'))
172+
response = {'path': None}
173+
try:
174+
open(default_path, 'r').read()
175+
response['path'] = default_path
176+
except IOError:
177+
pass
178+
179+
if 'VULTR_API_CONFIG' in os.environ:
180+
try:
181+
open(os.environ['VULTR_API_CONFIG'], 'r').read()
182+
response['path'] = os.environ['VULTR_API_CONFIG']
183+
except IOError:
184+
pass
185+
return web.json_response(response)
186+
187+
188+
@routes.get('/vultr_regions')
189+
async def vultr_regions(request):
190+
async with ClientSession() as session:
191+
async with session.get('https://api.vultr.com/v1/regions/list') as r:
192+
json_body = await r.json()
193+
return web.json_response(json_body)
194+
168195
app = web.Application()
169196
app.router.add_routes(routes)
170197
app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))])

app/static/provider-setup.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ module.exports = {
6060
'digitalocean': window.httpVueLoader('/static/provider-do.vue'),
6161
'lightsail': window.httpVueLoader('/static/provider-lightsail.vue'),
6262
'ec2': window.httpVueLoader('/static/provider-ec2.vue'),
63-
'gce': window.httpVueLoader('/static/provider-gce.vue')
63+
'gce': window.httpVueLoader('/static/provider-gce.vue'),
64+
'vultr': window.httpVueLoader('/static/provider-vultr.vue')
6465
}
6566
};
6667
</script>

app/static/provider-vultr.vue

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<template>
2+
<div>
3+
4+
<div class="form-group">
5+
<label
6+
>Enter the local path to your configuration INI file
7+
<a
8+
href="https://trailofbits.github.io/algo/cloud-vultr.html"
9+
title="https://trailofbits.github.io/algo/cloud-vultr.html"
10+
target="_blank"
11+
rel="noreferrer noopener"
12+
class="badge bagde-pill badge-primary"
13+
>?</a
14+
></label
15+
>
16+
<input
17+
type="text"
18+
class="form-control"
19+
name="vultr_config"
20+
v-bind:disabled="ui_loading_check"
21+
v-model="vultr_config"
22+
/>
23+
</div>
24+
25+
<div class="form-group">
26+
<region-select v-model="region"
27+
v-bind:options="ui_region_options"
28+
v-bind:loading="ui_loading_check || ui_loading_regions">
29+
</region-select>
30+
</div>
31+
32+
<button
33+
class="btn btn-primary"
34+
type="button"
35+
v-on:click="submit"
36+
v-bind:disabled="!is_valid"
37+
>
38+
Next
39+
</button>
40+
</div>
41+
</template>
42+
43+
<script>
44+
module.exports = {
45+
data: function () {
46+
return {
47+
vultr_config: null,
48+
region: null,
49+
// helper variables
50+
ui_loading_check: false,
51+
ui_loading_regions: false,
52+
ui_region_options: []
53+
};
54+
},
55+
created: function() {
56+
this.check_config();
57+
this.load_regions();
58+
},
59+
computed: {
60+
is_valid() {
61+
return this.vultr_config && this.region;
62+
}
63+
},
64+
methods: {
65+
check_config() {
66+
this.ui_loading_check = true;
67+
fetch("/vultr_config")
68+
.then(r => r.json())
69+
.then(response => {
70+
if (response.path) {
71+
this.vultr_config = response.path;
72+
}
73+
})
74+
.finally(() => {
75+
this.ui_loading_check = false;
76+
});
77+
},
78+
load_regions() {
79+
this.ui_loading_regions = true;
80+
fetch("/vultr_regions")
81+
.then((r) => r.json())
82+
.then((data) => {
83+
this.ui_region_options = Object.keys(data).map(k => ({
84+
value: data[k].name,
85+
key: data[k].name
86+
}));
87+
})
88+
.finally(() => {
89+
this.ui_loading_regions = false;
90+
});
91+
},
92+
submit() {
93+
this.$emit("submit", {
94+
vultr_config: this.vultr_config,
95+
region: this.region
96+
});
97+
},
98+
},
99+
components: {
100+
"region-select": window.httpVueLoader("/static/region-select.vue"),
101+
},
102+
};
103+
</script>

0 commit comments

Comments
 (0)