mirror of
https://github.com/trailofbits/algo.git
synced 2025-09-10 05:53:27 +02:00
Draft for GCE
This commit is contained in:
parent
2da62f4877
commit
149e7dd019
2 changed files with 85 additions and 1 deletions
|
@ -1,12 +1,16 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import boto3
|
import boto3
|
||||||
from os.path import join, dirname
|
from os.path import join, dirname
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import sys
|
import sys
|
||||||
from playbook import PlaybookCLI
|
|
||||||
|
|
||||||
|
from google.auth.transport.requests import AuthorizedSession
|
||||||
|
from google.oauth2 import service_account
|
||||||
|
from playbook import PlaybookCLI
|
||||||
|
|
||||||
routes = web.RouteTableDef()
|
routes = web.RouteTableDef()
|
||||||
PROJECT_ROOT = dirname(dirname(__file__))
|
PROJECT_ROOT = dirname(dirname(__file__))
|
||||||
|
@ -87,6 +91,7 @@ async def post_config(request):
|
||||||
f.write(config)
|
f.write(config)
|
||||||
return web.json_response({'ok': True})
|
return web.json_response({'ok': True})
|
||||||
|
|
||||||
|
|
||||||
@routes.post('/exit')
|
@routes.post('/exit')
|
||||||
async def post_exit(_):
|
async def post_exit(_):
|
||||||
if task_future and task_future.done():
|
if task_future and task_future.done():
|
||||||
|
@ -94,6 +99,7 @@ async def post_exit(_):
|
||||||
else:
|
else:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@routes.post('/lightsail_regions')
|
@routes.post('/lightsail_regions')
|
||||||
async def post_exit(request):
|
async def post_exit(request):
|
||||||
data = await request.json()
|
data = await request.json()
|
||||||
|
@ -107,6 +113,7 @@ async def post_exit(request):
|
||||||
)
|
)
|
||||||
return web.json_response(response)
|
return web.json_response(response)
|
||||||
|
|
||||||
|
|
||||||
@routes.post('/ec2_regions')
|
@routes.post('/ec2_regions')
|
||||||
async def post_exit(request):
|
async def post_exit(request):
|
||||||
data = await request.json()
|
data = await request.json()
|
||||||
|
@ -119,6 +126,20 @@ async def post_exit(request):
|
||||||
return web.json_response(response)
|
return web.json_response(response)
|
||||||
|
|
||||||
|
|
||||||
|
@routes.post('/gce_regions')
|
||||||
|
async def post_exit(request):
|
||||||
|
#data = await request.json()
|
||||||
|
gce_config_file = 'configs/gce.json' # 'data.get('gce_config_file')
|
||||||
|
project_id = json.loads(open(gce_config_file, 'r').read())['project_id']
|
||||||
|
|
||||||
|
response = AuthorizedSession(
|
||||||
|
service_account.Credentials.from_service_account_file(gce_config_file).with_scopes(
|
||||||
|
['https://www.googleapis.com/auth/compute'])).get(
|
||||||
|
'https://www.googleapis.com/compute/v1/projects/{project_id}/regions'.format(project_id=project_id))
|
||||||
|
|
||||||
|
return web.json_response(json.loads(response.content))
|
||||||
|
|
||||||
|
|
||||||
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'))])
|
||||||
|
|
63
app/static/provider-gce.vue
Normal file
63
app/static/provider-gce.vue
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<template>
|
||||||
|
<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 {
|
||||||
|
gce_credentials_file: null,
|
||||||
|
region: null,
|
||||||
|
// helper variables
|
||||||
|
region_options: [],
|
||||||
|
is_loading: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
is_valid() {
|
||||||
|
return this.gce_credentials_file && this.region;
|
||||||
|
},
|
||||||
|
is_region_disabled() {
|
||||||
|
return !(this.gce_credentials_file) || this.is_loading;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
load_regions() {
|
||||||
|
if (this.gce_credentials_file && this.region_options.length === 0) {
|
||||||
|
this.is_loading = true;
|
||||||
|
fetch('/gce_regions', {
|
||||||
|
method: 'post',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
gce_credentials_file: this.gce_credentials_file
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(data => {
|
||||||
|
this.region_options = data;
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.is_loading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
submit() {
|
||||||
|
this.$emit('submit', {
|
||||||
|
gce_credentials_file: this.gce_credentials_file,
|
||||||
|
region: this.region
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
Add table
Reference in a new issue