def test_logon(): _clear_creds() _load_creds(certificates_tarball='pcmdi9-certs.tar.gz') lm = LogonManager(esgf_dir) lm.logon(TEST_USER, TEST_PASSWORD, TEST_MYPROXY) assert lm.is_logged_on()
def main(): #--- input user credential -- username='******' password='******' #---------------------------- #--- input search criteria -- project='ISIMIP2b' model='GFDL-ESM2M' impact_model='WaterGAP2' experiment ='rcp45' variable='Discharge' # Loging in lm = LogonManager() lm.logoff() lm.is_logged_on() OPENID = 'https://esgf-data.dkrz.de/esgf-idp/openid/'+username myproxy_host = 'esgf-data.dkrz.de' lm.logon_with_openid(openid=OPENID, password=password, bootstrap=True) lm.logon(hostname=myproxy_host,interactive=False, username=username,password=password,bootstrap=True) lm.is_logged_on() # Open connection with potsam node (ISIMIP) conn = SearchConnection('http://esg.pik-potsdam.de/esg-search', distrib=False) # Search datasets # can do general searches e.g., search for all datasets in ISIMIP2b with experiment='rcp45'. This will return all instances in ctx ctx = conn.new_context( project=project, model=model, impact_model=impact_model, experiment=experiment, variable_long_name=variable) # list number of counts print('Founds '+str(ctx.hit_count)+' matching datasets') # grab search results and display them a=ctx.search() cnt=1 for i in a : print('['+str(cnt)+']'+' -----> '+i.dataset_id) print('- - - - - - - - - - - - - - - - - - - - - - - -') cnt = cnt + 1 # Ask user to choose a dataset or to download all num = input("Which one should I download master? [Type -1 for all, 3 for third listed dataset.]") # Case where user select a specific dataset if num != -1: print("Downloading dataset "+str(num)+".") wget_makeNrun(a[num-1].file_context()) # case where user selects all elif num == -1: print("Downloading all "+str(ctx.hit_count)+" datasets.") for i in a: print("Downloading all datasets returned in search.") wget_makeNrun(i.file_context()) return 0
def test_logon(self, extra_args=None): _clear_creds(self.esgf_dir) _load_creds(self.esgf_dir, certificates_tarball='pcmdi9-certs.tar.gz') if not extra_args: extra_args = {} lm = LogonManager(self.esgf_dir, **extra_args) lm.logon(TEST_USER, TEST_PASSWORD, TEST_MYPROXY) assert lm.is_logged_on()
def logon(host=DKRZ_HOST): """logon to ESGF Host.""" from pyesgf.logon import LogonManager print("logon to: ".format(host)) lm = LogonManager() lm.logoff() lm.logon(hostname=host, interactive=True, bootstrap=True) print("logged on: {}".format(lm.is_logged_on())) return lm.is_logged_on()
def logon(username=None, password=None, hostname=None, interactive=False, outdir=None): """ Logon to MyProxy and fetch proxy certificate. """ outdir = outdir or os.curdir lm = LogonManager(esgf_dir=outdir, dap_config=os.path.join(outdir, 'dodsrc')) lm.logoff() # logon lm.logon(username=username, password=password, hostname=hostname, bootstrap=True, update_trustroots=False, interactive=interactive) return os.path.join(outdir, ESGF_CREDENTIALS)
def auth(self): ''' Authenticate with the auth server specified on object creation. ''' # Check that we're logged on lm = LogonManager() log.debug('Logon manager started') if not lm.is_logged_on(): log.debug(self.username, self.password, self.auth_server) lm.logon(self.username, self.password, self.auth_server) if not lm.is_logged_on(): raise Exception('NOAUTH')
def test_logoff(): lm = LogonManager(esgf_dir) # Only re-logon if credentials are not valid if not lm.is_logged_on(): lm.logon(TEST_USER, TEST_PASSWORD, TEST_MYPROXY, bootstrap=True) assert lm.is_logged_on() lm.logoff() assert not op.exists(op.join(esgf_dir, 'credentials.pem')) assert not lm.is_logged_on() assert lm.state == lm.STATE_NO_CREDENTIALS
def myproxy_logon_with_openid(openid, password=None, interactive=False, outdir=None): """ Tries to get MyProxy parameters from OpenID and calls :meth:`logon`. :param openid: OpenID used to login at ESGF node. """ outdir = outdir or os.curdir username, hostname, port = parse_openid(openid) lm = LogonManager(esgf_dir=outdir, dap_config=os.path.join(outdir, 'dodsrc')) lm.logoff() lm.logon(username=username, password=password, hostname=hostname, bootstrap=True, update_trustroots=False, interactive=interactive) return os.path.join(outdir, ESGF_CREDENTIALS)
def logon(username=None, password=None, hostname=None, interactive=False, outdir=None): """ Logon to MyProxy and fetch proxy certificate. """ outdir = outdir or os.curdir # use myproxy patch # TODO: update to myproxyclient 2.x from phoenix.patch import patch_myproxy_client patch_myproxy_client() # end patch lm = LogonManager(esgf_dir=outdir, dap_config=os.path.join(outdir, 'dodsrc')) lm.logoff() lm.logon(username=username, password=password, hostname=hostname, bootstrap=True, update_trustroots=False, interactive=interactive) return os.path.join(outdir, ESGF_CREDENTIALS)
def test_bootstrap(): _clear_creds() lm = LogonManager(esgf_dir) lm.logon(TEST_USER, TEST_PASSWORD, TEST_MYPROXY, bootstrap=True) assert lm.is_logged_on()
"""Example for plotting all orographies with OoPlot by accessing the ESGF database. """ import cordex.plot as crxplt from pyesgf.search import SearchConnection from pyesgf.logon import LogonManager # logon to ESGF node print('logon to ESGF') lm = LogonManager() lm.logoff() lm.logon(hostname='esgf-data.dkrz.de', interactive=True, bootstrap=True) print('logged on: {}'.format(lm.is_logged_on())) def plot_orog(filename, output): """plots the orog variable to output file. """ var = 'orog' crxplt.contour2(filename, var, output) # search CORDEX project for REMO2015 fx orog variables conn = SearchConnection('http://esgf-data.dkrz.de/esg-search', distrib=False) ctx = conn.new_context(project='CORDEX', experiment='evaluation', time_frequency='fx', rcm_name='REMO2015', variable='orog') result = ctx.search()