Skip to content

Commit 1bf3a80

Browse files
committed
Added Linode support
1 parent 3c6d0da commit 1bf3a80

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

app/server.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,19 @@ async def azure_regions(_):
301301
return web.json_response(regions)
302302

303303

304+
@routes.get('/linode_config')
305+
async def linode_config(_):
306+
return web.json_response({"has_secret": 'LINODE_API_TOKEN' in os.environ})
307+
308+
309+
@routes.get('/linode_regions')
310+
async def linode_config(_):
311+
async with ClientSession() as session:
312+
async with session.get('https://api.linode.com/v4/regions') as r:
313+
json_body = await r.json()
314+
return web.json_response(json_body)
315+
316+
304317
app = web.Application()
305318
app.router.add_routes(routes)
306319
app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))])

app/static/provider-linode.vue

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<template>
2+
<div>
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>
9+
<label for="id_token">
10+
Enter your API token. The token must have read and write permissions
11+
<a href="https://github.com/trailofbits/algo/blob/master/docs/cloud-linode.md" title="https://github.com/trailofbits/algo/blob/master/docs/cloud-linode.md" class="badge bagde-pill badge-primary" target="_blank" rel="noopener noreferrer">?</a>
12+
</label>
13+
<input
14+
type="text"
15+
class="form-control"
16+
id="id_token"
17+
name="linode_token"
18+
v-bind:disabled="ui_loading_check"
19+
v-model="linode_token"
20+
/>
21+
</div>
22+
<region-select v-model="region"
23+
v-bind:options="ui_region_options"
24+
v-bind:loading="ui_loading_check || ui_loading_regions"
25+
v-bind:error="ui_region_error">
26+
</region-select>
27+
<button v-on:click="submit"
28+
v-bind:disabled="!is_valid" class="btn btn-primary" type="button">Next</button>
29+
</div>
30+
</template>
31+
32+
<script>
33+
module.exports = {
34+
data: function() {
35+
return {
36+
linode_token: null,
37+
region: null,
38+
// helper variables
39+
ui_loading_check: false,
40+
ui_loading_regions: false,
41+
ui_region_error: null,
42+
ui_token_from_env: false,
43+
ui_region_options: []
44+
}
45+
},
46+
computed: {
47+
is_valid() {
48+
return (this.linode_token || this.ui_token_from_env) && this.region;
49+
}
50+
},
51+
created: function() {
52+
this.check_config();
53+
this.load_regions();
54+
},
55+
methods: {
56+
check_config() {
57+
this.ui_loading_check = true;
58+
return fetch("/linode_config")
59+
.then(r => r.json())
60+
.then(response => {
61+
if (response.has_secret) {
62+
this.ui_token_from_env = true;
63+
}
64+
})
65+
.finally(() => {
66+
this.ui_loading_check = false;
67+
});
68+
},
69+
load_regions() {
70+
this.ui_loading_regions = true;
71+
this.ui_region_error = null;
72+
const payload = this.ui_token_from_env ? {} : {
73+
token: this.hcloud_token
74+
};
75+
fetch("/linode_regions")
76+
.then((r) => {
77+
if (r.status === 200) {
78+
return r.json();
79+
}
80+
throw new Error(r.status);
81+
})
82+
.then((data) => {
83+
this.ui_region_options = data.data.map(i => ({key: i.id, value: i.id}));
84+
})
85+
.catch((err) => {
86+
this.ui_region_error = err;
87+
})
88+
.finally(() => {
89+
this.ui_loading_regions = false;
90+
});
91+
},
92+
submit() {
93+
if (this.ui_token_from_env) {
94+
this.$emit("submit", {
95+
region: this.region
96+
});
97+
} else {
98+
this.$emit("submit", {
99+
linode_token: this.linode_token,
100+
region: this.region
101+
});
102+
}
103+
}
104+
},
105+
components: {
106+
"region-select": window.httpVueLoader("/static/region-select.vue"),
107+
}
108+
};
109+
</script>

app/static/provider-setup.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = {
3434
{ name: "Google Compute Engine", alias: "gce" },
3535
{ name: "Hetzner Cloud", alias: "hetzner" },
3636
{ name: "Vultr", alias: "vultr" },
37+
{ name: "Linode", alias: "linode" },
3738
{ name: "Scaleway", alias: "scaleway" },
3839
{ name: "OpenStack (DreamCompute optimised)", alias: "openstack" },
3940
{ name: "CloudStack (Exoscale optimised)", alias: "cloudstack" },
@@ -64,7 +65,8 @@ module.exports = {
6465
'vultr': window.httpVueLoader('/static/provider-vultr.vue'),
6566
'scaleway': window.httpVueLoader('/static/provider-scaleway.vue'),
6667
'hetzner': window.httpVueLoader('/static/provider-hetzner.vue'),
67-
'azure': window.httpVueLoader('/static/provider-azure.vue')
68+
'azure': window.httpVueLoader('/static/provider-azure.vue'),
69+
'linode': window.httpVueLoader('/static/provider-linode.vue')
6870
}
6971
};
7072
</script>

0 commit comments

Comments
 (0)