forked from cloud-gov/cg-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-pipeline-git-resources-without-verification.sh
69 lines (55 loc) · 1.69 KB
/
get-pipeline-git-resources-without-verification.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
function usage {
echo -e "
./$( basename "$0" ) [pipeline-name] [--help, -h]
Get all git resources in Concourse pipelines that don\'t have commit signing
configured
Optional environment variable \$CI_URL matching your Concourse URL.
example: CI_URL=https://ci.fr.cloud.gov ./$( basename "$0" )
Optional argument for specific pipeline to check
example: ./$( basename "$0" ) pipeline-name
\$CI_URL, Defaults to https://ci.fr.cloud.gov
"
exit
}
while getopts ":h" opt; do
case ${opt} in
h )
usage
exit 0
;;
* )
usage
exit 0
;;
esac
done
CI_URL="${CI_URL:-"https://ci.fr.cloud.gov"}"
FLY_TARGET=$(fly targets | grep "${CI_URL}" | head -n 1 | awk '{print $1}')
if ! fly --target "${FLY_TARGET}" workers > /dev/null; then
echo "Not logged in to concourse"
exit 1
fi
function find_git_resources_without_commit_verification {
fly -t ci get-pipeline --pipeline "$1" --json \
| jq '.resources[] |
select(.type=="git") |
select(.source.uri | test("github.com.*(cloud-gov|18[Ff])")) |
select(.source | has("commit_verification_keys") | not)'
}
function report_git_resources_without_verification {
resource_names=$(find_git_resources_without_commit_verification "$1" | jq .name)
if [[ $resource_names ]]; then
printf 'pipeline: %s\n' "$1"
echo "$resource_names"
printf "\n"
fi
}
if [ -z "$1" ]; then
fly --target "${FLY_TARGET}" pipelines | tail -n +1 | while read -r line; do
pipeline_name=$(echo "$line" | awk '{print $2}')
report_git_resources_without_verification "$pipeline_name"
done
else
report_git_resources_without_verification "$1"
fi