Skip to content

Commit a97fb8e

Browse files
committed
add more configuration for git checkout
1 parent bc1fa54 commit a97fb8e

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ resource_types:
5555
through, without relying on a status being on it. This feature should only be used in
5656
concourse version 1.2.x and higher and the [`version: every`](http://concourse.ci/get-step.html#get-version).
5757

58+
* `username`: *Optional.* Username for HTTP(S) auth when pulling/pushing.
59+
This is needed when only HTTP/HTTPS protocol for git is available (which does not support private key auth)
60+
and auth is required.
61+
62+
* `password`: *Optional.* Password for HTTP(S) auth when pulling/pushing.
63+
64+
* `skip_ssl_verification`: *Optional.* Skips git ssl verification by exporting
65+
`GIT_SSL_NO_VERIFY=true`.
66+
67+
* `git_config`: *Optional*. If specified as (list of pairs `name` and `value`)
68+
it will configure git global options, setting each name with each value.
69+
70+
This can be useful to set options like `credential.helper` or similar.
71+
72+
See the [`git-config(1)` manual page](https://www.kernel.org/pub/software/scm/git/docs/git-config.html)
73+
for more information and documentation of existing git options.
74+
5875
## Behavior
5976

6077
### `check`: Check for new pull requests

assets/check

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ set -e
55
exec 3>&1 # make stdout available as fd 3 for the result
66
exec 1>&2 # redirect all output to stderr for logging
77

8-
. $(dirname $0)/common.sh
9-
108
payload=$(mktemp $TMPDIR/pullrequest-resource.XXXXXX)
119
cat > $payload <&0
12-
load_pubkey $payload
1310

1411
$(dirname $0)/lib/check.rb $1 >&3 < $payload

assets/common.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load_pubkey() {
1111
eval $(ssh-agent) >/dev/null 2>&1
1212
trap "kill $SSH_AGENT_PID" 0
1313

14-
ssh-add $private_key_path >/dev/null 2>&1
14+
SSH_ASKPASS=/opt/resource/askpass.sh DISPLAY= ssh-add $private_key_path >/dev/null
1515

1616
mkdir -p ~/.ssh
1717
cat > ~/.ssh/config <<EOF
@@ -21,3 +21,26 @@ EOF
2121
chmod 0600 ~/.ssh/config
2222
fi
2323
}
24+
25+
configure_git_ssl_verification() {
26+
skip_ssl_verification=$(jq -r '.source.skip_ssl_verification // false' < $1)
27+
if [ "$skip_ssl_verification" = "true" ]; then
28+
export GIT_SSL_NO_VERIFY=true
29+
fi
30+
}
31+
32+
configure_credentials() {
33+
local username=$(jq -r '.source.username // ""' < $1)
34+
local password=$(jq -r '.source.password // ""' < $1)
35+
36+
rm -f $HOME/.netrc
37+
if [ "$username" != "" -a "$password" != "" ]; then
38+
echo "default login $username password $password" > $HOME/.netrc
39+
fi
40+
}
41+
42+
configure_git_global() {
43+
local git_config_payload="$1"
44+
eval $(echo "$git_config_payload" | \
45+
jq -r ".[] | \"git config --global '\\(.name)' '\\(.value)'; \"")
46+
}

assets/in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ exec 1>&2 # redirect all output to stderr for logging
1010
payload=$(mktemp $TMPDIR/pullrequest-resource.XXXXXX)
1111
cat > $payload <&0
1212
load_pubkey $payload
13+
configure_git_ssl_verification $payload
14+
configure_credentials $payload
15+
16+
git_config_payload=$(jq -r '.source.git_config // []' < $payload)
17+
configure_git_global "${git_config_payload}"
1318

1419
$(dirname $0)/lib/in.rb $1 >&3 < $payload

assets/out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ exec 1>&2 # redirect all output to stderr for logging
1010
payload=$(mktemp $TMPDIR/pullrequest-resource.XXXXXX)
1111
cat > $payload <&0
1212
load_pubkey $payload
13+
configure_git_ssl_verification $payload
14+
configure_credentials $payload
15+
16+
git_config_payload=$(jq -r '.source.git_config // []' < $payload)
17+
configure_git_global "${git_config_payload}"
1318

1419
$(dirname $0)/lib/out.rb $1 >&3 < $payload

0 commit comments

Comments
 (0)