Skip to content

Commit

Permalink
validate date is in the past
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenruizdegauna committed Jan 14, 2025
1 parent 63d39cc commit 997925b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .github/workflows/recover_s3_repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,23 @@ jobs:
steps:
- name: Validate datetime
run: |
set -e
datetime="${{ github.event.inputs.date_month }}-${{ github.event.inputs.date_day }}-${{ github.event.inputs.date_year }} ${{ github.event.inputs.time }} +0000"
# Use Python's strptome (same as s3-pit-restore) to check if it's a valid datetime
python3 -c "from datetime import datetime; datetime.strptime('$datetime', '%m-%d-%Y %H:%M:%S %z')" 2> /dev/null
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Invalid datetime: $datetime"
exit 1
fi
# check that datetime is not in the future
python3 -c "from datetime import datetime,timezone; import sys; sys.exit(1) if datetime.strptime('01-14-2025 14:02:00 +0000', '%m-%d-%Y %H:%M:%S %z') >= datetime.now(timezone.utc) else sys.exit(0)"
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "datetime cannot be in the future: $datetime"
exit 1
fi
echo "DATE_TIME=$datetime" >> $GITHUB_ENV
- name: Validate path input does not have leading nor trailing slash
Expand Down

0 comments on commit 997925b

Please sign in to comment.