Compare commits

...

14 Commits

Author SHA1 Message Date
Frank Jogeleit
5d7e3ef283 Merge pull request #5 from fjogeleit/fix-bearer-token-header
Fix Header Name for Bearer Authorization
2020-05-06 20:45:21 +02:00
Frank
089a11111a Fix Header Name for Bearer Authorization 2020-05-06 20:43:17 +02:00
Frank Jogeleit
f7cd714b2c Add Test Action (#4)
* Don't apply "data" on GET Requests
* Add Test Workflow
* Add Debug output for Instance Config and Request Data
2020-04-21 14:17:51 +02:00
Frank
acd894b2e1 update readme 2020-04-21 14:16:49 +02:00
Frank
8ed097ea3f fix basic auth method 2020-04-21 14:09:38 +02:00
Frank
b9373e0ef3 add auth test 2020-04-21 14:07:56 +02:00
Frank
65d4ab42a4 add post test 2020-04-21 13:58:56 +02:00
Frank
193a7dd98c update data payload 2020-04-21 13:55:30 +02:00
Frank
3b9f5efa1c Move workflow in the right folder 2020-04-21 13:47:34 +02:00
Frank
cfc342658b Add Test Action 2020-04-21 13:44:56 +02:00
Frank
bd6ff9fa68 build actions 2020-04-21 13:30:34 +02:00
Frank
748170326f add debug statements 2020-04-21 13:24:39 +02:00
Frank Jogeleit
b52a6b1b8b Merge pull request #3 from fjogeleit/DirectApiRequestHasMoreThanOneAuthorization
remove auth config when no http basic is defined
2020-04-21 12:44:00 +02:00
Frank
8f0ce9cdaf remove auth config when no http basic is defined 2020-04-21 12:41:30 +02:00
5 changed files with 95 additions and 27 deletions

32
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,32 @@
name: Test
on: [push, pull_request]
jobs:
request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Request Postment Echo GET
uses: ./
with:
url: 'https://postman-echo.com/get'
method: 'GET'
- name: Request Postment Echo POST
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
data: '{ "key": "value" }'
- name: Request Postment Echo BasicAuth
uses: ./
with:
url: 'https://postman-echo.com/basic-auth'
method: 'GET'
username: 'postman'
password: 'password'

View File

@@ -32,3 +32,11 @@ jobs:
### Output
- `response` Request Response as JSON String
### Debug Informations
Enable Debug mode to get informations about
- Instance Configuration (Url / Timeout / Headers)
- Request Data (Body / Auth / Method)

40
dist/index.js vendored
View File

@@ -2597,7 +2597,10 @@ module.exports = function httpAdapter(config) {
const core = __webpack_require__(470);
const axios = __webpack_require__(53);
const auth = {}
const METHOD_GET = 'GET'
const METHOD_POST = 'POST'
let auth = undefined
let customHeaders = {}
if (!!core.getInput('customHeaders')) {
@@ -2610,32 +2613,43 @@ if (!!core.getInput('customHeaders')) {
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
if (!!core.getInput('username')) {
auth.username = core.getInput('username');
}
if (!!core.getInput('username') || !!core.getInput('password')) {
core.debug('Add BasicHTTP Auth config')
if (!!core.getInput('password')) {
auth.password = core.getInput('password');
auth = {
username: core.getInput('username'),
password: core.getInput('password')
}
}
if (!!core.getInput('bearerToken')) {
headers['Authentication'] = `Bearer ${core.getInput('bearerToken')}`;
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
}
const instance = axios.create({
const instanceConfig = {
baseURL: core.getInput('url', { required: true }),
timeout: parseInt(core.getInput('timeout') || 5000, 10),
headers: { ...headers, ...customHeaders }
});
}
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
const instance = axios.create(instanceConfig);
(async() => {
try {
const response = await instance.request({
const method = core.getInput('method') || METHOD_POST;
const data = method === METHOD_GET ? undefined : JSON.parse(core.getInput('data') || '{}')
const requestData = {
auth,
method: core.getInput('method') || 'POST',
data: JSON.parse(core.getInput('data') || '{}')
})
method,
data
}
core.debug('Request Data: ' + JSON.stringify(requestData))
const response = await instance.request(requestData)
core.setOutput('response', JSON.stringify(response.data))
} catch (error) {

View File

@@ -1,6 +1,6 @@
{
"name": "http-request-action",
"version": "1.0.0",
"version": "1.3.0",
"description": "",
"main": "src/index.js",
"private": false,

View File

@@ -1,7 +1,10 @@
const core = require("@actions/core");
const axios = require("axios");
const auth = {}
const METHOD_GET = 'GET'
const METHOD_POST = 'POST'
let auth = undefined
let customHeaders = {}
if (!!core.getInput('customHeaders')) {
@@ -14,32 +17,43 @@ if (!!core.getInput('customHeaders')) {
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
if (!!core.getInput('username')) {
auth.username = core.getInput('username');
}
if (!!core.getInput('username') || !!core.getInput('password')) {
core.debug('Add BasicHTTP Auth config')
if (!!core.getInput('password')) {
auth.password = core.getInput('password');
auth = {
username: core.getInput('username'),
password: core.getInput('password')
}
}
if (!!core.getInput('bearerToken')) {
headers['Authentication'] = `Bearer ${core.getInput('bearerToken')}`;
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
}
const instance = axios.create({
const instanceConfig = {
baseURL: core.getInput('url', { required: true }),
timeout: parseInt(core.getInput('timeout') || 5000, 10),
headers: { ...headers, ...customHeaders }
});
}
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
const instance = axios.create(instanceConfig);
(async() => {
try {
const response = await instance.request({
const method = core.getInput('method') || METHOD_POST;
const data = method === METHOD_GET ? undefined : JSON.parse(core.getInput('data') || '{}')
const requestData = {
auth,
method: core.getInput('method') || 'POST',
data: JSON.parse(core.getInput('data') || '{}')
})
method,
data
}
core.debug('Request Data: ' + JSON.stringify(requestData))
const response = await instance.request(requestData)
core.setOutput('response', JSON.stringify(response.data))
} catch (error) {