mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 23:46:05 -03:30
Merge pull request #1343 from jakemcdermott/oauth_n_session
ui tooling fixes / updates for oauth changes
This commit is contained in:
@@ -52,7 +52,7 @@ const watch = {
|
|||||||
publicPath: '/static/',
|
publicPath: '/static/',
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
port: 3000,
|
port: 3000,
|
||||||
https: true
|
https: true,
|
||||||
proxy: {
|
proxy: {
|
||||||
'/': {
|
'/': {
|
||||||
target: TARGET,
|
target: TARGET,
|
||||||
|
|||||||
@@ -8,15 +8,17 @@ import {
|
|||||||
AWX_E2E_PASSWORD
|
AWX_E2E_PASSWORD
|
||||||
} from './settings';
|
} from './settings';
|
||||||
|
|
||||||
let authenticated;
|
|
||||||
|
|
||||||
const session = axios.create({
|
const session = axios.create({
|
||||||
baseURL: AWX_E2E_URL,
|
baseURL: AWX_E2E_URL,
|
||||||
xsrfHeaderName: 'X-CSRFToken',
|
xsrfHeaderName: 'X-CSRFToken',
|
||||||
xsrfCookieName: 'csrftoken',
|
xsrfCookieName: 'csrftoken',
|
||||||
httpsAgent: new https.Agent({
|
httpsAgent: new https.Agent({
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
})
|
}),
|
||||||
|
auth: {
|
||||||
|
username: AWX_E2E_USERNAME,
|
||||||
|
password: AWX_E2E_PASSWORD
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const getEndpoint = location => {
|
const getEndpoint = location => {
|
||||||
@@ -27,36 +29,15 @@ const getEndpoint = location => {
|
|||||||
return `${AWX_E2E_URL}/api/v2${location}`;
|
return `${AWX_E2E_URL}/api/v2${location}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const authenticate = () => {
|
|
||||||
if (authenticated) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
const uri = getEndpoint('/authtoken/');
|
|
||||||
|
|
||||||
const credentials = {
|
|
||||||
username: AWX_E2E_USERNAME,
|
|
||||||
password: AWX_E2E_PASSWORD
|
|
||||||
};
|
|
||||||
|
|
||||||
return session.post(uri, credentials).then(res => {
|
|
||||||
session.defaults.headers.Authorization = `Token ${res.data.token}`;
|
|
||||||
authenticated = true;
|
|
||||||
|
|
||||||
return res;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const request = (method, location, data) => {
|
const request = (method, location, data) => {
|
||||||
const uri = getEndpoint(location);
|
const uri = getEndpoint(location);
|
||||||
const action = session[method.toLowerCase()];
|
const action = session[method.toLowerCase()];
|
||||||
|
|
||||||
return authenticate()
|
return action(uri, data)
|
||||||
.then(() => action(uri, data))
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log([ // eslint-disable-line no-console
|
console.log([ // eslint-disable-line no-console
|
||||||
res.config.method.toUpperCase(),
|
res.config.method.toUpperCase(),
|
||||||
uri,
|
res.config.url,
|
||||||
res.status,
|
res.status,
|
||||||
res.statusText
|
res.statusText
|
||||||
].join(' '));
|
].join(' '));
|
||||||
|
|||||||
Reference in New Issue
Block a user