How to use the yandexcloud._auth_fabric.get_auth_token_requester function in yandexcloud

To help you get started, we’ve selected a few yandexcloud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yandex-cloud / python-sdk / tests / test_service_account_auth.py View on Github external
def test_invalid_service_account_type():
    with pytest.raises(RuntimeError) as e:
        get_auth_token_requester(service_account_key=[]).get_token_request()

    assert str(e.value).startswith("Invalid Service Account Key: expecting dictionary, actually got")
github yandex-cloud / python-sdk / tests / test_service_account_auth.py View on Github external
def test_both_params_error(token, service_account_key):
    with pytest.raises(RuntimeError) as e:
        get_auth_token_requester(token=token, service_account_key=service_account_key).get_token_request()

    assert str(e.value) == "Conflicting API credentials properties 'token' and 'service-account-key' are set."
github yandex-cloud / python-sdk / tests / test_service_account_auth.py View on Github external
def test_oauth_token(token):
    request_func = get_auth_token_requester(token=token).get_token_request
    request = request_func()
    assert token == request.yandex_passport_oauth_token
github yandex-cloud / python-sdk / tests / test_service_account_auth.py View on Github external
def test_service_account_key(service_account_key):
    request_func = get_auth_token_requester(service_account_key=service_account_key).get_token_request
    request = request_func()
    now = int(time.time())
    headers = jwt.get_unverified_header(request.jwt)
    parsed = jwt.decode(request.jwt, secret=service_account_key["public_key"], algorithms=['PS256'], verify=False)
    assert headers["typ"] == "JWT"
    assert headers["alg"] == "PS256"
    assert headers["kid"] == service_account_key["id"]

    assert parsed["iss"] == service_account_key["service_account_id"]
    assert parsed["aud"] == "https://iam.api.cloud.yandex.net/iam/v1/tokens"
    assert now - 60 <= int(parsed["iat"]) <= now
github yandex-cloud / python-sdk / tests / test_service_account_auth.py View on Github external
def test_service_account_no_id(service_account_key, key, error_msg):
    service_account_key.pop(key)

    with pytest.raises(RuntimeError) as e:
        get_auth_token_requester(service_account_key=service_account_key).get_token_request()

    assert str(e.value) == error_msg
github yandex-cloud / python-sdk / yandexcloud / _channels.py View on Github external
def __init__(self, **kwargs):
        self._channel_creds = grpc.ssl_channel_credentials(
            root_certificates=kwargs.get('root_certificates'),
            private_key=kwargs.get('private_key'),
            certificate_chain=kwargs.get('certificate_chain'),
        )
        self._endpoint = kwargs.get('endpoint', 'api.cloud.yandex.net')
        self._token_requester = get_auth_token_requester(token=kwargs.get("token"),
                                                         service_account_key=kwargs.get("service_account_key"))

        self._unauthenticated_channel = None
        self._channels = None