1
1
<template >
2
2
<div >
3
- <div v-if =" ui_env_secrets " class =" form-text alert alert-success" role =" alert" >
3
+ <div v-if =" ui_token_from_env " class =" form-text alert alert-success" role =" alert" >
4
4
Vultr config file was found in your system
5
5
</div >
6
6
<div v-else class =" form-group" >
7
7
<label
8
- >Enter the local path to your configuration INI file
8
+ >Enter Vultr API Token, it will be saved in your system
9
9
<a
10
10
href =" https://trailofbits.github.io/algo/cloud-vultr.html"
11
11
title =" https://trailofbits.github.io/algo/cloud-vultr.html"
18
18
<input
19
19
type =" text"
20
20
class =" form-control"
21
- name =" vultr_config "
21
+ name =" vultr_token "
22
22
v-bind:disabled =" ui_loading_check"
23
- v-model =" vultr_config"
23
+ v-model =" ui_token"
24
+ v-on:blur =" save_config"
24
25
/>
25
- <div v-if =" ui_env_secrets " class =" form-text alert alert-success" role =" alert" >
26
- Configuration file was found in your system. You still can change the path to it
26
+ <div v-if =" vultr_config " class =" form-text alert alert-success" role =" alert" >
27
+ The config file was saved on your system
27
28
</div >
28
29
</div >
29
30
@@ -52,7 +53,8 @@ module.exports = {
52
53
vultr_config: null ,
53
54
region: null ,
54
55
// helper variables
55
- ui_env_secrets: false ,
56
+ ui_token: null ,
57
+ ui_token_from_env: false ,
56
58
ui_loading_check: false ,
57
59
ui_loading_regions: false ,
58
60
ui_region_options: []
@@ -64,7 +66,7 @@ module.exports = {
64
66
},
65
67
computed: {
66
68
has_secrets () {
67
- return this .ui_env_secrets || this .vultr_config ;
69
+ return this .ui_token_from_env || this .vultr_config ;
68
70
},
69
71
is_valid () {
70
72
return this .has_secrets && this .region ;
@@ -82,7 +84,7 @@ module.exports = {
82
84
})
83
85
.then (response => {
84
86
if (response .has_secret ) {
85
- this .ui_env_secrets = true ;
87
+ this .ui_token_from_env = true ;
86
88
this .load_regions ();
87
89
} else if (response .error ) {
88
90
this .ui_config_error = response .error ;
@@ -92,14 +94,42 @@ module.exports = {
92
94
this .ui_loading_check = false ;
93
95
});
94
96
},
97
+ save_config () {
98
+ this .ui_loading_check = true ;
99
+ fetch (" /vultr_config" , {
100
+ method: ' post' ,
101
+ headers: {
102
+ ' Content-Type' : ' application/json'
103
+ },
104
+ body: JSON .stringify ({
105
+ token: this .ui_token
106
+ })
107
+ })
108
+ .then (r => {
109
+ if (r .status === 200 || r .status === 400 ) {
110
+ return r .json ();
111
+ }
112
+ throw new Error (r .status );
113
+ })
114
+ .then (response => {
115
+ if (' saved_to' in response) {
116
+ this .vultr_config = response .saved_to ;
117
+ } else if (response .error ) {
118
+ this .ui_config_error = response .error ;
119
+ }
120
+ })
121
+ .finally (() => {
122
+ this .ui_loading_check = false ;
123
+ });
124
+ },
95
125
load_regions () {
96
126
this .ui_loading_regions = true ;
97
127
fetch (" /vultr_regions" )
98
128
.then ((r ) => r .json ())
99
129
.then ((data ) => {
100
130
this .ui_region_options = Object .keys (data).map (k => ({
101
131
value: data[k].name ,
102
- key: data[k].name
132
+ key: data[k].DCID
103
133
}));
104
134
})
105
135
.finally (() => {
@@ -110,7 +140,7 @@ module.exports = {
110
140
let submit_value = {
111
141
region: this .region
112
142
}
113
- if (! this .ui_env_secrets ) {
143
+ if (! this .ui_token_from_env ) {
114
144
submit_value[' vultr_config' ] = this .vultr_config ;
115
145
}
116
146
this .$emit (" submit" , submit_value);
0 commit comments