-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixes on submitter-test in xfarm
- Loading branch information
Showing
4 changed files
with
63 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import requests | ||
|
||
class FlagStatus: | ||
ok = 'ok' | ||
wait = 'wait' | ||
timeout = 'timeout' | ||
invalid = 'invalid' | ||
|
||
RESPONSES = { | ||
FlagStatus.wait: ['game not started', 'try again later', 'game over', 'is not up', 'no such flag'], | ||
FlagStatus.timeout: ['timeout'], | ||
FlagStatus.ok: ['accepted', 'congrat'], | ||
FlagStatus.invalid: ['bad', 'wrong', 'expired', 'unknown', 'your own', | ||
'too old', 'not in database', 'already', 'invalid', 'nop team'], | ||
} | ||
|
||
|
||
def submit(flags, token:str = None, http_timeout:int=30, url:str="http://10.10.0.1:8080/flags"): | ||
r = requests.put(url, headers={'X-Team-Token': token}, json=flags, timeout=http_timeout) | ||
if r.status_code == 429: | ||
for flag in flags: | ||
yield (flag, FlagStatus.wait, "Too many requests. Error 429") | ||
else: | ||
for i, item in enumerate(r.json()): | ||
if not isinstance(item, dict): | ||
yield (flags[i], FlagStatus.wait, "Unexpected response. Error 429") | ||
|
||
response = item['msg'].strip() | ||
response = response.replace('[{}] '.format(item['flag']), '') | ||
|
||
response_lower = response.lower() | ||
for status, substrings in RESPONSES.items(): | ||
if any(s in response_lower for s in substrings): | ||
found_status = status | ||
break | ||
else: | ||
found_status = FlagStatus.wait | ||
|
||
yield (item['flag'], found_status, response) |