[docs]defpublic_s3_config(refresh:bool=False,url:str=rest_url(),cache_dir:Optional[str]=None)->dict:"""Get S3 configuration to the bucket storing the data. Users can use this downstream to access the bucket directly using boto3. Args: refresh: Whether to refresh the cached credentials. Defaults to False. url: URL to the gypsum compatible API. cache_dir: Path to the cache directory. Defaults to None. Returns: A dictionary containing the S3 credentials. """creds=Noneifnotrefresh:ifcache_dirisNone:creds=CREDS_CACHE["uncached"]ifcredsisnotNone:returncredselse:creds=CREDS_CACHE["info"].get(cache_dir)ifcredsisnotNone:returncredscache_path=_config_cache_path(cache_dir)ifos.path.exists(cache_path):_lock=FileLock(cache_path+".LOCK")with_lock:withopen(cache_dir,"r")asf:creds=json.load(f)if(time.time()-os.path.getctime(cache_dir))<=(1*7*24*60*60):CREDS_CACHE["info"][cache_dir]=credsreturncredsreq=requests.get(url+"/credentials/s3-api",verify=REQUESTS_MOD["verify"])creds=req.json()ifcache_dirisNone:CREDS_CACHE["uncached"]=credselse:CREDS_CACHE["info"][cache_dir]=credsconfig_path=_config_cache_path(cache_dir)os.makedirs(os.path.dirname(config_path),exist_ok=True)withFileLock(config_path+".LOCK"):withopen(config_path,"w")asf:json.dump(creds,f)returncreds