Merge pull request #3 from slashtechno/deepsource-autofix-908ab65d

refactor unnecessary `else` / `elif` when `if` block has a `raise` statement
This commit is contained in:
/techno 2023-08-06 19:04:03 -04:00 committed by GitHub
commit 61990cfa4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 18 deletions

View File

@ -19,21 +19,19 @@ class Config:
def token(self, token): def token(self, token):
if token is None: if token is None:
raise ValueError("No token provided") raise ValueError("No token provided")
else: url = "https://api.cloudflare.com/client/v4/user/tokens/verify"
url = "https://api.cloudflare.com/client/v4/user/tokens/verify" headers = {
headers = { "Authorization": f"Bearer {token}",
"Authorization": f"Bearer {token}", "Content-Type": "application/json",
"Content-Type": "application/json", }
} response = requests.get(url, headers=headers, timeout=10)
response = requests.get(url, headers=headers, timeout=10) if response.json()["success"] is False:
if response.json()["success"] is False: raise ValueError("Invalid token")
raise ValueError("Invalid token") # Token needs the following scopes:
else: # Zero Trust: Read/Edit
# Token needs the following scopes: # Account Firewall Access Rules: Read/Edit
# Zero Trust: Read/Edit # Access Apps and Policies: Read/Edit
# Account Firewall Access Rules: Read/Edit self._token = token
# Access Apps and Policies: Read/Edit
self._token = token
@property @property
def account_id(self): def account_id(self):
@ -43,9 +41,8 @@ class Config:
def account_id(self, account_id): def account_id(self, account_id):
if account_id is None: if account_id is None:
raise ValueError("No account ID provided") raise ValueError("No account ID provided")
else: # Possibly make a request to lists to check if the account ID exists
# Possibly make a request to lists to check if the account ID exists self._account_id = account_id
self._account_id = account_id
# List Utils # List Utils