-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding timeout options both CLI and .cigar.json (#32)
* Adding timeout options both CLI and .cigar.json πππ Happy New Year πππ This PR adds the timeout options discussed in #31 Closes / implements #31 Any values in the CLI are overridden by what ever value is in the `.cigar.json` * Removed short hand (ct) for --connect-timeout via #32 (comment) by @Brunty * Test response timeout .json config and CLI flags through stubs via #32 (comment) by @Brunty * s is now short the connect-timeout
- Loading branch information
1 parent
06db910
commit 6389b9e
Showing
11 changed files
with
154 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ use Brunty\Cigar\Outputter; | |
use Brunty\Cigar\Parser; | ||
use Brunty\Cigar\Result; | ||
|
||
$options = getopt('c:ia:u:jh:', ['version', 'help', 'quiet', 'config:', 'insecure', 'auth:', 'url:', 'json', 'header:']); | ||
$options = getopt('c:ia:u:jh:t:s:', ['version', 'help', 'quiet', 'config:', 'insecure', 'auth:', 'url:', 'json', 'header:', 'timeout:', 'connect-timeout:']); | ||
|
||
if (isset($options['help'])) { | ||
$content = <<<HELP | ||
|
@@ -27,14 +27,16 @@ if (isset($options['help'])) { | |
cigar [options] | ||
\033[33mOptions:\033[0m | ||
\033[32m-c file.json, --config=file.json\033[0m Use the specified config file instead of the default .cigar.json file | ||
\033[32m-u URL, --url=URL\033[0m Base URL for checks, e.g. https://example.org/ | ||
\033[32m-i, --insecure\033[0m Allow invalid SSL certificates | ||
\033[32m-a, --auth\033[0m Authorization header "\074type\076 \074credentials\076" | ||
\033[32m-h, --header\033[0m Custom header "\074name\076: \074value\076" | ||
\033[32m-j, --json\033[0m Output JSON | ||
\033[32m --quiet\033[0m Do not output any message | ||
\033[32m --version\033[0m Print the version of Cigar | ||
\033[32m-c file.json, --config=file.json\033[0m Use the specified config file instead of the default .cigar.json file | ||
\033[32m-u URL, --url=URL\033[0m Base URL for checks, e.g. https://example.org/ | ||
\033[32m-i, --insecure\033[0m Allow invalid SSL certificates | ||
\033[32m-a, --auth\033[0m Authorization header "\074type\076 \074credentials\076" | ||
\033[32m-h, --header\033[0m Custom header "\074name\076: \074value\076" | ||
\033[32m-s --connect-timeout=TIMEOUT\033[0m Connect Timeout | ||
\033[32m-t, --timeout=TIMEOUT\033[0m Timeout | ||
\033[32m-j, --json\033[0m Output JSON | ||
\033[32m --quiet\033[0m Do not output any message | ||
\033[32m --version\033[0m Print the version of Cigar | ||
Created by Matt Brunt | ||
E: [email protected] | ||
|
@@ -78,17 +80,19 @@ if ( ! file_exists($file)) { | |
exit(1); | ||
} | ||
|
||
$secure = ! (isset($options['i']) || isset($options['insecure'])); | ||
$authorization = $options['a'] ?? $options['auth'] ?? null; | ||
$headers = (array) ($options['h'] ?? $options['header'] ?? []); | ||
$connectTimeout = $options['s'] ?? $options['connect-timeout'] ?? null; | ||
$timeout = $options['t'] ?? $options['timeout'] ?? null; | ||
|
||
try { | ||
$domains = (new Parser($baseUrl))->parse($file); | ||
$domains = (new Parser($baseUrl, $connectTimeout, $timeout))->parse($file); | ||
} catch (\Throwable $e) { | ||
$outputter->writeErrorLine('Unable to parse .cigar.json file'); | ||
exit(1); | ||
} | ||
|
||
$secure = ! (isset($options['i']) || isset($options['insecure'])); | ||
$authorization = $options['a'] ?? $options['auth'] ?? null; | ||
$headers = (array) ($options['h'] ?? $options['header'] ?? []); | ||
|
||
$results = (new AsyncChecker($secure, $authorization, $headers))->check($domains); | ||
$passedResults = array_filter($results, function (Result $result) { | ||
return $result->hasPassed(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"url": "http://httpbin.org/delay/3", | ||
"status": 200, | ||
"request-timeout": 1, | ||
"response-timeout": 5 | ||
}, | ||
{ | ||
"url": "http://httpbin.org/drip?duration=3", | ||
"status": 200, | ||
"request-timeout": 1, | ||
"response-timeout": 5 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters