mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 23:46:05 -03:30
Begin using async/await.
This commit is contained in:
38
src/api.js
38
src/api.js
@@ -1,12 +1,6 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const API_ROOT = '/api/';
|
||||
const API_LOGIN = `${API_ROOT}login/`;
|
||||
const API_LOGOUT = `${API_ROOT}logout/`;
|
||||
const API_V2 = `${API_ROOT}v2/`;
|
||||
const API_CONFIG = `${API_V2}config/`;
|
||||
const API_PROJECTS = `${API_V2}projects/`;
|
||||
const API_ORGANIZATIONS = `${API_V2}organizations/`;
|
||||
import * as constant from './endpoints';
|
||||
|
||||
const CSRF_COOKIE_NAME = 'csrftoken';
|
||||
const CSRF_HEADER_NAME = 'X-CSRFToken';
|
||||
@@ -38,7 +32,7 @@ class APIClient {
|
||||
return authenticated;
|
||||
}
|
||||
|
||||
login (username, password, redirect = API_CONFIG) {
|
||||
async login (username, password, redirect = constant.API_CONFIG) {
|
||||
const un = encodeURIComponent(username);
|
||||
const pw = encodeURIComponent(password);
|
||||
const next = encodeURIComponent(redirect);
|
||||
@@ -46,29 +40,15 @@ class APIClient {
|
||||
const data = `username=${un}&password=${pw}&next=${next}`;
|
||||
const headers = { 'Content-Type': LOGIN_CONTENT_TYPE };
|
||||
|
||||
return this.http.get(API_LOGIN, { headers })
|
||||
.then(() => this.http.post(API_LOGIN, data, { headers }));
|
||||
try {
|
||||
await this.http.get(constant.API_LOGIN, { headers });
|
||||
await this.http.post(constant.API_LOGIN, data, { headers });
|
||||
} catch (err) {
|
||||
alert(`There was a problem logging in: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
logout () {
|
||||
return this.http.get(API_LOGOUT);
|
||||
}
|
||||
|
||||
getConfig () {
|
||||
return this.http.get(API_CONFIG);
|
||||
}
|
||||
|
||||
getProjects () {
|
||||
return this.http.get(API_PROJECTS);
|
||||
}
|
||||
|
||||
getOrganizations () {
|
||||
return this.http.get(API_ORGANIZATIONS);
|
||||
}
|
||||
|
||||
getRoot () {
|
||||
return this.http.get(API_ROOT);
|
||||
}
|
||||
BaseGet = (endpoint) => this.http.get(endpoint);
|
||||
}
|
||||
|
||||
export default new APIClient();
|
||||
|
||||
Reference in New Issue
Block a user