gamingflexer commited on
Commit
c5cbcbd
1 Parent(s): 8079714

Add CopyleaksClient class for submitting files to Copyleaks API

Browse files
Files changed (1) hide show
  1. src/checker/copy_leaks_login.py +37 -0
src/checker/copy_leaks_login.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import random
3
+ from copyleaks.copyleaks import Copyleaks
4
+ from copyleaks.exceptions.command_error import CommandError
5
+ from copyleaks.models.submit.document import FileDocument
6
+ from copyleaks.models.submit.properties.scan_properties import ScanProperties
7
+
8
+ class CopyleaksClient:
9
+ def __init__(self, email_address, key):
10
+ self.email_address = email_address
11
+ self.key = key
12
+ self.auth_token = None
13
+
14
+ def login(self):
15
+ try:
16
+ self.auth_token = Copyleaks.login(self.email_address, self.key)
17
+ except CommandError as ce:
18
+ response = ce.get_response()
19
+ print(f"An error occurred (HTTP status code {response.status_code}):")
20
+ print(response.content)
21
+ exit(1)
22
+
23
+ print("Logged successfully!\nToken:")
24
+ print(self.auth_token)
25
+
26
+ def submit_file(self, file_content, filename, webhook_url):
27
+ scan_id = random.randint(100, 100000)
28
+ BASE64_FILE_CONTENT = base64.b64encode(file_content.encode('utf-8')).decode('utf-8')
29
+ file_submission = FileDocument(BASE64_FILE_CONTENT, filename)
30
+
31
+ scan_properties = ScanProperties(webhook_url)
32
+ scan_properties.set_sandbox(True)
33
+ file_submission.set_properties(scan_properties)
34
+
35
+ Copyleaks.submit_file(self.auth_token, scan_id, file_submission)
36
+ print("Sent to scanning")
37
+ print("You will be notified using your webhook once the scan is completed.")