Skip to content

Commit d883a5e

Browse files
committed
set up hadoop config with the new bluemix cos creds
1 parent ca8e0cc commit d883a5e

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

python/ibmos2spark/osconfig.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,11 @@ def __init__(self, sparkcontext, credentials, configuration_name='', cos_type='c
192192
193193
'''
194194
# check if all required values are availble
195-
_validate_input(credentials, cos_type, auth_method)
195+
self._validate_input(credentials, cos_type, auth_method)
196196

197197
self.bucket_name = bucket_name
198198
self.conf_name = configuration_name
199199

200-
credential_key_list = ["endpoint", "access_key", "secret_key"]
201-
202-
for i in range(len(credential_key_list)):
203-
key = credential_key_list[i]
204-
if (not key in credentials):
205-
raise ValueError("Invalid input: credentials.{} is required!".format(key))
206-
207200
# setup config
208201
prefix = "fs.cos"
209202

@@ -214,8 +207,20 @@ def __init__(self, sparkcontext, credentials, configuration_name='', cos_type='c
214207

215208
hconf = sparkcontext._jsc.hadoopConfiguration()
216209
hconf.set(prefix + ".endpoint", credentials['endpoint'])
217-
hconf.set(prefix + ".access.key", credentials['access_key'])
218-
hconf.set(prefix + ".secret.key", credentials['secret_key'])
210+
211+
if (cos_type == "classic_cos"):
212+
hconf.set(prefix + ".access.key", credentials['access_key'])
213+
hconf.set(prefix + ".secret.key", credentials['secret_key'])
214+
215+
elif (cos_type == "bluemix_cos"):
216+
hconf.set(prefix + ".iam.service.id", credentials['service_id'])
217+
if (auth_method == "api_key"):
218+
hconf.set(prefix + ".iam.api.key", credentials['api_key'])
219+
elif (auth_method == "iam_token"):
220+
hconf.set(prefix + ".iam.token", credentials['iam_token'])
221+
222+
if (credentials.get('v2_signer_type')):
223+
hconf.set(prefix + ".v2.signer.type", credentials['v2_signer_type'])
219224

220225
def _validate_input(self, credentials, cos_type, auth_method):
221226
required_key_classic_cos = ["endpoint", "access_key", "secret_key"]

0 commit comments

Comments
 (0)