Esempio n. 1
0
    def __init__(self,
                 user_key=None,
                 timeout=None,
                 user_agent=None,
                 api_base=None):
        if api_base is None:
            api_base = self.URL_API_BASE

        self.URL_PING = api_base + '/v1/ping'

        self.URL_INPUT = api_base + '/v1/documents/input/'
        self.URL_OUTPUT = api_base + '/v1/documents/output/'
        self.URL_FEEDBACK = api_base + '/v1/documents/training/{domain}/'

        self.URL_PREDICT = api_base + '/v1/reference/{domain}/{name}'
        self.URL_STATUS = api_base + '/v1/reference/{domain}/{task_id}/status'
        self.URL_CANCEL = api_base + '/v1/reference/{domain}/{task_id}/cancel'

        self.URL_PREDICT_DV = api_base + '/v1/prediction/{domain}/{collection}/{name}'

        self._user_key = user_key or get_secret().get('ilabs_user_key')
        if self._user_key is None:
            raise RuntimeError('Could not find credentials')
        self._user_agent = user_agent or ILABS_USER_AGENT
        self._timeout = timeout
        if self._timeout is None:
            self._timeout = socket._GLOBAL_DEFAULT_TIMEOUT
 def __init__(self,
              user_key=None,
              datavault_key=None,
              timeout=None,
              user_agent=None,
              api_base=None):
     self._user_key = user_key or get_secret().get('ilabs_user_key')
     self._datavault_key = datavault_key or get_secret().get(
         'ilabs_datavault_key')
     if self._user_key is None or self._datavault_key is None:
         raise RuntimeError('Could not find credentials')
     self._user_agent = user_agent or ILABS_USER_AGENT
     self._timeout = timeout
     if self._timeout is None:
         self._timeout = socket._GLOBAL_DEFAULT_TIMEOUT
     if api_base is None:
         api_base = self.URL_API_BASE
     self._api_base = api_base + '/datavault'
Esempio n. 3
0
    def test_smoke(self):
        with mock.patch.dict(os.environ, {}):
            with mock.patch(
                    'ilabs.client.get_secret.configparser',
                    mock.Mock(ConfigParser=mock.Mock(return_value=mock.Mock(
                        get=mock.Mock(return_value=None))))):
                user_key = get_secret().get('ilabs_user_key')

        self.assertIsNone(user_key)
Esempio n. 4
0
    def test_datavault_file(self):

        config = '''
[default]
ilabs_datavault_key=foo
'''
        os.environ.pop('ILABS_DATAVAULT_KEY', None)
        with mock.patch('ilabs.client.get_secret.configparser.open',
                        mock_fs({'/etc/ilabs.conf': config})):
            datavault_key = get_secret().get('ilabs_datavault_key')

        self.assertEqual(datavault_key, 'foo')
Esempio n. 5
0
    def test_file(self):

        config = '''
[default]
ilabs_user_key=foo
'''

        os.environ.pop('ILABS_USER_KEY', None)
        with mock.patch('ilabs.client.get_secret.configparser.open',
                        mock_fs({'/etc/ilabs.conf': config})):
            with mock.patch.dict(os.environ, {}):
                user_key = get_secret().get('ilabs_user_key')

        self.assertEqual(user_key, 'foo')
Esempio n. 6
0
    def test_file_precedence(self):

        config1 = '''
[default]
ilabs_user_key=bar
'''

        config2 = '''
[default]
ilabs_user_key=foo
'''
        os.environ.pop('ILABS_USER_KEY', None)
        with mock.patch(
                'ilabs.client.get_secret.configparser.open',
                mock_fs({
                    '/etc/ilabs.conf':
                    config2,
                    os.path.expanduser(r'~/.config/ilabs/ilabs.conf'):
                    config1
                })):
            user_key = get_secret().get('ilabs_user_key')

        self.assertEqual(user_key, 'bar')
Esempio n. 7
0
    def test_env(self):

        with mock.patch.dict(os.environ, {'ILABS_USER_KEY': 'blah'}):
            user_key = get_secret().get('ilabs_user_key')

        self.assertEqual(user_key, 'blah')
Esempio n. 8
0
    def test_datavault_env(self):

        with mock.patch.dict(os.environ, {'ILABS_DATAVAULT_KEY': 'blah'}):
            datavault_key = get_secret().get('ilabs_datavault_key')

        self.assertEqual(datavault_key, 'blah')