Skip to content

Commit

Permalink
Working on apiCall for proxmox ve rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
mhermosi committed Mar 27, 2019
1 parent b145e26 commit 938ba3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
21 changes: 9 additions & 12 deletions component/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default Ember.Component.extend(NodeDriver, {
driverName: '%%DRIVERNAME%%',
config: alias('model.%%DRIVERNAME%%Config'),
app: service(),
cookies: service(),
authToken: null,
netModelChoices: NET_MODEL_CHOICES,
step: 1,
Expand Down Expand Up @@ -153,7 +154,7 @@ export default Ember.Component.extend(NodeDriver, {
proxmoxLogin() {
let self = this;
set(self, 'errors', null);
self.apiRequest('/access/ticket').then((response) => {
self.apiRequest('POST', '/access/ticket').then((response) => {

if(response.status !== 200) {
console.log('response status !== 200 [authentication]: ', response.status );
Expand All @@ -167,16 +168,14 @@ export default Ember.Component.extend(NodeDriver, {
step: 2
});

self.apiRequest(`/nodes/${self.config.node}/network`).then((response) => {
self.apiRequest('GET', `/nodes/${self.config.node}/network`).then((response) => {
if(response.status !== 200) {
console.log('response status !== 200 [networks]: ', response.status );
return;
}
response.json().then((json) => {
console.log('response.json [networks]: ', json);
setProperties(self, {
bridges: json.data,
step: 2
bridges: json.data.filter(device => device.type === 'bridge'),
});
});
}).catch((err) => {
Expand All @@ -189,7 +188,7 @@ export default Ember.Component.extend(NodeDriver, {
});
},
},
apiRequest: function(path) {
apiRequest: function(method, path) {
let self = this;
let apiUrl = `${self.config.host}:${self.config.port}/api2/json${path}`;
let url = `${ get(this, 'app.proxyEndpoint') }/`;
Expand All @@ -204,18 +203,16 @@ export default Ember.Component.extend(NodeDriver, {
params = `username=${username}&password=${password}`;
headers.append('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
} else {
console.log(`Set-Cookie: PVEAuthCookie=${self.authToken.ticket};`);
console.log(`CSRFPreventionToken: ${self.authToken.CSRFPreventionToken}`);
console.log(`username: ${self.authToken.username}`);

headers.append('Set-Cookie', `PVEAuthCookie=${self.authToken.ticket};`);
get(this, 'cookies').setWithOptions("PVEAuthCookie", self.authToken.ticket, {
secure: 'auto'
});
headers.append("CSRFPreventionToken", self.authToken.CSRFPreventionToken);
headers.append("username", self.authToken.username);
}
headers.append('Accept', 'application/json');

return fetch(url, {
method: 'POST',
method: method,
headers: headers,
dataType: 'json',
credentials: 'include',
Expand Down
4 changes: 2 additions & 2 deletions component/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@
{{new-select
classNames="form-control"
content=bridges
optionLabelPath="name"
optionValuePath="value"
optionLabelPath="iface"
optionValuePath="iface"
value=config.netBridge
}}
<p class="text-info text-small m-0">{{get resourceFields "netBridge.description"}}</p>
Expand Down

0 comments on commit 938ba3a

Please sign in to comment.