| 53 | |
| 54 | |
| 55 | class Client(object): |
| 56 | def __init__( |
| 57 | self, |
| 58 | base_url=None, |
| 59 | auth_url=None, |
| 60 | api_url=None, |
| 61 | stream_url=None, |
| 62 | api_version=None, |
| 63 | cacert=None, |
| 64 | debug=False, |
| 65 | token=None, |
| 66 | api_key=None, |
| 67 | basic_auth=None, |
| 68 | ): |
| 69 | # Get CLI options. If not given, then try to get it from the environment. |
| 70 | self.endpoints = dict() |
| 71 | |
| 72 | # Populate the endpoints |
| 73 | if base_url: |
| 74 | self.endpoints["base"] = base_url |
| 75 | else: |
| 76 | self.endpoints["base"] = os.environ.get("ST2_BASE_URL", DEFAULT_BASE_URL) |
| 77 | |
| 78 | api_version = api_version or os.environ.get( |
| 79 | "ST2_API_VERSION", DEFAULT_API_VERSION |
| 80 | ) |
| 81 | |
| 82 | self.endpoints["exp"] = "%s:%s/%s" % ( |
| 83 | self.endpoints["base"], |
| 84 | DEFAULT_API_PORT, |
| 85 | "exp", |
| 86 | ) |
| 87 | |
| 88 | if api_url: |
| 89 | self.endpoints["api"] = api_url |
| 90 | else: |
| 91 | self.endpoints["api"] = os.environ.get( |
| 92 | "ST2_API_URL", |
| 93 | "%s:%s/%s" % (self.endpoints["base"], DEFAULT_API_PORT, api_version), |
| 94 | ) |
| 95 | |
| 96 | if auth_url: |
| 97 | self.endpoints["auth"] = auth_url |
| 98 | else: |
| 99 | self.endpoints["auth"] = os.environ.get( |
| 100 | "ST2_AUTH_URL", "%s:%s" % (self.endpoints["base"], DEFAULT_AUTH_PORT) |
| 101 | ) |
| 102 | |
| 103 | if stream_url: |
| 104 | self.endpoints["stream"] = stream_url |
| 105 | else: |
| 106 | self.endpoints["stream"] = os.environ.get( |
| 107 | "ST2_STREAM_URL", |
| 108 | "%s:%s/%s" % (self.endpoints["base"], DEFAULT_STREAM_PORT, api_version), |
| 109 | ) |
| 110 | |
| 111 | if cacert is not None: |
| 112 | self.cacert = cacert |
no outgoing calls