@@ -53,9 +53,11 @@ def get_lock():
53
53
def main (request ):
54
54
data = request .get_json ()
55
55
if data ['token' ] != os .environ ['ACCESS_TOKEN' ]:
56
+ logging .info ('Rejecting request due to invalid token' )
56
57
return jsonify ('Invalid token' ), 403
57
58
58
59
if request .method != 'POST' :
60
+ logging .info ('Rejecting request due to invalid HTTP method' )
59
61
return jsonify ('Invalid request method' ), 405
60
62
61
63
storage_client = storage .Client ()
@@ -69,6 +71,7 @@ def main(request):
69
71
next_file_url = queue_dict ['queue' ].pop (0 )
70
72
except IndexError :
71
73
# No items in the queue!
74
+ logging .info ('No binaries are currently queued for signing' )
72
75
return jsonify ('No items in the queue' ), 204
73
76
74
77
queuefile .upload_from_string (json .dumps (queue_dict ))
@@ -84,16 +87,21 @@ def main(request):
84
87
85
88
elif data ['action' ] == 'enqueue' :
86
89
url = data ['url' ]
90
+ logging .info ('Attempting to enqueue url %s' , url )
87
91
88
92
if not url .endswith ('.exe' ):
93
+ logging .info ("Rejecting URL because it doesn't end in .exe" ')
89
94
return jsonify ('Invalid URL to sign' ), 400
90
95
91
96
if not url .startswith (GOOGLE_PREFIX ):
97
+ logging .info ('Rejecting URL because it does not start with %s' ,
98
+ GOOGLE_PREFIX )
92
99
return jsonify ('Invalid host' ), 400
93
100
94
101
if not url .startswith ((
95
102
f'{ GOOGLE_PREFIX } /releases.naturalcapitalproject.org/' ,
96
103
f'{ GOOGLE_PREFIX } /natcap-dev-build-artifacts/' )):
104
+ logging .info ('Rejecting URL because the bucket is incorrect' )
97
105
return jsonify ("Invalid target bucket" ), 400
98
106
99
107
# Remove http character quoting
@@ -106,6 +114,7 @@ def main(request):
106
114
# If the file does not exist at this URL, reject it.
107
115
response = requests .head (url )
108
116
if response .status_code > 400 :
117
+ logging .info ('Rejecting URL because it does not exist' )
109
118
return jsonify ('Requested file does not exist' ), 403
110
119
111
120
# If the file is too old, reject it. Trying to avoid a
@@ -114,6 +123,7 @@ def main(request):
114
123
modified_time = datetime .datetime .strptime (
115
124
' ' .join ((mday , mmonth , myear )), '%d %b %Y' )
116
125
if modified_time < datetime .datetime (year = 2024 , month = 6 , day = 1 ):
126
+ logging .info ('Rejecting URL because it is too old' )
117
127
return jsonify ('File is too old' ), 400
118
128
119
129
with get_lock ():
@@ -126,6 +136,8 @@ def main(request):
126
136
signed_files_list .download_as_string ())
127
137
128
138
if url in signed_files_dict ['signed_files' ]:
139
+ logging .info (
140
+ 'Rejecting URL because it has already been signed' )
129
141
return jsonify ('File has already been signed' ), 400
130
142
131
143
# Since the file has not already been signed, add the file to the
0 commit comments