mirror of
https://github.com/trailofbits/algo.git
synced 2025-07-14 01:32:55 +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 json
|
||||
|
||||
import yaml
|
||||
import boto3
|
||||
from os.path import join, dirname
|
||||
from aiohttp import web
|
||||
import concurrent.futures
|
||||
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()
|
||||
PROJECT_ROOT = dirname(dirname(__file__))
|
||||
|
@ -87,6 +91,7 @@ async def post_config(request):
|
|||
f.write(config)
|
||||
return web.json_response({'ok': True})
|
||||
|
||||
|
||||
@routes.post('/exit')
|
||||
async def post_exit(_):
|
||||
if task_future and task_future.done():
|
||||
|
@ -94,6 +99,7 @@ async def post_exit(_):
|
|||
else:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@routes.post('/lightsail_regions')
|
||||
async def post_exit(request):
|
||||
data = await request.json()
|
||||
|
@ -107,6 +113,7 @@ async def post_exit(request):
|
|||
)
|
||||
return web.json_response(response)
|
||||
|
||||
|
||||
@routes.post('/ec2_regions')
|
||||
async def post_exit(request):
|
||||
data = await request.json()
|
||||
|
@ -119,6 +126,20 @@ async def post_exit(request):
|
|||
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.router.add_routes(routes)
|
||||
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