mirror of
https://github.com/trailofbits/algo.git
synced 2025-07-13 17:22:56 +02:00
Added Azure provider
This commit is contained in:
parent
e8873870eb
commit
00271f27a5
3 changed files with 146 additions and 1 deletions
|
@ -32,6 +32,14 @@ try:
|
|||
except ImportError:
|
||||
HAS_GOOGLE_LIBRARIES = False
|
||||
|
||||
try:
|
||||
from azure.mgmt.automation import AutomationClient
|
||||
import azure.mgmt.automation.models as AutomationModel
|
||||
|
||||
HAS_AZURE_LIBRARIES = True
|
||||
except ImportError:
|
||||
HAS_AZURE_LIBRARIES = False
|
||||
|
||||
routes = web.RouteTableDef()
|
||||
PROJECT_ROOT = dirname(dirname(__file__))
|
||||
pool = None
|
||||
|
@ -253,6 +261,46 @@ async def check_scaleway_config(_):
|
|||
return web.json_response({"has_secret": 'SCW_TOKEN' in os.environ})
|
||||
|
||||
|
||||
@routes.get('/hetzner_config')
|
||||
async def check_hetzner_config(_):
|
||||
return web.json_response({"has_secret": 'HCLOUD_TOKEN' in os.environ})
|
||||
|
||||
|
||||
@routes.post('/hetzner_regions')
|
||||
async def hetzner_regions(request):
|
||||
data = await request.json()
|
||||
token = data.get('token', os.environ.get('HCLOUD_TOKEN'))
|
||||
if not token:
|
||||
return web.json_response({'error': 'no token provided'}, status=400)
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer {0}'.format(token),
|
||||
}
|
||||
async with ClientSession(headers=headers) as session:
|
||||
async with session.get('https://api.hetzner.cloud/v1/datacenters') as r:
|
||||
json_body = await r.json()
|
||||
return web.json_response(json_body)
|
||||
|
||||
|
||||
@routes.get('/azure_config')
|
||||
async def azure_config(_):
|
||||
if not HAS_REQUESTS:
|
||||
return web.json_response({'error': 'missing_requests'}, status=400)
|
||||
if not HAS_AZURE_LIBRARIES:
|
||||
return web.json_response({'error': 'missing_azure'}, status=400)
|
||||
response = {'status': 'ok'}
|
||||
return web.json_response(response)
|
||||
|
||||
|
||||
@routes.get('/azure_regions')
|
||||
async def azure_regions(_):
|
||||
with open(join(PROJECT_ROOT, 'roles', 'cloud-azure', 'defaults', 'main.yml'), 'r') as f:
|
||||
regions_json = yaml.safe_load(f.read())
|
||||
regions = json.loads(regions_json['_azure_regions'])
|
||||
return web.json_response(regions)
|
||||
|
||||
|
||||
app = web.Application()
|
||||
app.router.add_routes(routes)
|
||||
app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))])
|
||||
|
|
96
app/static/provider-azure.vue
Normal file
96
app/static/provider-azure.vue
Normal file
|
@ -0,0 +1,96 @@
|
|||
<template>
|
||||
<div>
|
||||
<div v-if="ui_config_error && ui_config_error === 'missing_requests'" class="form-text alert alert-danger" role="alert">
|
||||
Python module "requests" is missing, please install it to proceed
|
||||
</div>
|
||||
<div v-if="ui_config_error && ui_config_error === 'missing_azure'" class="form-text alert alert-danger" role="alert">
|
||||
Python Azure SDK libraries are missing, please install it to proceed
|
||||
</div>
|
||||
<div class="form-text alert alert-info" role="alert">
|
||||
<strong>Prerequisites:</strong> <a href="https://github.com/trailofbits/algo/blob/master/docs/cloud-azure.md"
|
||||
target="_blank" rel="noopener noreferrer">Install azure-cli</a>
|
||||
</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 {
|
||||
region: null,
|
||||
// helper variables
|
||||
ui_loading_check: false,
|
||||
ui_config_error: false,
|
||||
ui_loading_regions: false,
|
||||
ui_region_error: null,
|
||||
ui_region_options: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
is_valid() {
|
||||
return !!this.region;
|
||||
}
|
||||
},
|
||||
created: function () {
|
||||
this.check_config();
|
||||
},
|
||||
methods: {
|
||||
check_config() {
|
||||
this.ui_loading_check = true;
|
||||
fetch("/azure_config")
|
||||
.then(r => {
|
||||
if (r.status === 200 || r.status === 400) {
|
||||
return r.json();
|
||||
}
|
||||
throw new Error(r.status);
|
||||
})
|
||||
.then(response => {
|
||||
if (response.status === 'ok') {
|
||||
this.load_regions();
|
||||
} else if (response.error) {
|
||||
this.ui_config_error = response.error;
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.ui_loading_check = false;
|
||||
});
|
||||
},
|
||||
load_regions() {
|
||||
this.ui_loading_regions = true;
|
||||
this.ui_region_error = null;
|
||||
fetch("/azure_regions")
|
||||
.then((r) => {
|
||||
if (r.status === 200) {
|
||||
return r.json();
|
||||
}
|
||||
throw new Error(r.status);
|
||||
})
|
||||
.then((data) => {
|
||||
this.ui_region_options = data.map(i => ({key: i.name, value: i.displayName}));
|
||||
})
|
||||
.catch((err) => {
|
||||
this.ui_region_error = err;
|
||||
})
|
||||
.finally(() => {
|
||||
this.ui_loading_regions = false;
|
||||
});
|
||||
},
|
||||
submit() {
|
||||
this.$emit("submit", {
|
||||
region: this.region
|
||||
});
|
||||
}
|
||||
},
|
||||
components: {
|
||||
"region-select": window.httpVueLoader("/static/region-select.vue"),
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -63,7 +63,8 @@ module.exports = {
|
|||
'gce': window.httpVueLoader('/static/provider-gce.vue'),
|
||||
'vultr': window.httpVueLoader('/static/provider-vultr.vue'),
|
||||
'scaleway': window.httpVueLoader('/static/provider-scaleway.vue'),
|
||||
'hetzner': window.httpVueLoader('/static/provider-hetzner.vue')
|
||||
'hetzner': window.httpVueLoader('/static/provider-hetzner.vue'),
|
||||
'azure': window.httpVueLoader('/static/provider-azure.vue')
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Add table
Reference in a new issue