forked from Brunty/cigar
-
Notifications
You must be signed in to change notification settings - Fork 0
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
πππ Happy New Year πππ This PR adds the timeout options discussed in Brunty#31 Closes / implements Brunty#31 Any values in the CLI are overridden by what ever value is in the `.cigar.json`
- Loading branch information
1 parent
b8d82fb
commit e44ac97
Showing
7 changed files
with
109 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:ct:', ['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-ct, --connect-timeout=TIMEOUT\033[0m Connect Timeout | ||
\033[32m-t, --timeout=TIMEOUT\033[0m Response 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['ct'] ?? $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