This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from cloudfoundry-incubator/add-httplint
Add httplint.sh
- Loading branch information
Showing
5 changed files
with
95 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,3 @@ | ||
# kubecf-tools | ||
|
||
This repository contains various helper tools for [KubeCF](https://github.com/cloudfoundry-incubator/kubecf) | ||
|
||
## versioning | ||
|
||
This dir contains a common versioning script which prints the version of the current git commit to stdout. | ||
|
||
This script is a wrapper around the functionality of `git describe --tags --dirty` with small changes to split the git pre-release identifiers to allow | ||
semver sorting. | ||
It requires the latest tag of the current branch to be a semver version, otherwise it raises an exception. | ||
Semver versions with plus elements like `1.0.2+gold` are not supported and also raise an exception. | ||
|
||
If the latest commit is not tagged by a semver tag then a pre-release version is printed. | ||
|
||
`<latest-released-version>-[<additional-pre-release-identifier>.]<commits-since-release>.g<small-latest-git-sha>[-<dirty-tag>]` | ||
|
||
For example `1.0.2-5.gb3f7a0c1-dirty` or if there are additional pre-release identifiers in the git tag `1.0.2-alpha.5.gb3f7a0c1-dirty`. |
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,9 @@ | ||
# Linters | ||
|
||
## httplint.sh | ||
|
||
Lint for URLs using http, instead of https. | ||
|
||
The linter looks for a file __.http_exceptions__ in `pwd`. If it doesn't exist, | ||
it excludes `127.0.0.1` & `localhost`by default. If it exists, it expects one | ||
line for each allowed domain. The file can contain comments, starting with `#`. |
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 @@ | ||
#!/usr/bin/env bash | ||
|
||
HTTP_EXCEPTIONS=.http_exceptions | ||
if [ -f "${HTTP_EXCEPTIONS}" ]; then | ||
EXCEPTIONS=$(perl -e 'while(<>){chomp; push @_,quotemeta unless /^#/} print join("|", @_)' < "${HTTP_EXCEPTIONS}") | ||
else | ||
EXCEPTIONS="127\.0\.0\.1|localhost" | ||
fi | ||
|
||
if [ "$(git grep --untracked -P "http://(?!${EXCEPTIONS})" -- ':(exclude)httplint.sh' | wc -l)" -gt 0 ]; then | ||
echo "URLS should not start with 'http://' (with excepted domains listed in ${HTTP_EXCEPTIONS})" | ||
git grep --untracked -P "http://(?!${EXCEPTIONS})" -- ':(exclude)httplint.sh' | ||
exit 1 | ||
fi |
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,58 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -Eeuo pipefail | ||
|
||
create_example() { | ||
# let's create an example file on the fly, to not need to implement ignore | ||
# lists ignoring this script | ||
echo 'http''://example.com/fail_without_exceptions_file' > example.md | ||
echo 'http''://localhost/fail_with_exceptions_file' >> example.md | ||
} | ||
|
||
cleanup() { | ||
rm -f example.md .http_exceptions | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
# Positive test without .http_exceptions | ||
cleanup | ||
create_example | ||
if ./httplint.sh > /dev/null ; then | ||
# we expect to fail because example.com | ||
echo "FAIL: httplint.sh without .http_exceptions didn't find example.com" | ||
exit 1 | ||
fi | ||
|
||
# Positive test with .http_exceptions | ||
cleanup | ||
create_example | ||
cat > .http_exceptions <<EOF | ||
# exceptions file for httplint | ||
localhost | ||
127.0.0.1 | ||
example.com | ||
EOF | ||
if ! ./httplint.sh > /dev/null ; then | ||
# we expect to succeed because example.com & localhost are on the exceptions | ||
echo "FAIL: httplint.sh with .http_exceptions found example.com, albeit it's on exceptions" | ||
exit 1 | ||
fi | ||
|
||
# Negative test with .http_exceptions | ||
cleanup | ||
create_example | ||
cat > .http_exceptions <<EOF | ||
# exceptions file for httplint | ||
localhost | ||
127.0.0.1 | ||
local.com | ||
EOF | ||
if ./httplint.sh > /dev/null ; then | ||
# we expect to fail because example.com is not on the exceptions | ||
echo "FAIL: httplint.sh with .http_exceptions failed to find example.com" | ||
exit 1 | ||
fi | ||
|
||
echo "SUCCESS: httplint.sh linted correctly" | ||
cleanup |
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 @@ | ||
## versioning | ||
|
||
This dir contains a common versioning script which prints the version of the current git commit to stdout. | ||
|
||
This script is a wrapper around the functionality of `git describe --tags --dirty` with small changes to split the git pre-release identifiers to allow | ||
semver sorting. | ||
It requires the latest tag of the current branch to be a semver version, otherwise it raises an exception. | ||
Semver versions with plus elements like `1.0.2+gold` are not supported and also raise an exception. | ||
|
||
If the latest commit is not tagged by a semver tag then a pre-release version is printed. | ||
|
||
`<latest-released-version>-[<additional-pre-release-identifier>.]<commits-since-release>.g<small-latest-git-sha>[-<dirty-tag>]` | ||
|
||
For example `1.0.2-5.gb3f7a0c1-dirty` or if there are additional pre-release identifiers in the git tag `1.0.2-alpha.5.gb3f7a0c1-dirty`. |