Lightsail provided added

This commit is contained in:
Ivan Gromov 2020-05-23 02:20:55 +05:00
parent 2f9fa4ddca
commit dfa2990e5a
2 changed files with 66 additions and 3 deletions

View file

@ -1,5 +1,6 @@
import asyncio
import yaml
import boto3
from os.path import join, dirname
from aiohttp import web
import concurrent.futures
@ -93,6 +94,20 @@ async def post_exit(_):
else:
sys.exit(1)
@routes.post('/lightsail_regions')
async def post_exit(request):
data = await request.json()
client = boto3.client(
'lightsail',
aws_access_key_id=data.get('aws_access_key'),
aws_secret_access_key=data.get('aws_secret_key')
)
response = client.get_regions(
includeAvailabilityZones=False
)
return web.json_response(response)
app = web.Application()
app.router.add_routes(routes)
app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))])

View file

@ -11,6 +11,7 @@
type="text"
class="form-control"
name="aws_access_key"
v-on:blur="load_regions"
v-model="aws_access_key"
/>
</div>
@ -21,8 +22,26 @@
type="password"
class="form-control"
name="aws_secret_key"
v-on:blur="load_regions"
v-model="aws_secret_key">
</div>
<div class="form-group">
<label v-if="lightsail_regions.length === 0">Please enter Access key and Secret key to select region</label>
<label v-if="is_loading">Loading regions...</label>
<label v-if="lightsail_regions.length > 0">What region should the server be located in?</label>
<select name="region"
class="form-control"
v-model="region"
v-bind:disabled="is_region_disabled">
<option value disabled>Select region</option>
<option
v-for="(region, i) in lightsail_regions"
v-bind:key="region.displayName"
v-bind:value="region.name"
>{{region.displayName}}</option>
</select>
</div>
<button class="btn btn-primary"
type="button"
v-on:click="submit"
@ -37,19 +56,48 @@ module.exports = {
data: function() {
return {
aws_access_key: null,
aws_secret_key: null
aws_secret_key: null,
region: null,
lightsail_regions: [],
is_loading: false
};
},
computed: {
is_valid() {
return this.aws_access_key && this.aws_secret_key;
return this.aws_access_key && this.aws_secret_key && this.region;
},
is_region_disabled() {
return !(this.aws_access_key && this.aws_secret_key) || this.is_loading;
}
},
methods: {
load_regions() {
if (this.aws_access_key && this.aws_secret_key && this.lightsail_regions.length === 0) {
this.is_loading = true;
fetch('/lightsail_regions', {
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
aws_access_key: this.aws_access_key,
aws_secret_key: this.aws_secret_key
})
})
.then(r => r.json())
.then(data => {
this.lightsail_regions = data.regions;
})
.finally(() => {
this.is_loading = false;
});
}
},
submit() {
this.$emit('submit', {
aws_access_key: this.aws_access_key,
aws_secret_key: this.aws_secret_key
aws_secret_key: this.aws_secret_key,
region: this.region
});
}
}