Skip to content

Commit f3f7bd7

Browse files
authored
Merge pull request #22 from MuH3gPaB/curl_cookies_auth_support
Cookie and basic auth support
2 parents ad6b4b0 + 75dc6c1 commit f3f7bd7

File tree

6 files changed

+56
-2
lines changed

6 files changed

+56
-2
lines changed

.github/workflows/check.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,19 @@ jobs:
8989
max-attempts: 5
9090
retry-delay: 2s
9191
retry-all: true
92+
93+
check-single-with-basic-auth:
94+
strategy:
95+
matrix:
96+
os:
97+
- ubuntu-latest
98+
- macos-latest
99+
- windows-latest
100+
runs-on: ${{ matrix.os }}
101+
name: Check single, with basic auth
102+
steps:
103+
- uses: actions/checkout@v2
104+
- uses: ./
105+
with:
106+
url: https://postman-echo.com/basic-auth
107+
basic-auth: "postman:password"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ steps:
1717
retry-delay: 5s # Optional, only applicable to max-attempts > 1
1818
# Retry all errors, including 404. This option might trigger curl upgrade.
1919
retry-all: false # Optional, defaults to "false"
20+
# String representation of cookie attached to health check request.
21+
# Format: `Name=Value`
22+
cookie: "token=asdf1234" # Optional, default is empty
23+
# Basic auth login password pair.
24+
# Format: `login:password`
25+
basic-auth: "login:password" # Optional, default is empty
2026
```
2127
2228
The action will fail if any of the URLs reports either 4xx or 5xx status codes.

action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ inputs:
2323
This might upgrade curl to the version supporting this flag.
2424
required: false
2525
default: "false"
26+
cookie:
27+
description: |
28+
String representation of cookie attached to health check request.
29+
Format: `Name=Value`
30+
required: false
31+
default: ""
32+
basic-auth:
33+
description: |
34+
Basic auth login password pair.
35+
Format: `login:password`
36+
required: false
37+
default: ""
2638
branding:
2739
icon: check
2840
color: purple

curl.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as semver from "semver";
66

77
export async function curl(
88
url,
9-
{ maxAttempts, retryDelaySeconds, retryAll, followRedirect }
9+
{ maxAttempts, retryDelaySeconds, retryAll, followRedirect, cookie, basicAuth }
1010
) {
1111
const options = ["--fail", "-sv"];
1212
if (maxAttempts > 1) {
@@ -24,6 +24,12 @@ export async function curl(
2424
if (retryAll) {
2525
options.push("--retry-all-errors");
2626
}
27+
if(cookie) {
28+
options.push("--cookie", `${cookie}`);
29+
}
30+
if(basicAuth) {
31+
options.push("-u", `${basicAuth}`);
32+
}
2733

2834
options.push(url);
2935

dist/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7566,7 +7566,7 @@ var semver = __nccwpck_require__(1383);
75667566

75677567
async function curl(
75687568
url,
7569-
{ maxAttempts, retryDelaySeconds, retryAll, followRedirect }
7569+
{ maxAttempts, retryDelaySeconds, retryAll, followRedirect, cookie, basicAuth }
75707570
) {
75717571
const options = ["--fail", "-sv"];
75727572
if (maxAttempts > 1) {
@@ -7584,6 +7584,12 @@ async function curl(
75847584
if (retryAll) {
75857585
options.push("--retry-all-errors");
75867586
}
7587+
if(cookie) {
7588+
options.push("--cookie", `${cookie}`);
7589+
}
7590+
if(basicAuth) {
7591+
options.push("-u", `${basicAuth}`);
7592+
}
75877593

75887594
options.push(url);
75897595

@@ -7661,6 +7667,8 @@ async function run() {
76617667
const retryDelay = core.getInput("retry-delay");
76627668
const followRedirect = core.getBooleanInput("follow-redirect");
76637669
const retryAll = core.getBooleanInput("retry-all");
7670+
const cookie = core.getInput("cookie");
7671+
const basicAuth = core.getInput("basic-auth");
76647672

76657673
const urls = urlString.split("|");
76667674
const retryDelaySeconds = duration_default().parse(retryDelay).seconds();
@@ -7686,6 +7694,8 @@ async function run() {
76867694
retryDelaySeconds,
76877695
retryAll,
76887696
followRedirect,
7697+
cookie,
7698+
basicAuth
76897699
});
76907700
}
76917701

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ async function run() {
2121
const retryDelay = core.getInput("retry-delay");
2222
const followRedirect = core.getBooleanInput("follow-redirect");
2323
const retryAll = core.getBooleanInput("retry-all");
24+
const cookie = core.getInput("cookie");
25+
const basicAuth = core.getInput("basic-auth");
2426

2527
const urls = urlString.split("|");
2628
const retryDelaySeconds = duration.parse(retryDelay).seconds();
@@ -46,6 +48,8 @@ async function run() {
4648
retryDelaySeconds,
4749
retryAll,
4850
followRedirect,
51+
cookie,
52+
basicAuth
4953
});
5054
}
5155

0 commit comments

Comments
 (0)