| 26 | bearerToken = None |
| 27 | |
| 28 | def __init__(self, apiKey=None, apiAddress=None, caCert=None, bearerToken=None): |
| 29 | # Override apiKey with environment variable |
| 30 | config = None |
| 31 | self.requestSession = requests.Session() |
| 32 | if apiKey is None and 'ALGORITHMIA_API_KEY' in os.environ: |
| 33 | apiKey = os.environ['ALGORITHMIA_API_KEY'] |
| 34 | elif bearerToken is None and 'ALGORITHMIA_BEARER_TOKEN' in os.environ: |
| 35 | bearerToken = os.environ['ALGORITHMIA_BEARER_TOKEN'] |
| 36 | |
| 37 | self.bearerToken = bearerToken |
| 38 | self.apiKey = apiKey |
| 39 | if apiAddress is not None: |
| 40 | self.apiAddress = apiAddress |
| 41 | else: |
| 42 | self.apiAddress = Algorithmia.getApiAddress() |
| 43 | if caCert == False: |
| 44 | self.requestSession.verify = False |
| 45 | self.requestSession.trust_env = False |
| 46 | config = Configuration(use_ssl=False) |
| 47 | elif caCert is None and 'REQUESTS_CA_BUNDLE' in os.environ: |
| 48 | caCert = os.environ.get('REQUESTS_CA_BUNDLE') |
| 49 | self.catCerts(caCert) |
| 50 | self.requestSession.verify = self.ca_cert |
| 51 | elif caCert is not None and 'REQUESTS_CA_BUNDLE' not in os.environ: |
| 52 | self.catCerts(caCert) |
| 53 | self.requestSession.verify = self.ca_cert |
| 54 | elif caCert is not None and 'REQUESTS_CA_BUNDLE' in os.environ: |
| 55 | # if both are available, use the one supplied in the constructor. I assume that a user supplying a cert in initialization wants to use that one. |
| 56 | self.catCerts(caCert) |
| 57 | self.requestSession.verify = self.ca_cert |
| 58 | |
| 59 | if not config: |
| 60 | config = Configuration() |
| 61 | |
| 62 | config.api_key['Authorization'] = self.apiKey |
| 63 | config.host = "{}/v1".format(self.apiAddress) |
| 64 | self.manageApi = DefaultApi(ApiClient(config)) |
| 65 | |
| 66 | def algo(self, algoRef): |
| 67 | return Algorithm(self, algoRef) |