コード例 #1
0
    def _getToken(self, username):
        """Get authentication token through :func:`authClient.login()`

        Parameters
        ----------
        username : str
            If 'anonymous', use default password and obtain default
            auth token. Otherwise prompt for password while trying to
            obtain a valid auth token.

            :func:`authClient.login() returns either a valid token, or
            an error message (as string), so we check the return value
            using :func:`authClient.isValidToken()`. If this returns
            False, we raise an Exception here.
        """

        if username == 'anonymous':
            token = authClient.login('anonymous', '')
        else:
            #            print("Enter password:"******"Invalid user name and/or password provided. Please try again."
            )
        else:
            print("Authentication successful.")
            return token
コード例 #2
0
    def login(self,user="",password=""):
        if user != "" and password !="":
            token = ac.login(user,password)
        else:
            token = ac.login('anonymous')

        self.__TOKEN_SESSION=token
        return token
コード例 #3
0
    def authenticate(self, handler, data):
        username = data["username"]
        password = data["password"]

        # Allow password-less login for specific users. Typically used
        # for upport purposes only to debug a user's environment.
        if username in self.debug_user:
            return username

        # Punt on any attempted login to excluded account names.
        for user in self.excluded_users:
            if user == username:
                self.log.warning("Auth error: %s: Excluded login denied", user)
                return None

        try:
            authClient.set_svc_url(DEF_SERVICE_URL)
            token = authClient.login(username, password)
            if not authClient.isValidToken(token):
                self.log.warning("Invalid token: %s: %s" % (username, token))
                return None
        except Exception as e:
            self.log.error("Exception Auth error: %s: %s" % (username, str(e)))
            return None

        return data['username']
コード例 #4
0
    def login(self):
        ''' Log-in to the Data Lab.
        '''
        try:
            self.token = self.dl.get(self.user.value, 'authtoken')
            if authClient.isValidToken(self.token):
                # FIXME --  What we really want here is a login-by-token call
                # to the AuthMgr so the login is recorded on the server.
                self.login_error = None
                return True
        except Exception as e:
            pass

        # Get the security token for the user
        self.token = authClient.login(self.user.value, self.password.value)
        if not authClient.isValidToken(self.token):
            self.dl.save("login", "status", "loggedout")
            self.dl.save("login", "user", '')
            self.dl.save("login", "authtoken", '')
            self.dl.save(self.user.value, "authtoken", self.token)
            self.login_error = self.token
            return False
        else:
            self.login_error = None
            return True
コード例 #5
0
def login(dl):
    token = authClient.login('dltest', 'datalab')
    dl.loginuser = '******'
    dl.dl.save("login", "status", "loggedin")
    dl.dl.save("login", "user", "dltest")
    dl.dl.save("login", "authtoken", token)
    dl.dl.save("dltest", "authtoken", token)
    dl.loginstatus = "loggedin"
コード例 #6
0
ファイル: test_authClient.py プロジェクト: lpsinger/datalab
 def test_loginvalid(self):
     token = authClient.login('datalabtest','DataLabTest1')
     self.assertTrue(isValidTokenStructure(token))
     self.assertTrue(isValidTokenCall(token))
     user, uid, gid, hash = token.strip().split('.', 3)
     self.assertEqual(user,'datalabtest')
     self.assertEqual(len(token),56)
     res = logout(token)
コード例 #7
0
ファイル: noao.py プロジェクト: minzastro/lookup
 def __init__(self):
     if os.path.exists(self.LOGIN_FILE):
         try:
             login_data = json.load(open(self.LOGIN_FILE, 'r'))
             self.token = authClient.login(login_data['login'],
                                           password=login_data['password'])
             self.enabled = True
         except ImportError:
             self.enabled = False
     else:
         self.enabled = False
コード例 #8
0
    def __init__(self, coord, radius, **kwargs):
        surveycoord.SurveyCoord.__init__(self, coord, radius, **kwargs)

        #Define photmetric band names.
        self.token = ac.login('anonymous')
        self.bands = []
        #Instantiate sia service
        self.svc = None
        #Generate query
        self.query = None
        self.qc_profile = None
コード例 #9
0
ファイル: surveys.py プロジェクト: yaoyuhan/ztfsub
def download_deepest_image(ra, dec, fov=1.0 / 60.0, band='g'):
    import pyvo.dal
    from pyvo.dal import sia
    from dl import authClient as ac

    pos = SkyCoord(ra=ra, dec=dec, unit=(u.deg, u.deg), frame='icrs')

    url = "https://datalab.noao.edu/sia/des_dr1"
    svc = sia.SIAService(url)
    token = ac.login('anonymous')

    #imgTable = svc.search(pos=pos, size=fov)
    #print(imgTable)
    #print(stop)

    imgTable = pyvo.dal.conesearch(
        url, pos=pos, radius=fov,
        maxrec=100000).votable.get_first_table().to_table()
    sel0 = imgTable['obs_bandpass'].astype(str) == band
    sel = sel0 & (
        (imgTable['proctype'].astype(str) == 'Stack') &
        (imgTable['prodtype'].astype(str) == 'image'))  # basic selection
    Table = imgTable[sel]  # select

    if (len(Table) > 0):
        #row = Table[np.argmax(Table['exptime'].data.data.astype('float'))] # pick image with longest exposure time
        #url = row['access_url'].decode() # get the download URL
        dist = angular_distance(ra, dec,
                                Table["s_ra"].data.data.astype('float'),
                                Table["s_dec"].data.data.astype('float'))
        idx = np.argmin(dist)
        row = Table[idx]
        url = row['access_url'].decode().replace("&extn=1", "")

    else:
        print('No image available.')
        url = None

    return url
コード例 #10
0
else:
    ac.set_svc_url(defauth)

if args.storagemgr:
    sc.set_svc_url(args.storagemgr)
else:
    sc.set_svc_url(defstoragemanager)

if args.token:
    token = args.token
else:
    token = None

while not token:
    token = ac.login(
        args.username,
        getpass.getpass('Enter {} password (+ENTER): '.format(args.username)))

global_debug = args.debug
remote_debug = not global_debug

while global_debug != remote_debug:
    remote_debug = True if sc.sc_client.getFromURL(sc.get_svc_url(), '/debug', None).content.decode().lower() == 'true'\
        else False

if args.seed:
    seed_node = args.seed

LIST_LARGE_ARCH_CONTAINER = False
LIST_ARCH_CONTAINER = False
COPY_DIR_FROM_ARCHIVE = False
コード例 #11
0
ファイル: test_authClient.py プロジェクト: lpsinger/datalab
 def test_loginnotvalid1(self):
     token = authClient.login('temptemptemp','blah')
     self.assertEqual(token,'Error: Username "temptemptemp" does not exist.')
コード例 #12
0
ファイル: test_authClient.py プロジェクト: lpsinger/datalab
 def test_logindltest(self):
     token = authClient.login('dltest','datalab')
     self.assertEqual(token,TEST_TOKEN)
コード例 #13
0
ファイル: test_authClient.py プロジェクト: lpsinger/datalab
 def test_loginnotvalid2(self):
     token = authClient.login('datalabtest','blah')
     self.assertEqual(token,'Error: Invalid password')
コード例 #14
0
ファイル: nsc_dwarfs_hpix.py プロジェクト: dnidever/nscdwarfs
    fileHandler = logging.FileHandler(logfile)
    fileHandler.setFormatter(logFormatter)
    rootLogger.addHandler(fileHandler)

    consoleHandler = logging.StreamHandler()
    consoleHandler.setFormatter(logFormatter)
    rootLogger.addHandler(consoleHandler)
    #rootLogger.setLevel(logging.NOTSET)
    rootLogger.setLevel(logging.INFO)

    rootLogger.info("Searching for overdensities at RA=" + str(ra0) + " DEC=" +
                    str(dec0) + " Radius=" + str(radius) + " on host=" + host)
    #rootLogger.info("  Temporary directory is: "+tmpdir)

    # Either get token for anonymous user
    token = ac.login('anonymous')

    # Authenticated users please uncomment the next line
    #token = ac.login(input("Enter user name: "),getpass("Enter password: "))

    #df0 = getData(ra0,dec0,radius=0.01)
    #print(str(len(df0))+' objects found')
    bcatall = getDataCuts(ra0,
                          dec0,
                          radius=radius,
                          colcutlo=-0.2,
                          colcuthi=0.8,
                          classcut=0.6,
                          fwhmcut=1.5,
                          errcut=0.1)
    rootLogger.info(str(len(bcatall)) + ' objects found')
コード例 #15
0
    #paths = '../01_GettingStartedWithDataLab/'  # test ony notebooks in 01_GetttingStartedWithDataLab/ directory
    #paths = ('../01_GettingStartedWithDataLab/','../02_DataAccessOverview/')  # test notebooks in these two directories
    #paths = ('../01_GettingStartedWithDataLab/02_GettingStartedWithDataLab.ipynb','../02_DataAccessOverview/')  # test one NB in 01... dir, and all NBs in 02... dir
    paths = '../'  # test all notebooks that are not excluded below

    # List pattern of notebook names, and/or paths, to exclude from testing.
    # ** means "any number of intermediate directries"
    # * means "any number if intermediate characters in this directory"
    # A few default notebooks are explicitly excluded here b/c they absolutely require interactive execution.
    # A few others are temporarily excluded until they will be fixed.
    exclude = ('**/*AuthClient.ipynb', '**/Rowstore*.ipynb',
               '**/e-Teen*/**/*ipynb')

    # log in to Data Lab once
    cprint('Login to Data Lab', color='yellow', bar=0, pad='')
    token = login(input('Username: '******'Password: '******'Total runtime: %g seconds' % (stop - start),
           color='yellow',
           bar=0,
           pad='',
           newline=True)

    cprint('TEST RESULT MATRIX', color='yellow', bar=0, pad='')
    print(testresults.data)
    print()
コード例 #16
0
ファイル: search-datalab.py プロジェクト: shiaki/sforzando
import sys
import json
from collections import OrderedDict, namedtuple

import numpy as np
from tqdm import tqdm

from astropy.coordinates import SkyCoord
from dl import authClient as ac, queryClient as qc
from dl.helpers.utils import convert
from getpass import getpass

if __name__ == '__main__':

    # initialize datalab
    token = ac.login(input('Data Lab user name: '), getpass('Password: '******'candidate-events.json', 'r') as fp:
        candidate_events = json.load(fp, object_pairs_hook=OrderedDict)

    if os.path.isfile('candidate-hosts-dl.json'):
        with open('candidate-hosts-dl.json', 'r') as fp:
            candidate_hosts = json.load(fp, object_pairs_hook=OrderedDict)
    else:
        candidate_hosts = OrderedDict()

    # 'radius' of the box.
    box_radius = 60. / 60. / 60.  # 60 asec in degrees

    # for each event: search for