Exemplo n.º 1
0
    def login(self, refresh=None):
        ''' Login with netrc credentials to receive an API token

        Copy this token into the "use_token" parameter in your
        custom marvin.yml file to ensure preserve authentication
        across iPython user sessions.

        Parameters:
            refresh (bool):
                Set to True to refresh a login to receive a new token

        '''

        assert config.access == 'collab', 'You must have collaboration access to login.'

        # do nothing if token already generated
        if self.token and not refresh:
            return

        valid_netrc = bconfig._check_netrc()
        if valid_netrc:
            # get login info for api.sdss.org
            user, password = bconfig._read_netrc('api.sdss.org')
            data = {'username': user, 'password': password}

            # send token request
            url = self.urlmap['api']['login']['url']
            try:
                resp = Interaction(url, params=data, auth='netrc')
            except Exception as e:
                raise MarvinError('Error getting login token. {0}'.format(e))
            else:
                self.token = resp.results['access_token']
Exemplo n.º 2
0
 def wrapper(*args, **kwargs):
     # iscollab = bconfig.access == 'collab'
     valid_netrc = bconfig._check_netrc()
     if valid_netrc:
         return func(*args, **kwargs)
     else:
         raise BrainError(
             'You are not authorized to access the SDSS collaboration')
Exemplo n.º 3
0
    def _check_access(self):
        """Makes sure there is a valid netrc."""

        autocheck = self._custom_config.get('check_access', None)
        token = self._custom_config.get('use_token', None)

        if autocheck:
            try:
                valid_netrc = bconfig._check_netrc()
            except BrainError as e:
                pass
            else:
                # if it's valid, then auto set to collaboration
                if valid_netrc:
                    self.access = 'collab'

            # check for a valid login token in the marvin config
            if token and isinstance(token, six.string_types):
                self.token = token
Exemplo n.º 4
0
 def test_badperm_netrc(self, netrc):
     netrc.write('')
     with pytest.raises(BrainError) as cm:
         bconfig._check_netrc()
     assert 'your .netrc file does not have 600 permissions.' in str(
         cm.value)
Exemplo n.º 5
0
 def test_no_netrc(self, netrc):
     with pytest.raises(BrainError) as cm:
         bconfig._check_netrc()
     assert 'No .netrc file found in your HOME directory!' in str(cm.value)
Exemplo n.º 6
0
 def test_good_netrc(self, bestnet):
     assert bconfig._check_netrc() is True
Exemplo n.º 7
0
    def test_only_one_host(self, goodnet, host, msg):
        goodnet.write(write(host))
        with pytest.warns(BrainUserWarning) as cm:
            bconfig._check_netrc()

        assert msg in str(cm[0].message)