Skip to content

Commit

Permalink
Merge pull request #22 from MuH3gPaB/curl_cookies_auth_support
Browse files Browse the repository at this point in the history
Cookie and basic auth support
  • Loading branch information
Jtalk authored Mar 2, 2023
2 parents ad6b4b0 + 75dc6c1 commit f3f7bd7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,19 @@ jobs:
max-attempts: 5
retry-delay: 2s
retry-all: true

check-single-with-basic-auth:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
name: Check single, with basic auth
steps:
- uses: actions/checkout@v2
- uses: ./
with:
url: https://postman-echo.com/basic-auth
basic-auth: "postman:password"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ steps:
retry-delay: 5s # Optional, only applicable to max-attempts > 1
# Retry all errors, including 404. This option might trigger curl upgrade.
retry-all: false # Optional, defaults to "false"
# String representation of cookie attached to health check request.
# Format: `Name=Value`
cookie: "token=asdf1234" # Optional, default is empty
# Basic auth login password pair.
# Format: `login:password`
basic-auth: "login:password" # Optional, default is empty
```
The action will fail if any of the URLs reports either 4xx or 5xx status codes.
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ inputs:
This might upgrade curl to the version supporting this flag.
required: false
default: "false"
cookie:
description: |
String representation of cookie attached to health check request.
Format: `Name=Value`
required: false
default: ""
basic-auth:
description: |
Basic auth login password pair.
Format: `login:password`
required: false
default: ""
branding:
icon: check
color: purple
Expand Down
8 changes: 7 additions & 1 deletion curl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as semver from "semver";

export async function curl(
url,
{ maxAttempts, retryDelaySeconds, retryAll, followRedirect }
{ maxAttempts, retryDelaySeconds, retryAll, followRedirect, cookie, basicAuth }
) {
const options = ["--fail", "-sv"];
if (maxAttempts > 1) {
Expand All @@ -24,6 +24,12 @@ export async function curl(
if (retryAll) {
options.push("--retry-all-errors");
}
if(cookie) {
options.push("--cookie", `${cookie}`);
}
if(basicAuth) {
options.push("-u", `${basicAuth}`);
}

options.push(url);

Expand Down
12 changes: 11 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7566,7 +7566,7 @@ var semver = __nccwpck_require__(1383);

async function curl(
url,
{ maxAttempts, retryDelaySeconds, retryAll, followRedirect }
{ maxAttempts, retryDelaySeconds, retryAll, followRedirect, cookie, basicAuth }
) {
const options = ["--fail", "-sv"];
if (maxAttempts > 1) {
Expand All @@ -7584,6 +7584,12 @@ async function curl(
if (retryAll) {
options.push("--retry-all-errors");
}
if(cookie) {
options.push("--cookie", `${cookie}`);
}
if(basicAuth) {
options.push("-u", `${basicAuth}`);
}

options.push(url);

Expand Down Expand Up @@ -7661,6 +7667,8 @@ async function run() {
const retryDelay = core.getInput("retry-delay");
const followRedirect = core.getBooleanInput("follow-redirect");
const retryAll = core.getBooleanInput("retry-all");
const cookie = core.getInput("cookie");
const basicAuth = core.getInput("basic-auth");

const urls = urlString.split("|");
const retryDelaySeconds = duration_default().parse(retryDelay).seconds();
Expand All @@ -7686,6 +7694,8 @@ async function run() {
retryDelaySeconds,
retryAll,
followRedirect,
cookie,
basicAuth
});
}

Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ async function run() {
const retryDelay = core.getInput("retry-delay");
const followRedirect = core.getBooleanInput("follow-redirect");
const retryAll = core.getBooleanInput("retry-all");
const cookie = core.getInput("cookie");
const basicAuth = core.getInput("basic-auth");

const urls = urlString.split("|");
const retryDelaySeconds = duration.parse(retryDelay).seconds();
Expand All @@ -46,6 +48,8 @@ async function run() {
retryDelaySeconds,
retryAll,
followRedirect,
cookie,
basicAuth
});
}

Expand Down

0 comments on commit f3f7bd7

Please sign in to comment.