-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(updatecli): create an issue when CRL cert close to expiration (#…
…354) * WIP * change variable name * chore(updatecli): manifest to create an Issue on helpdesk to renew CRL certificate * chore * revert delay to 30days
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
# This script log to github and create an issue if not in dry mode | ||
set -eux -o pipefail | ||
|
||
command -v "gh" >/dev/null 2>&1 || { echo "ERROR: gh command not found. Exiting."; exit 1; } | ||
|
||
cmd=$(cat <<- EOM | ||
gh issue create --title "[private.vpn.jenkins.io] $1 VPN CRL expires" \ | ||
--body "follow https://github.com/jenkins-infra/docker-openvpn?tab=readme-ov-file#howto-renew-certificate-revocation-list \ | ||
See https://github.com/jenkins-infra/helpdesk/issues/4266 for details." \ | ||
--label crl \ | ||
--label updatecli \ | ||
--repo jenkins-infra/helpdesk | ||
EOM | ||
) | ||
|
||
if test "$DRY_RUN" == "false" | ||
then | ||
export GITHUB_TOKEN="${UPDATECLI_GITHUB_TOKEN}" | ||
alreadyOpened=$(gh issue list --repo jenkins-infra/helpdesk --state open --search "label:crl label:updatecli" | wc -l) | ||
if test "$alreadyOpened" -eq 0 | ||
then | ||
"${cmd}" | ||
else | ||
echo "issue already opened" | ||
fi | ||
else | ||
echo "should create an issue on --repo jenkins-infra/helpdesk" | ||
echo "with title: [private.vpn.jenkins.io] $1 VPN CRL expires" | ||
echo "${cmd}" | ||
fi | ||
|
||
exit 0 |
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,27 @@ | ||
#!/bin/bash | ||
# This script calculate diff between dates for letsencrypt expiration | ||
set -eux -o pipefail | ||
|
||
currentexpirydate="${1}" | ||
DATE_BIN='date' | ||
|
||
## non GNU operating system | ||
if command -v gdate >/dev/null 2>&1 | ||
then | ||
DATE_BIN='gdate' | ||
fi | ||
command -v "${DATE_BIN}" >/dev/null 2>&1 || { echo "ERROR: ${DATE_BIN} command not found. Exiting."; exit 1; } | ||
|
||
currentdateepoch=$("${DATE_BIN}" --utc "+%s" 2>/dev/null) | ||
expirydateepoch=$("${DATE_BIN}" "+%s" -d "$currentexpirydate") | ||
|
||
datediff=$(((expirydateepoch-currentdateepoch)/(60*60*24))) # diff per days | ||
|
||
if [ "$datediff" -lt 30 ] # launch renew 30 days before expiration | ||
then | ||
echo "time for update" | ||
exit 0 | ||
else | ||
echo "not yet expired" | ||
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,44 @@ | ||
--- | ||
# yamllint disable rule:line-length | ||
name: "CRL Renew cert for the VPN" | ||
|
||
scms: | ||
default: | ||
kind: github | ||
spec: | ||
user: "{{ .github.user }}" | ||
email: "{{ .github.email }}" | ||
owner: "{{ .github.owner }}" | ||
repository: "{{ .github.repository }}" | ||
token: "{{ requiredEnv .github.token }}" | ||
username: "{{ .github.username }}" | ||
branch: "{{ .github.branch }}" | ||
|
||
sources: | ||
currentEndDate: | ||
name: Get current `end_date` date | ||
kind: shell | ||
spec: | ||
command: openssl crl -in ./cert/pki/crl.pem -noout -nextupdate | cut -d= -f2 | ||
transformers: | ||
- addprefix: "'" | ||
- addsuffix: "'" | ||
|
||
conditions: | ||
checkIfEndDateSoonExpired: | ||
kind: shell | ||
sourceid: currentEndDate | ||
spec: | ||
# Current end_date date value passed as argument | ||
command: bash ./updatecli/scripts/datediff.sh | ||
environments: | ||
- name: PATH | ||
targets: | ||
createIssue: | ||
kind: shell | ||
sourceid: currentEndDate | ||
spec: | ||
environments: | ||
- name: PATH | ||
- name: UPDATECLI_GITHUB_TOKEN | ||
command: bash ./updatecli/scripts/createIssue.sh |