def check_reference_open(refpath): """Verify that `refpath` exists and is readable for the current user. Ignore reference path values of "N/A" or "" for checking. """ if refpath != "N/A" and refpath.strip() != "": if s3_utils.is_s3_uri(refpath): if not s3_utils.object_exists(refpath): raise RuntimeError("S3 object does not exist: " + refpath) else: with open(refpath, "rb"): pass return refpath
def _load_config_file_s3(config_file): if not s3_utils.object_exists(config_file): raise ValueError("Config file {0} not found.".format(config_file)) content = s3_utils.get_object(config_file) try: with asdf_open(content) as asdf_file: return _config_obj_from_asdf(asdf_file) except (AsdfValidationError, ValueError): logger.debug( 'Config file did not parse as ASDF. Trying as ConfigObj: %s', config_file) content.seek(0) return ConfigObj(content, raise_errors=True)
def test_object_exists(s3_text_file): assert s3_utils.object_exists("s3://test-s3-data/test.txt") is True assert s3_utils.object_exists("s3://test-s3-data/missing.fits") is False assert s3_utils.object_exists("s3://missing-bucket/test.txt") is False