Пример #1
0
def test_config_clear_upload_key():
    config.config_file_clear_section(SECTION)
    random_key = ''.join(
        random.choices(string.ascii_uppercase + string.digits, k=12))
    config.config_file_save_upload_key(random_key, USERNAME, SECTION)
    assert config.config_file_read_upload_key(SECTION) == random_key
    config.config_file_clear_upload_key(SECTION)
    assert config.config_file_read_upload_key(SECTION) is None
Пример #2
0
    def _check_and_set_auth_key(self, headers, url):
        if API_AUTH_PATH_REGISTER in url or API_AUTH_PATH_LOGIN in url or 'Authorization' in headers.keys():
            return headers

        # Choose the strongest key first
        auth_key = self.state.api_key or self.state.upload_key

        if auth_key is None:
            if self.state.verbose:
                click.echo('Checking local API|Upload key... ', nl=False)

            # Choose the strongest key first
            auth_key = config_file_read_api_key(self.state.config_section())
            if not auth_key:
                auth_key = config_file_read_upload_key(self.state.config_section())
                if not auth_key:
                    raise ArcsecondError('Missing auth keys (API or Upload). You must login first: $ arcsecond login')

        headers['X-Arcsecond-API-Authorization'] = 'Key ' + auth_key

        if self.state.verbose:
            key_str = auth_key[:3] + 9 * '*'
            click.echo(f'OK (\'X-Arcsecond-API-Authorization\' = \'Key {key_str}\'')

        return headers
Пример #3
0
def test_login_basic():
    clear_test_credentials()
    assert config.config_file_read_api_key('test') is None
    prepare_successful_login()
    ArcsecondAPI.login(TEST_LOGIN_USERNAME,
                       TEST_LOGIN_PASSWORD,
                       debug=True,
                       test=True)
    assert config.config_file_read_api_key('test') is None
    assert config.config_file_read_upload_key('test') is None
Пример #4
0
def test_login_both_apikey_uploadkey():
    clear_test_credentials()
    assert config.config_file_read_api_key('test') is None
    prepare_successful_login()
    ArcsecondAPI.login(TEST_LOGIN_USERNAME,
                       TEST_LOGIN_PASSWORD,
                       api_key=True,
                       upload_key=True,
                       debug=True,
                       test=True)
    assert config.config_file_read_api_key('test') == TEST_API_KEY
    assert config.config_file_read_upload_key('test') == TEST_UPLOAD_KEY
Пример #5
0
 def upload_key(cls, state: Optional[State] = None, **kwargs) -> str:
     state = get_api_state(state, **kwargs)
     return config_file_read_upload_key(section=state.config_section()) or ''