diff --git a/requirements.txt b/requirements.txt index bbf6ede..a63b24f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ colorlog==4.4.0 coverage==5.3 flake8==3.8.4 flake8-polyfill==1.0.2 -future==0.18.2 +future==0.18.3 gitdb==4.0.5 GitPython==3.1.11 idna==2.10 diff --git a/sciencebasepy/SbSession.py b/sciencebasepy/SbSession.py index f0e8b35..a2198f2 100644 --- a/sciencebasepy/SbSession.py +++ b/sciencebasepy/SbSession.py @@ -1273,60 +1273,115 @@ def remove_acl_role_write(self, role_name, item_id): """ return self._update_acls(self.ACL_REMOVE, self.ACL_WRITE, "ROLE:%s" % role_name, item_id) - def publish_to_public_bucket(self, item_id): - """ call publish end point from catalog - this should publish all files to public s3 publish bucket - TODO: Fix documentation - """ - return self._session.post(self._base_item_url + item_id + "/publishFilesToS3") - def publish_array_to_public_bucket(self, item_id, filenames): - """ publish a list of files on an item to the public s3 publish bucket + """publish a list of files on an item from the public s3 publish bucket :param item_id: The ID of the ScienceBase item - :param filenames: a list of filenames to be published + :param filenames: a list of filenames to be unpublished """ - for filename in filenames: + if not self._sbSessionEx.is_logged_in(): + print(f'{self._username} not logged into Keycloak -- cloud services not available') + else: item = self.get_item(item_id) - pathOnDisk = "" - cuid = "" - if 'files' in item: - for f in item['files']: - if 'name' in f: - if f['name'] == filename: - if 'pathOnDisk' in f: - pathOnDisk = f['pathOnDisk'] - if 'cuid' in f: - cuid = f['cuid'] - break - if pathOnDisk == "": - if 'facets' in item: - for facet in item['facets']: - if 'files' in facet: - for f in facet['files']: - if f['name'] == filename: - if 'pathOnDisk' in f: - pathOnDisk = f['pathOnDisk'] - if 'cuid' in f: - cuid = f['cuid'] - break - - publishDict = { - "filename": filename, - "actionValue": "publish", - "cuid": cuid, - "pathOnDisk": pathOnDisk - } - - response = self._session.post(self._base_item_url + item_id + "/publishSingleFileToS3", - data=json.dumps(publishDict)) - print(response) + for filename in filenames: + cuid = "" + key = "" + pathOnDisk = "" - if response: - print("Successfully published filename " + filename + " to public S3 bucket") - else: - print("Failed to publish file " + filename + " to public S3 bucket") + if 'files' in item: + for f in item['files']: + if 'name' in f: + if f['name'] == filename: + if 'pathOnDisk' in f: + pathOnDisk = f['pathOnDisk'] + if 'cuid' in f: + cuid = f['cuid'] + if 'key' in f: + key = f['key'] + break + + if cuid == "": + if 'facets' in item: + for facet in item['facets']: + if 'files' in facet: + for f in facet['files']: + if f['name'] == filename: + if 'pathOnDisk' in f: + pathOnDisk = f['pathOnDisk'] + if 'cuid' in f: + cuid = f['cuid'] + if 'key' in f: + key = f['key'] + break + + if cuid is None: + cuid = "" + + input = {"itemId": item_id, "filename": filename, "action": "publish", "pathOnDisk": pathOnDisk} + + response = self._sbSessionEx.publish_to_public_bucket(input) + print(response) + if response: + print("Successfully published filename " + filename + " from public S3 bucket") + else: + print("Failed to publish file " + filename + " from public S3 bucket") + + + # def publish_to_public_bucket(self, item_id): + # """ call publish end point from catalog + # this should publish all files to public s3 publish bucket + # TODO: Fix documentation + # """ + # return self._session.post(self._base_item_url + item_id + "/publishFilesToS3") + + # def publish_array_to_public_bucket(self, item_id, filenames): + # """ publish a list of files on an item to the public s3 publish bucket + + # :param item_id: The ID of the ScienceBase item + # :param filenames: a list of filenames to be published + # """ + # for filename in filenames: + # item = self.get_item(item_id) + # pathOnDisk = "" + # cuid = "" + + # if 'files' in item: + # for f in item['files']: + # if 'name' in f: + # if f['name'] == filename: + # if 'pathOnDisk' in f: + # pathOnDisk = f['pathOnDisk'] + # if 'cuid' in f: + # cuid = f['cuid'] + # break + # if pathOnDisk == "": + # if 'facets' in item: + # for facet in item['facets']: + # if 'files' in facet: + # for f in facet['files']: + # if f['name'] == filename: + # if 'pathOnDisk' in f: + # pathOnDisk = f['pathOnDisk'] + # if 'cuid' in f: + # cuid = f['cuid'] + # break + + # publishDict = { + # "filename": filename, + # "actionValue": "publish", + # "cuid": cuid, + # "pathOnDisk": pathOnDisk + # } + + # response = self._session.post(self._base_item_url + item_id + "/publishSingleFileToS3", + # data=json.dumps(publishDict)) + # print(response) + + # if response: + # print("Successfully published filename " + filename + " to public S3 bucket") + # else: + # print("Failed to publish file " + filename + " to public S3 bucket") def unpublish_array_from_public_bucket(self, item_id, filenames): """unpublish a list of files on an item from the public s3 publish bucket