@@ -3,12 +3,25 @@ name: . ⚠️⚠️⚠️ Recover S3 Repository back in time ⚠️⚠️⚠️
3
3
on :
4
4
workflow_dispatch :
5
5
inputs :
6
- date_time :
7
- description : ' UTC DateTime to recover the S3 repository back in time (MM-DD-YYYY HH:MM:SS +0)'
6
+ # description: 'UTC DateTime to recover the S3 repository back in time (MM-DD-YYYY HH:MM:SS +0)'
7
+ date_year :
8
+ description : ' UTC Date YEAR (YYYY) to recover the S3 repository back in time'
9
+ type : string
10
+ required : true
11
+ date_month :
12
+ description : ' UTC Date MONTH (MM) to recover the S3 repository back in time'
13
+ type : string
14
+ required : true
15
+ date_day :
16
+ description : ' UTC Date DAY (DD) to recover the S3 repository back in time'
17
+ type : string
18
+ required : true
19
+ time :
20
+ description : ' UTC Time (HH:MM:SS) to recover the S3 repository back in time'
8
21
type : string
9
22
required : true
10
23
path :
11
- description : ' Path under infrastructure_agent folder to recover (w/o leading slash, with trailing slash)'
24
+ description : ' Path under infrastructure_agent folder to recover (w/o leading nor trailing slash)'
12
25
type : string
13
26
required : true
14
27
environment :
29
42
jobs :
30
43
recover-s3-repository :
31
44
name : Execute S3 PIT restore
32
- runs-on : ubuntu-20 .04
45
+ runs-on : ubuntu-24 .04
33
46
steps :
34
47
- name : Validate datetime
35
48
run : |
36
- datetime="${{ github.event.inputs.date_time }}"
49
+ echo "Validating that datetime is in correct format"
50
+ datetime="${{ github.event.inputs.date_month }}-${{ github.event.inputs.date_day }}-${{ github.event.inputs.date_year }} ${{ github.event.inputs.time }} +0000"
37
51
# Use Python's strptome (same as s3-pit-restore) to check if it's a valid datetime
38
52
python3 -c "from datetime import datetime; datetime.strptime('$datetime', '%m-%d-%Y %H:%M:%S %z')" 2> /dev/null
39
53
exit_code=$?
40
- if [ $exit_code -ne 0 ]] ; then
54
+ if [ $exit_code -ne 0 ]; then
41
55
exit 1
42
56
fi
57
+ echo "datetime format is correct"
58
+ echo ""
59
+
60
+ echo "Validating that datetime is not in the future"
61
+ # check that datetime is not in the future
62
+ python3 -c "from datetime import datetime,timezone; import sys; sys.exit(1) if datetime.strptime('$datetime', '%m-%d-%Y %H:%M:%S %z') >= datetime.now(timezone.utc) else sys.exit(0)"
63
+ exit_code=$?
64
+ if [ $exit_code -ne 0 ]; then
65
+ exit 1
66
+ fi
67
+ echo "datetime is not in the future"
68
+
69
+ echo "DATE_TIME=$datetime" >> $GITHUB_ENV
43
70
44
71
- name : Validate path input does not have leading nor trailing slash
45
72
run : |
73
+ set -e
46
74
s3_path="${{ github.event.inputs.path }}"
47
75
# Check if the path has a leading slash
48
76
if [[ "$s3_path" == /* ]]; then
49
77
echo "Invalid path: should not have a leading slash."
50
- return 1
78
+ exit 1
51
79
fi
52
80
53
81
# Check if the path has a trailing slash
54
82
if [[ "$s3_path" == */ ]]; then
55
83
echo "Invalid path : should not have a trailing slash."
56
- return 1
84
+ exit 1
57
85
fi
58
86
59
87
- name : Checkout repository
@@ -63,43 +91,45 @@ jobs:
63
91
ref : master
64
92
65
93
- name : Setup AWS credentials for Production
66
- if : ${{ env.ENVIRONMENT == 'production' }}
94
+ if : ${{ github.event.inputs.environment == 'production' }}
67
95
run : |
68
96
./setup_aws_credentials.sh
69
97
env :
70
98
AWS_ACCESS_KEY_ID : ${{ secrets.OHAI_AWS_ACCESS_KEY_ID_PRODUCTION }}
71
99
AWS_SECRET_ACCESS_KEY : ${{ secrets.OHAI_AWS_SECRET_ACCESS_KEY_PRODUCTION }}
72
100
AWS_ROLE_ARN : ${{ secrets.OHAI_AWS_ROLE_ARN_PRODUCTION }}
73
101
AWS_ROLE_SESSION_NAME : ${{ secrets.OHAI_AWS_ROLE_SESSION_NAME_PRODUCTION }}
102
+ AWS_SESSION_DURATION_SECONDS : 14400
74
103
TEMP_AWS_PROFILE : ${{ env.TEMP_AWS_PROFILE }}
75
104
76
105
- name : Run S3 PIT restore
77
- if : ${{ env.ENVIRONMENT == 'production' }}
106
+ if : ${{ github.event.inputs.environment == 'production' }}
78
107
run : |
79
108
BUCKET="nr-downloads-main" \
80
109
PREFIX="${{ env.MANDATORY_PREFIX }}${{ github.event.inputs.path }}" \
81
- TIME="${{ github.event.inputs.date_time }}" \
110
+ TIME="${{ env.DATE_TIME }}" \
82
111
IMAGE="${{ env.IMAGE }}" \
83
112
AWS_PROFILE="${{ env.TEMP_AWS_PROFILE }}" \
84
113
make restore
85
114
86
115
- name : Setup AWS credentials for Staging
87
- if : ${{ env.ENVIRONMENT == 'staging' }}
116
+ if : ${{ github.event.inputs.environment == 'staging' }}
88
117
run : |
89
118
./setup_aws_credentials.sh
90
119
env :
91
120
AWS_ACCESS_KEY_ID : ${{ secrets.OHAI_AWS_ACCESS_KEY_ID_STAGING }}
92
121
AWS_SECRET_ACCESS_KEY : ${{ secrets.OHAI_AWS_SECRET_ACCESS_KEY_STAGING }}
93
122
AWS_ROLE_ARN : ${{ secrets.OHAI_AWS_ROLE_ARN_STAGING }}
94
123
AWS_ROLE_SESSION_NAME : ${{ secrets.OHAI_AWS_ROLE_SESSION_NAME_STAGING }}
124
+ AWS_SESSION_DURATION_SECONDS : 14400
95
125
TEMP_AWS_PROFILE : ${{ env.TEMP_AWS_PROFILE }}
96
126
97
127
- name : Run S3 PIT restore in Staging S3
98
- if : ${{ env.ENVIRONMENT == 'staging' }}
128
+ if : ${{ github.event.inputs.environment == 'staging' }}
99
129
run : |
100
130
BUCKET="nr-downloads-ohai-staging" \
101
- PREFIX="${{ env.MANDATORY_PREFIX }}${{ env.S3_PATH }}" \
102
- TIME="${{ env.DATETIME }}" \
131
+ PREFIX="${{ env.MANDATORY_PREFIX }}${{ github.event.inputs.path }}" \
132
+ TIME="${{ env.DATE_TIME }}" \
103
133
IMAGE="${{ env.IMAGE }}" \
104
134
AWS_PROFILE="${{ env.TEMP_AWS_PROFILE }}" \
105
135
make restore
0 commit comments