Skip to content

Commit

Permalink
Merge pull request #11 from BIDMCDigitalPsychiatry/connect_environ
Browse files Browse the repository at this point in the history
Optionally get access_key and secret_key from environmental vars
  • Loading branch information
avaidyam authored May 6, 2021
2 parents 181d5da + f373524 commit e05db52
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion LAMP/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


from __future__ import absolute_import
import os

__version__ = "develop"

Expand Down Expand Up @@ -74,7 +75,15 @@
SensorSpec = SensorEventApi()
SensorEvent = SensorEventApi()

def connect(access_key, secret_key, server_address="api.lamp.digital"):
def connect(access_key=None, secret_key=None, server_address=None):
if access_key is None and secret_key is None:
access_key = os.getenv('LAMP_ACCESS_KEY')
secret_key = os.getenv('LAMP_SECRET_KEY')
if server_address is None: # let arg override environmental var
server_address = os.getenv('LAMP_SERVER_ADDRESS', 'api.lamp.digital')
if access_key is None or secret_key is None:
raise TypeError("connect() requires 2 positional arguments: 'access_key' and 'secret_key', unless environmental variables 'LAMP_ACCESS_KEY' and 'LAMP_SECRET_KEY' are provided")

client = ApiClient(Configuration(host=f"https://{server_address}", username=access_key, password=secret_key))

global API
Expand Down

0 comments on commit e05db52

Please sign in to comment.