@@ -76,14 +76,38 @@ def sync_challenge(challenge, ignore=[]):
76
76
r .raise_for_status ()
77
77
for flag in challenge ["flags" ]:
78
78
if type (flag ) == str :
79
- data = {"content" : flag , "type" : "static" , "challenge " : challenge_id }
79
+ data = {"content" : flag , "type" : "static" , "challenge_id " : challenge_id }
80
80
r = s .post (f"/api/v1/flags" , json = data )
81
81
r .raise_for_status ()
82
82
elif type (flag ) == dict :
83
- flag ["challenge " ] = challenge_id
83
+ flag ["challenge_id " ] = challenge_id
84
84
r = s .post (f"/api/v1/flags" , json = flag )
85
85
r .raise_for_status ()
86
86
87
+ # Update topics
88
+ if challenge .get ("topics" ) and "topics" not in ignore :
89
+ # Delete existing challenge topics
90
+ current_topics = s .get (
91
+ f"/api/v1/challenges/{ challenge_id } /topics" , json = ""
92
+ ).json ()["data" ]
93
+ for topic in current_topics :
94
+ topic_id = topic ["id" ]
95
+ r = s .delete (
96
+ f"/api/v1/topics?type=challenge&target_id={ topic_id } " , json = True
97
+ )
98
+ r .raise_for_status ()
99
+ # Add new challenge topics
100
+ for topic in challenge ["topics" ]:
101
+ r = s .post (
102
+ f"/api/v1/topics" ,
103
+ json = {
104
+ "value" : topic ,
105
+ "type" : "challenge" ,
106
+ "challenge_id" : challenge_id ,
107
+ },
108
+ )
109
+ r .raise_for_status ()
110
+
87
111
# Update tags
88
112
if challenge .get ("tags" ) and "tags" not in ignore :
89
113
# Delete existing tags
@@ -94,7 +118,9 @@ def sync_challenge(challenge, ignore=[]):
94
118
r = s .delete (f"/api/v1/tags/{ tag_id } " , json = True )
95
119
r .raise_for_status ()
96
120
for tag in challenge ["tags" ]:
97
- r = s .post (f"/api/v1/tags" , json = {"challenge" : challenge_id , "value" : tag })
121
+ r = s .post (
122
+ f"/api/v1/tags" , json = {"challenge_id" : challenge_id , "value" : tag }
123
+ )
98
124
r .raise_for_status ()
99
125
100
126
# Upload files
@@ -119,7 +145,7 @@ def sync_challenge(challenge, ignore=[]):
119
145
click .secho (f"File { file_path } was not found" , fg = "red" )
120
146
raise Exception (f"File { file_path } was not found" )
121
147
122
- data = {"challenge " : challenge_id , "type" : "challenge" }
148
+ data = {"challenge_id " : challenge_id , "type" : "challenge" }
123
149
# Specifically use data= here instead of json= to send multipart/form-data
124
150
r = s .post (f"/api/v1/files" , files = files , data = data )
125
151
r .raise_for_status ()
@@ -136,12 +162,12 @@ def sync_challenge(challenge, ignore=[]):
136
162
137
163
for hint in challenge ["hints" ]:
138
164
if type (hint ) == str :
139
- data = {"content" : hint , "cost" : 0 , "challenge " : challenge_id }
165
+ data = {"content" : hint , "cost" : 0 , "challenge_id " : challenge_id }
140
166
else :
141
167
data = {
142
168
"content" : hint ["content" ],
143
169
"cost" : hint ["cost" ],
144
- "challenge " : challenge_id ,
170
+ "challenge_id " : challenge_id ,
145
171
}
146
172
147
173
r = s .post (f"/api/v1/hints" , json = data )
@@ -205,18 +231,33 @@ def create_challenge(challenge, ignore=[]):
205
231
if challenge .get ("flags" ) and "flags" not in ignore :
206
232
for flag in challenge ["flags" ]:
207
233
if type (flag ) == str :
208
- data = {"content" : flag , "type" : "static" , "challenge " : challenge_id }
234
+ data = {"content" : flag , "type" : "static" , "challenge_id " : challenge_id }
209
235
r = s .post (f"/api/v1/flags" , json = data )
210
236
r .raise_for_status ()
211
237
elif type (flag ) == dict :
212
238
flag ["challenge" ] = challenge_id
213
239
r = s .post (f"/api/v1/flags" , json = flag )
214
240
r .raise_for_status ()
215
241
242
+ # Create topics
243
+ if challenge .get ("topics" ) and "topics" not in ignore :
244
+ for topic in challenge ["topics" ]:
245
+ r = s .post (
246
+ f"/api/v1/topics" ,
247
+ json = {
248
+ "value" : topic ,
249
+ "type" : "challenge" ,
250
+ "challenge_id" : challenge_id ,
251
+ },
252
+ )
253
+ r .raise_for_status ()
254
+
216
255
# Create tags
217
256
if challenge .get ("tags" ) and "tags" not in ignore :
218
257
for tag in challenge ["tags" ]:
219
- r = s .post (f"/api/v1/tags" , json = {"challenge" : challenge_id , "value" : tag })
258
+ r = s .post (
259
+ f"/api/v1/tags" , json = {"challenge_id" : challenge_id , "value" : tag }
260
+ )
220
261
r .raise_for_status ()
221
262
222
263
# Upload files
@@ -231,7 +272,7 @@ def create_challenge(challenge, ignore=[]):
231
272
click .secho (f"File { file_path } was not found" , fg = "red" )
232
273
raise Exception (f"File { file_path } was not found" )
233
274
234
- data = {"challenge " : challenge_id , "type" : "challenge" }
275
+ data = {"challenge_id " : challenge_id , "type" : "challenge" }
235
276
# Specifically use data= here instead of json= to send multipart/form-data
236
277
r = s .post (f"/api/v1/files" , files = files , data = data )
237
278
r .raise_for_status ()
@@ -240,12 +281,12 @@ def create_challenge(challenge, ignore=[]):
240
281
if challenge .get ("hints" ) and "hints" not in ignore :
241
282
for hint in challenge ["hints" ]:
242
283
if type (hint ) == str :
243
- data = {"content" : hint , "cost" : 0 , "challenge " : challenge_id }
284
+ data = {"content" : hint , "cost" : 0 , "challenge_id " : challenge_id }
244
285
else :
245
286
data = {
246
287
"content" : hint ["content" ],
247
288
"cost" : hint ["cost" ],
248
- "challenge " : challenge_id ,
289
+ "challenge_id " : challenge_id ,
249
290
}
250
291
251
292
r = s .post (f"/api/v1/hints" , json = data )
0 commit comments