|
23 | 23 |
|
24 | 24 |
|
25 | 25 | from oauth2client.client import OAuth2Credentials |
26 | | -from oauth2client.client import SignedJwtAssertionCredentials |
27 | 26 |
|
28 | 27 | from google.cloud.dataflow.utils import processes |
29 | 28 | from google.cloud.dataflow.utils.options import GoogleCloudOptions |
@@ -124,19 +123,33 @@ def get_service_credentials(): |
124 | 123 | raise Exception('key file not provided for service account.') |
125 | 124 | if not os.path.exists(google_cloud_options.service_account_key_file): |
126 | 125 | raise Exception('Specified service account key file does not exist.') |
127 | | - with file(google_cloud_options.service_account_key_file) as f: |
128 | | - service_account_key = f.read() |
129 | 126 | client_scopes = [ |
130 | 127 | 'https://www.googleapis.com/auth/bigquery', |
131 | 128 | 'https://www.googleapis.com/auth/cloud-platform', |
132 | 129 | 'https://www.googleapis.com/auth/devstorage.full_control', |
133 | 130 | 'https://www.googleapis.com/auth/userinfo.email', |
134 | 131 | 'https://www.googleapis.com/auth/datastore' |
135 | 132 | ] |
136 | | - return SignedJwtAssertionCredentials( |
137 | | - google_cloud_options.service_account_name, |
138 | | - service_account_key, |
139 | | - client_scopes, |
140 | | - user_agent=user_agent) |
| 133 | + |
| 134 | + # The following code uses oauth2client >=2.0.0 functionality and if this |
| 135 | + # is not available due to import errors will use 1.5.2 functionality. |
| 136 | + # TODO(silviuc): Remove the 1.5.2 when dependencies have been updated. |
| 137 | + try: |
| 138 | + from oauth2client.service_account import ServiceAccountCredentials |
| 139 | + return ServiceAccountCredentials.from_p12_keyfile( |
| 140 | + google_cloud_options.service_account_name, |
| 141 | + google_cloud_options.service_account_key_file, |
| 142 | + client_scopes, |
| 143 | + user_agent=user_agent) |
| 144 | + except ImportError: |
| 145 | + with file(google_cloud_options.service_account_key_file) as f: |
| 146 | + service_account_key = f.read() |
| 147 | + from oauth2client.client import SignedJwtAssertionCredentials |
| 148 | + return SignedJwtAssertionCredentials( |
| 149 | + google_cloud_options.service_account_name, |
| 150 | + service_account_key, |
| 151 | + client_scopes, |
| 152 | + user_agent=user_agent) |
| 153 | + |
141 | 154 | else: |
142 | 155 | return _GCloudWrapperCredentials(user_agent) |
0 commit comments