Skip to content

Commit

Permalink
chore(updatecli): Update the expiration date in security.txt when app…
Browse files Browse the repository at this point in the history
…roaching it. (#7793)

* chore(updatecli): Update the expiration date in security.txt when approaching it.

* WiP

* fix(updatecli): Uses the right regexp.
  • Loading branch information
gounthar authored Jan 8, 2025
1 parent 10a2a45 commit 9d0f12b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
22 changes: 22 additions & 0 deletions updatecli/scripts/update-security-txt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Read the date after "Expires:"
expires_date=$(grep -oP 'Expires: \K.*' content/.well-known/security.txt)

# Convert the expires date to seconds since epoch
expires_epoch=$(date -d "$expires_date" +%s)

# Get the current date in seconds since epoch
current_epoch=$(date +%s)

# Calculate the difference in seconds (30 days * 24 hours * 60 minutes * 60 seconds)
one_month_seconds=$((30 * 24 * 60 * 60))

# Check if the current date is less than one month close to the expires date
if (( current_epoch + one_month_seconds >= expires_epoch )); then
# Add one year to the expires date
new_expires_date=$(date -u -d "$expires_date + 1 year" +%Y-%m-%dT%H:%M:%S.000Z)
echo "$new_expires_date"
else
echo "$expires_date"
fi
42 changes: 42 additions & 0 deletions updatecli/updatecli.d/update-security-txt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Bump the expiration date in content/.well-known/security.txt when approaching the expiry date

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:
expirationDate:
kind: shell
name: "Get Expiration date from security.txt"
spec:
command: bash ./updatecli/scripts/update-security-txt.sh

targets:
updateExpiresDate:
kind: file
name: "Update Expires date in security.txt"
spec:
file: content/.well-known/security.txt
matchpattern: >-
Expires: .*
replacepattern: >-
Expires: {{ source "expirationDate" }}
scmid: default

actions:
default:
kind: github/pullrequest
scmid: default
title: "Update Expiration date in security.txt"
spec:
labels:
- chore

0 comments on commit 9d0f12b

Please sign in to comment.