Skip to content

Commit 9aea577

Browse files
author
Michael Bianchi
committed
Allow override of authtype
1 parent fd69d5f commit 9aea577

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

pingdomWrapper.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@
1111
import sys
1212
from enum import Enum
1313

14-
14+
# Set up basic logger
1515
logger = logging.getLogger('pingdom.pingdomWrapper')
16-
handler = logging.StreamHandler(sys.stdout)
17-
logger.addHandler(handler)
16+
17+
# Setup stdout logger
18+
soh = logging.StreamHandler(sys.stdout)
19+
# Can optionally set logging levels per handler
20+
# soh.setLevel(logging.WARN)
21+
logger.addHandler(soh)
22+
23+
# File handler for logging to a file
24+
# fh = logging.FileHandler('apiWrapper.log')
25+
# fh.setLevel(logging.DEBUG)
26+
# logger.addHandler(fh)
1827

1928
# Get log level from env vars
2029
log_level = os.environ.get('LOG_LEVEL', 'INFO').upper()
@@ -46,7 +55,8 @@ def __init__(
4655
client_app_secret=None,
4756
user_oauth_token=None,
4857
user_oauth_token_secret=None,
49-
api_app_key=None
58+
api_app_key=None,
59+
auth_type=None
5060
):
5161
'''Set up client for API communications
5262
This is where you'll need to specify all the authentication and
@@ -67,7 +77,8 @@ def __init__(
6777
# If interested in using a config file instead of env vars, load with
6878
# self._load_key(config_key, path)
6979
# Feel free to clear out auth methods not implemented by the API
70-
auth_type = AuthType[os.getenv('AUTHTYPE', default='NONE')]
80+
if not auth_type:
81+
auth_type = AuthType[os.getenv('AUTHTYPE', default='NONE')]
7182
if (auth_type == AuthType.HTTPBASICAUTH or
7283
auth_type == AuthType.HTTPDIGESTAUTH):
7384
if not user:
@@ -343,7 +354,11 @@ def create_new_maintenance_window(
343354

344355

345356
if __name__ == "__main__":
346-
account = Pingdom('[email protected]', 'password')
357+
account = Pingdom(
358+
359+
'password',
360+
auth_type=AuthType.HTTPBASICAUTH
361+
)
347362
from_datetime = datetime.now()
348363
to_datetime = datetime.now() + timedelta(1)
349364
account.list_checks()

0 commit comments

Comments
 (0)