11import json
22from dataclasses import dataclass
33from pathlib import Path
4- from typing import Any , Optional
4+ from typing import Optional
55
66from requests .auth import AuthBase
77
@@ -22,17 +22,14 @@ def __init__(
2222 STACKIT_SERVICE_ACCOUNT_TOKEN : str = None ,
2323 STACKIT_SERVICE_ACCOUNT_KEY_PATH : str = None ,
2424 STACKIT_PRIVATE_KEY_PATH : str = None ,
25+ ** kwargs ,
2526 ):
2627 self .service_account_mail = STACKIT_SERVICE_ACCOUNT_EMAIL
2728 self .service_account_token = STACKIT_SERVICE_ACCOUNT_TOKEN
2829 self .service_account_key_path = STACKIT_SERVICE_ACCOUNT_KEY_PATH
2930 self .private_key_path = STACKIT_PRIVATE_KEY_PATH
3031
3132
32- def either_this_or_that (this : Any , that : Any ) -> Optional [Any ]:
33- return this if this else that
34-
35-
3633class Authorization :
3734 DEFAULT_CREDENTIALS_FILE_PATH = ".stackit/credentials.json"
3835 service_account_mail : Optional [str ] = None
@@ -45,16 +42,26 @@ class Authorization:
4542
4643 def __init__ (self , configuration : Configuration ):
4744 credentials = self .__read_credentials_file (configuration .credentials_file_path )
48- self .service_account_mail = either_this_or_that (
49- configuration .service_account_mail , credentials .service_account_mail
45+ self .service_account_mail = (
46+ configuration .service_account_mail
47+ if configuration .service_account_mail is not None
48+ else credentials .service_account_mail
49+ )
50+ self .service_account_token = (
51+ configuration .service_account_token
52+ if configuration .service_account_token is not None
53+ else credentials .service_account_token
5054 )
51- self .service_account_token = either_this_or_that (
52- configuration .service_account_token , credentials .service_account_token
55+ self .service_account_key_path = (
56+ configuration .service_account_key_path
57+ if configuration .service_account_key_path is not None
58+ else credentials .service_account_key_path
5359 )
54- self .service_account_key_path = either_this_or_that (
55- configuration .service_account_key_path , credentials .service_account_key_path
60+ self .private_key_path = (
61+ configuration .private_key_path
62+ if configuration .private_key_path is not None
63+ else credentials .private_key_path
5664 )
57- self .private_key_path = either_this_or_that (configuration .private_key_path , credentials .private_key_path )
5865 self .auth_method = configuration .custom_auth
5966 self .token_endpoint = configuration .token_endpoint
6067 self .__read_keys ()
0 commit comments