mirror of
https://github.com/trailofbits/algo.git
synced 2025-07-13 17:22:56 +02:00
Added Linode support
This commit is contained in:
parent
00271f27a5
commit
01bd17d361
3 changed files with 125 additions and 1 deletions
|
@ -301,6 +301,19 @@ async def azure_regions(_):
|
|||
return web.json_response(regions)
|
||||
|
||||
|
||||
@routes.get('/linode_config')
|
||||
async def linode_config(_):
|
||||
return web.json_response({"has_secret": 'LINODE_API_TOKEN' in os.environ})
|
||||
|
||||
|
||||
@routes.get('/linode_regions')
|
||||
async def linode_config(_):
|
||||
async with ClientSession() as session:
|
||||
async with session.get('https://api.linode.com/v4/regions') as r:
|
||||
json_body = await r.json()
|
||||
return web.json_response(json_body)
|
||||
|
||||
|
||||
app = web.Application()
|
||||
app.router.add_routes(routes)
|
||||
app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))])
|
||||
|
|
109
app/static/provider-linode.vue
Normal file
109
app/static/provider-linode.vue
Normal file
|
@ -0,0 +1,109 @@
|
|||
<template>
|
||||
<div>
|
||||
<div v-if="ui_token_from_env">
|
||||
<div v-if="ui_token_from_env" class="form-text alert alert-success" role="alert">
|
||||
The token was read from the environment variable
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" v-else>
|
||||
<label for="id_token">
|
||||
Enter your API token. The token must have read and write permissions
|
||||
<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>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="id_token"
|
||||
name="linode_token"
|
||||
v-bind:disabled="ui_loading_check"
|
||||
v-model="linode_token"
|
||||
/>
|
||||
</div>
|
||||
<region-select v-model="region"
|
||||
v-bind:options="ui_region_options"
|
||||
v-bind:loading="ui_loading_check || ui_loading_regions"
|
||||
v-bind:error="ui_region_error">
|
||||
</region-select>
|
||||
<button v-on:click="submit"
|
||||
v-bind:disabled="!is_valid" class="btn btn-primary" type="button">Next</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
module.exports = {
|
||||
data: function() {
|
||||
return {
|
||||
linode_token: null,
|
||||
region: null,
|
||||
// helper variables
|
||||
ui_loading_check: false,
|
||||
ui_loading_regions: false,
|
||||
ui_region_error: null,
|
||||
ui_token_from_env: false,
|
||||
ui_region_options: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
is_valid() {
|
||||
return (this.linode_token || this.ui_token_from_env) && this.region;
|
||||
}
|
||||
},
|
||||
created: function() {
|
||||
this.check_config();
|
||||
this.load_regions();
|
||||
},
|
||||
methods: {
|
||||
check_config() {
|
||||
this.ui_loading_check = true;
|
||||
return fetch("/linode_config")
|
||||
.then(r => r.json())
|
||||
.then(response => {
|
||||
if (response.has_secret) {
|
||||
this.ui_token_from_env = true;
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.ui_loading_check = false;
|
||||
});
|
||||
},
|
||||
load_regions() {
|
||||
this.ui_loading_regions = true;
|
||||
this.ui_region_error = null;
|
||||
const payload = this.ui_token_from_env ? {} : {
|
||||
token: this.hcloud_token
|
||||
};
|
||||
fetch("/linode_regions")
|
||||
.then((r) => {
|
||||
if (r.status === 200) {
|
||||
return r.json();
|
||||
}
|
||||
throw new Error(r.status);
|
||||
})
|
||||
.then((data) => {
|
||||
this.ui_region_options = data.data.map(i => ({key: i.id, value: i.id}));
|
||||
})
|
||||
.catch((err) => {
|
||||
this.ui_region_error = err;
|
||||
})
|
||||
.finally(() => {
|
||||
this.ui_loading_regions = false;
|
||||
});
|
||||
},
|
||||
submit() {
|
||||
if (this.ui_token_from_env) {
|
||||
this.$emit("submit", {
|
||||
region: this.region
|
||||
});
|
||||
} else {
|
||||
this.$emit("submit", {
|
||||
linode_token: this.linode_token,
|
||||
region: this.region
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
components: {
|
||||
"region-select": window.httpVueLoader("/static/region-select.vue"),
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -34,6 +34,7 @@ module.exports = {
|
|||
{ name: "Google Compute Engine", alias: "gce" },
|
||||
{ name: "Hetzner Cloud", alias: "hetzner" },
|
||||
{ name: "Vultr", alias: "vultr" },
|
||||
{ name: "Linode", alias: "linode" },
|
||||
{ name: "Scaleway", alias: "scaleway" },
|
||||
{ name: "OpenStack (DreamCompute optimised)", alias: "openstack" },
|
||||
{ name: "CloudStack (Exoscale optimised)", alias: "cloudstack" },
|
||||
|
@ -64,7 +65,8 @@ module.exports = {
|
|||
'vultr': window.httpVueLoader('/static/provider-vultr.vue'),
|
||||
'scaleway': window.httpVueLoader('/static/provider-scaleway.vue'),
|
||||
'hetzner': window.httpVueLoader('/static/provider-hetzner.vue'),
|
||||
'azure': window.httpVueLoader('/static/provider-azure.vue')
|
||||
'azure': window.httpVueLoader('/static/provider-azure.vue'),
|
||||
'linode': window.httpVueLoader('/static/provider-linode.vue')
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Add table
Reference in a new issue