diff options
author | Jonathan Weth <git@jonathanweth.de> | 2020-07-22 15:48:03 +0200 |
---|---|---|
committer | Jonathan Weth <git@jonathanweth.de> | 2020-07-22 15:48:03 +0200 |
commit | 803305c353e27f8ac04857d2add91df64ff1a882 (patch) | |
tree | f1a0540ece43a361d077befda41d3f0b49c9a0ab | |
parent | b3d8e355abd81eee87b28b1dfd96f556ce6e0216 (diff) | |
download | RWA.Support.SessionService-803305c353e27f8ac04857d2add91df64ff1a882.tar.gz RWA.Support.SessionService-803305c353e27f8ac04857d2add91df64ff1a882.tar.bz2 RWA.Support.SessionService-803305c353e27f8ac04857d2add91df64ff1a882.zip |
Simplify generation of random numbers
-rw-r--r-- | session.py | 31 |
1 files changed, 10 insertions, 21 deletions
@@ -18,6 +18,10 @@ REGISTER_URL = BASE_URL + "register/" STOP_URL = BASE_URL + "stop/" +def random_digits(length: int): + return "".join(random.choice(string.digits) for _ in range(length)) + + class Session: #: Session is running STATUS_RUNNING = "running" @@ -67,12 +71,8 @@ class Session: # Use negative values to ensure we don't do something harmful # to random processes - self.ws_pid = int( - "-" + "".join(random.choice(string.digits) for _ in range(5)) - ) - self.vnc_pid = int( - "-" + "".join(random.choice(string.digits) for _ in range(5)) - ) + self.ws_pid = int("-" + random_digits(5)) + self.vnc_pid = int("-" + random_digits(5)) # Create a temporary file to indicate that this process is still 'Running' filename = f"/tmp/rwa/{str(self.ws_port) + str(self.vnc_port) + str(self.ws_pid) + str(self.vnc_pid)}.lock" @@ -101,21 +101,10 @@ class Session: else: print('"Registered" in RWA') self.meta = {} - self.session_id = int( - "".join(random.choice(string.digits) for _ in range(10)) - ) - self.web_url = ( - "testhostname:" - + "".join(random.choice(string.digits) for _ in range(5)) - + "/RWA/test/" - ) - self.api_token = "".join( - random.choice( - string.ascii_uppercase + string.ascii_lowercase + string.digits - ) - for _ in range(10) - ) - self.pin = int("".join(random.choice(string.digits) for _ in range(5))) + self.session_id = int(random_digits(10)) + self.web_url = "testhostname:" + random_digits(5) + "/RWA/test/" + self.api_token = secrets.token_urlsafe(10) + self.pin = int(random_digits(5)) def _start_trigger_service(self): self.trigger_port = port_for.select_random() |