|
26 | 26 | from time import time, sleep, gmtime, strftime |
27 | 27 |
|
28 | 28 | import requests |
| 29 | +import six |
29 | 30 | import six.moves.urllib.parse as urlparse |
30 | 31 |
|
31 | 32 | from .auth import JWT, Auth, AccessRequest |
@@ -69,7 +70,12 @@ def __init__(self, |
69 | 70 | :param tech_acct_id: string technical account ID from Adobe.IO integration data |
70 | 71 | :param api_key: string api_key from Adobe.IO integration data |
71 | 72 | :param client_secret: string client secret from Adobe.IO integration data |
| 73 | + and one of: |
72 | 74 | :param private_key_file: path to local private key file that matches Adobe.IO public key for integration |
| 75 | + or: |
| 76 | + :param private_key_data: the contents of the private_key_file (PEM format) |
| 77 | + (NOTE: for compatibility with User Sync config files, the key names priv_key_path and tech_acct |
| 78 | + are accepted as aliases for private_key_file and tech_acct_id, respectively.) |
73 | 79 |
|
74 | 80 | Optional connection parameters (defaults are for Adobe production): |
75 | 81 | :param ims_host: the IMS host which will exchange your JWT for an access token |
@@ -121,14 +127,18 @@ def __init__(self, |
121 | 127 | self.session.headers["User-Agent"] = ua_string |
122 | 128 |
|
123 | 129 | def _get_auth(self, ims_host, ims_endpoint_jwt, |
124 | | - tech_acct_id=None, api_key=None, client_secret=None, private_key_file=None, |
| 130 | + tech_acct_id=None, api_key=None, client_secret=None, |
| 131 | + private_key_file=None, private_key_data=None, |
125 | 132 | **kwargs): |
126 | 133 | tech_acct_id = tech_acct_id or kwargs.get("tech_acct") |
127 | 134 | private_key_file = private_key_file or kwargs.get("priv_key_path") |
128 | | - if not (tech_acct_id and api_key and client_secret and private_key_file): |
| 135 | + if not (tech_acct_id and api_key and client_secret and (private_key_data or private_key_file)): |
129 | 136 | raise ValueError("Connector create: not all required auth parameters were supplied; please see docs") |
130 | | - with open(private_key_file, 'r') as private_key_stream: |
131 | | - jwt = JWT(self.org_id, tech_acct_id, ims_host, api_key, private_key_stream) |
| 137 | + if private_key_data: |
| 138 | + jwt = JWT(self.org_id, tech_acct_id, ims_host, api_key, six.StringIO(private_key_data)) |
| 139 | + else: |
| 140 | + with open(private_key_file, 'r') as private_key_stream: |
| 141 | + jwt = JWT(self.org_id, tech_acct_id, ims_host, api_key, private_key_stream) |
132 | 142 | token = AccessRequest("https://" + ims_host + ims_endpoint_jwt, api_key, client_secret, jwt()) |
133 | 143 | return Auth(api_key, token()) |
134 | 144 |
|
|
0 commit comments