Skip to content

Commit 3e6e6ea

Browse files
committed
Make bucket_name optional
1 parent 7a27605 commit 3e6e6ea

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

python/ibmos2spark/osconfig.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,17 @@ def url(self, container_name, object_name):
174174

175175
class CloudObjectStorage(object):
176176

177-
def __init__(self, sparkcontext, bucket_name, credentials):
177+
def __init__(self, sparkcontext, credentials, bucket_name=''):
178178

179179
'''
180180
sparkcontext: a SparkContext object.
181181
182-
bucket_name (projectId in DSX): string that identifies the bucket you want
182+
bucket_name (projectId in DSX) [optional]: string that identifies the bucket you want
183183
to access files from in the COS service instance.
184184
In DSX, bucket_name is the same as projectId. One bucket is
185185
associated with one project.
186+
If this value is not specified, you need to pass it when
187+
you use the url function.
186188
187189
credentials: a dictionary with the following required keys:
188190
* endpoint
@@ -194,7 +196,6 @@ def __init__(self, sparkcontext, bucket_name, credentials):
194196
choose the datasource you want to access then hit insert credentials.
195197
196198
'''
197-
198199
self.bucket_name = bucket_name
199200

200201
# check if all required values are availble
@@ -212,5 +213,13 @@ def __init__(self, sparkcontext, bucket_name, credentials):
212213
hconf.set(prefix + ".access.key", credentials['access_key'])
213214
hconf.set(prefix + ".secret.key", credentials['secret_key'])
214215

215-
def url(self, object_name):
216-
return "s3d://{}.service/{}".format(self.bucket_name, object_name)
216+
def url(self, object_name, bucket_name=''):
217+
bucket_name_var = ''
218+
if (bucket_name):
219+
bucket_name_var = bucket_name
220+
elif (self.bucket_name):
221+
bucket_name_var = self.bucket_name
222+
else:
223+
raise ValueError("Invalid input: bucket_name is required!")
224+
225+
return "s3d://{}.service/{}".format(bucket_name_var, object_name)

0 commit comments

Comments
 (0)