|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <div class="form-group"> |
| 4 | + <label> |
| 5 | + Enter your AWS Access Key |
| 6 | + <a |
| 7 | + href="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html" |
| 8 | + title="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html" |
| 9 | + target="_blank" |
| 10 | + rel="noreferrer noopener" |
| 11 | + class="badge bagde-pill badge-primary" |
| 12 | + >?</a |
| 13 | + > |
| 14 | + <br /> |
| 15 | + Note: Make sure to use an IAM user with an acceptable policy attached |
| 16 | + (see |
| 17 | + <a |
| 18 | + href="https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md" |
| 19 | + target="_blank" |
| 20 | + rel="noreferrer noopener" |
| 21 | + >docs</a |
| 22 | + >) |
| 23 | + </label> |
| 24 | + <input |
| 25 | + type="text" |
| 26 | + class="form-control" |
| 27 | + name="aws_access_key" |
| 28 | + v-on:blur="load_regions" |
| 29 | + v-model="aws_access_key" |
| 30 | + /> |
| 31 | + </div> |
| 32 | + <div class="form-group"> |
| 33 | + <label |
| 34 | + >Enter your AWS Secret Key |
| 35 | + <a |
| 36 | + href="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html" |
| 37 | + title="http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html" |
| 38 | + target="_blank" |
| 39 | + rel="noreferrer noopener" |
| 40 | + class="badge bagde-pill badge-primary" |
| 41 | + >?</a |
| 42 | + ></label |
| 43 | + > |
| 44 | + <input |
| 45 | + type="password" |
| 46 | + class="form-control" |
| 47 | + name="aws_secret_key" |
| 48 | + v-on:blur="load_regions" |
| 49 | + v-model="aws_secret_key" |
| 50 | + /> |
| 51 | + </div> |
| 52 | + <div class="form-group"> |
| 53 | + <label v-if="region_options.length === 0" |
| 54 | + >Please enter Access key and Secret key to select region</label |
| 55 | + > |
| 56 | + <label v-if="is_loading">Loading regions...</label> |
| 57 | + <label v-if="region_options.length > 0" |
| 58 | + >What region should the server be located in?</label |
| 59 | + > |
| 60 | + <select |
| 61 | + name="region" |
| 62 | + class="form-control" |
| 63 | + v-model="region" |
| 64 | + v-bind:disabled="is_region_disabled" |
| 65 | + > |
| 66 | + <option value disabled>Select region</option> |
| 67 | + <option |
| 68 | + v-for="(region, i) in region_options" |
| 69 | + v-bind:key="i" |
| 70 | + v-bind:value="region.RegionName" |
| 71 | + >{{ region.RegionName }}</option |
| 72 | + > |
| 73 | + </select> |
| 74 | + </div> |
| 75 | + <button |
| 76 | + class="btn btn-primary" |
| 77 | + type="button" |
| 78 | + v-on:click="submit" |
| 79 | + v-bind:disabled="!is_valid" |
| 80 | + > |
| 81 | + Next |
| 82 | + </button> |
| 83 | + </div> |
| 84 | +</template> |
| 85 | + |
| 86 | +<script> |
| 87 | +module.exports = { |
| 88 | + data: function() { |
| 89 | + return { |
| 90 | + // options for |
| 91 | + aws_access_key: null, |
| 92 | + aws_secret_key: null, |
| 93 | + region: null, |
| 94 | + // helper variables |
| 95 | + region_options: [], |
| 96 | + is_loading: false |
| 97 | + }; |
| 98 | + }, |
| 99 | + computed: { |
| 100 | + is_valid() { |
| 101 | + return this.aws_access_key && this.aws_secret_key && this.region; |
| 102 | + }, |
| 103 | + is_region_disabled() { |
| 104 | + return !(this.aws_access_key && this.aws_secret_key) || this.is_loading; |
| 105 | + } |
| 106 | + }, |
| 107 | + methods: { |
| 108 | + load_regions() { |
| 109 | + if (this.aws_access_key && this.aws_secret_key && this.region_options.length === 0) { |
| 110 | + this.is_loading = true; |
| 111 | + fetch('/ec2_regions', { |
| 112 | + method: 'post', |
| 113 | + headers: { |
| 114 | + 'Content-Type': 'application/json' |
| 115 | + }, |
| 116 | + body: JSON.stringify({ |
| 117 | + aws_access_key: this.aws_access_key, |
| 118 | + aws_secret_key: this.aws_secret_key |
| 119 | + }) |
| 120 | + }) |
| 121 | + .then(r => r.json()) |
| 122 | + .then(data => { |
| 123 | + this.region_options = data; |
| 124 | + }) |
| 125 | + .finally(() => { |
| 126 | + this.is_loading = false; |
| 127 | + }); |
| 128 | + } |
| 129 | + }, |
| 130 | + submit() { |
| 131 | + this.$emit('submit', { |
| 132 | + aws_access_key: this.aws_access_key, |
| 133 | + aws_secret_key: this.aws_secret_key, |
| 134 | + region: this.region |
| 135 | + }); |
| 136 | + } |
| 137 | + } |
| 138 | +}; |
| 139 | +</script> |
0 commit comments