mirror of
https://github.com/trailofbits/algo.git
synced 2025-07-27 07:52:57 +02:00
Added Vultr provider
This commit is contained in:
parent
97d3fabde2
commit
97a931d3d8
3 changed files with 134 additions and 3 deletions
|
@ -3,10 +3,11 @@ import json
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import boto3
|
import boto3
|
||||||
from os.path import join, dirname
|
from os.path import join, dirname, expanduser
|
||||||
from aiohttp import web
|
from aiohttp import web, ClientSession
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
from google.auth.transport.requests import AuthorizedSession
|
from google.auth.transport.requests import AuthorizedSession
|
||||||
from google.oauth2 import service_account
|
from google.oauth2 import service_account
|
||||||
|
@ -165,6 +166,32 @@ async def gce_regions(request):
|
||||||
return web.json_response(json.loads(response.content))
|
return web.json_response(json.loads(response.content))
|
||||||
|
|
||||||
|
|
||||||
|
@routes.get('/vultr_config')
|
||||||
|
async def check_vultr_config(request):
|
||||||
|
default_path = expanduser(join('~', '.vultr.ini'))
|
||||||
|
response = {'path': None}
|
||||||
|
try:
|
||||||
|
open(default_path, 'r').read()
|
||||||
|
response['path'] = default_path
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if 'VULTR_API_CONFIG' in os.environ:
|
||||||
|
try:
|
||||||
|
open(os.environ['VULTR_API_CONFIG'], 'r').read()
|
||||||
|
response['path'] = os.environ['VULTR_API_CONFIG']
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
return web.json_response(response)
|
||||||
|
|
||||||
|
|
||||||
|
@routes.get('/vultr_regions')
|
||||||
|
async def vultr_regions(request):
|
||||||
|
async with ClientSession() as session:
|
||||||
|
async with session.get('https://api.vultr.com/v1/regions/list') as r:
|
||||||
|
json_body = await r.json()
|
||||||
|
return web.json_response(json_body)
|
||||||
|
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
app.router.add_routes(routes)
|
app.router.add_routes(routes)
|
||||||
app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))])
|
app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))])
|
||||||
|
|
|
@ -60,7 +60,8 @@ module.exports = {
|
||||||
'digitalocean': window.httpVueLoader('/static/provider-do.vue'),
|
'digitalocean': window.httpVueLoader('/static/provider-do.vue'),
|
||||||
'lightsail': window.httpVueLoader('/static/provider-lightsail.vue'),
|
'lightsail': window.httpVueLoader('/static/provider-lightsail.vue'),
|
||||||
'ec2': window.httpVueLoader('/static/provider-ec2.vue'),
|
'ec2': window.httpVueLoader('/static/provider-ec2.vue'),
|
||||||
'gce': window.httpVueLoader('/static/provider-gce.vue')
|
'gce': window.httpVueLoader('/static/provider-gce.vue'),
|
||||||
|
'vultr': window.httpVueLoader('/static/provider-vultr.vue')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
103
app/static/provider-vultr.vue
Normal file
103
app/static/provider-vultr.vue
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label
|
||||||
|
>Enter the local path to your configuration INI file
|
||||||
|
<a
|
||||||
|
href="https://trailofbits.github.io/algo/cloud-vultr.html"
|
||||||
|
title="https://trailofbits.github.io/algo/cloud-vultr.html"
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer noopener"
|
||||||
|
class="badge bagde-pill badge-primary"
|
||||||
|
>?</a
|
||||||
|
></label
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="form-control"
|
||||||
|
name="vultr_config"
|
||||||
|
v-bind:disabled="ui_loading_check"
|
||||||
|
v-model="vultr_config"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<region-select v-model="region"
|
||||||
|
v-bind:options="ui_region_options"
|
||||||
|
v-bind:loading="ui_loading_check || ui_loading_regions">
|
||||||
|
</region-select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="btn btn-primary"
|
||||||
|
type="button"
|
||||||
|
v-on:click="submit"
|
||||||
|
v-bind:disabled="!is_valid"
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
module.exports = {
|
||||||
|
data: function () {
|
||||||
|
return {
|
||||||
|
vultr_config: null,
|
||||||
|
region: null,
|
||||||
|
// helper variables
|
||||||
|
ui_loading_check: false,
|
||||||
|
ui_loading_regions: false,
|
||||||
|
ui_region_options: []
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created: function() {
|
||||||
|
this.check_config();
|
||||||
|
this.load_regions();
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
is_valid() {
|
||||||
|
return this.vultr_config && this.region;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
check_config() {
|
||||||
|
this.ui_loading_check = true;
|
||||||
|
fetch("/vultr_config")
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(response => {
|
||||||
|
if (response.path) {
|
||||||
|
this.vultr_config = response.path;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.ui_loading_check = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
load_regions() {
|
||||||
|
this.ui_loading_regions = true;
|
||||||
|
fetch("/vultr_regions")
|
||||||
|
.then((r) => r.json())
|
||||||
|
.then((data) => {
|
||||||
|
this.ui_region_options = Object.keys(data).map(k => ({
|
||||||
|
value: data[k].name,
|
||||||
|
key: data[k].name
|
||||||
|
}));
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.ui_loading_regions = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
submit() {
|
||||||
|
this.$emit("submit", {
|
||||||
|
vultr_config: this.vultr_config,
|
||||||
|
region: this.region
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
"region-select": window.httpVueLoader("/static/region-select.vue"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
Add table
Reference in a new issue