Last active
May 18, 2022 15:39
-
-
Save SergK/7f6b2bd31b38431342affe88775c8754 to your computer and use it in GitHub Desktop.
logsight.ai
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
import copy | |
import time | |
from datetime import datetime | |
import argparse | |
import logsight.exceptions | |
from logsight.user import LogsightUser | |
from logsight.logs import LogsightLogs | |
from logsight.compare import LogsightCompare | |
SECONDS_SLEEP = 3 | |
# Instantiate the parser | |
parser = argparse.ArgumentParser(description='Logsight Init') | |
parser.add_argument('--username', type=str, help='Basic auth username') | |
parser.add_argument('--password', type=str, help='Basic auth password') | |
parser.add_argument('--application_id', type=str, help='Application id') | |
parser.add_argument('--baseline_tag', type=str, help='Baseline tag') | |
parser.add_argument('--candidate_tag', type=str, help='Compare tag') | |
parser.add_argument('--risk_threshold', type=int, help='Risk threshold (between 0 and 100)') | |
args = parser.parse_args() | |
EMAIL = args.username | |
PASSWORD = args.password | |
APPLICATION_ID = args.application_id | |
BASELINE_TAG = args.baseline_tag | |
CANDIDATE_TAG = args.candidate_tag | |
RISK_THRESHOLD = args.risk_threshold | |
user = LogsightUser(email=EMAIL, password=PASSWORD) | |
compare = LogsightCompare(user.user_id, user.token) | |
while True: | |
try: | |
r = compare.compare(app_id=APPLICATION_ID, | |
baseline_tag=BASELINE_TAG, | |
candidate_tag=CANDIDATE_TAG) | |
break | |
except logsight.exceptions.Conflict as conflict: | |
time.sleep(SECONDS_SLEEP) | |
except Exception as e: | |
application_tags = [tag['tag'] for tag in compare.tags(app_id=APPLICATION_ID)] | |
if CANDIDATE_TAG not in application_tags and BASELINE_TAG not in application_tags: | |
print("Both tags do not exist! We cant perform verification!") | |
exit(0) | |
if BASELINE_TAG not in application_tags: | |
BASELINE_TAG = copy.deepcopy(CANDIDATE_TAG) | |
if CANDIDATE_TAG not in application_tags: | |
CANDIDATE_TAG = copy.deepcopy(BASELINE_TAG) | |
time.sleep(SECONDS_SLEEP) | |
if r['risk'] >= RISK_THRESHOLD: | |
print(r['risk']) | |
exit(1) | |
else: | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment