Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.login returns await #49

Open
3 tasks
wlwwu opened this issue Mar 8, 2024 · 2 comments
Open
3 tasks

client.login returns await #49

wlwwu opened this issue Mar 8, 2024 · 2 comments
Labels

Comments

@wlwwu
Copy link

wlwwu commented Mar 8, 2024

Summary

with all the credentials provided, the client is returnning something error

Steps to Reproduce

from conjur_api.providers.authn_authentication_strategy import AuthnAuthenticationStrategy
from conjur_api.providers.simple_credentials_provider import SimpleCredentialsProvider
from conjur_api.models import SslVerificationMode,ConjurConnectionInfo,CredentialsData
from conjur_api.client import Client
from dotenv import load_dotenv, find_dotenv

import os

ENV_FILE = find_dotenv()
if ENV_FILE:
load_dotenv(ENV_FILE)

conjur_url = os.getenv("CONJUR_URL")
account = os.getenv("ACCOUNT")
username = os.getenv("CONJUR_LOGIN_ID")
api_key = os.getenv("API_KEY")
ssl_verification_mode = SslVerificationMode.TRUST_STORE

connection_info = ConjurConnectionInfo(conjur_url=conjur_url,account=account,cert_file=None)

credentials = CredentialsData(username=username, api_key=api_key, machine=conjur_url)
credentials_provider = SimpleCredentialsProvider()
credentials_provider.save(credentials)
del credentials

authn_provider = AuthnAuthenticationStrategy(credentials_provider)

client = Client(connection_info,
authn_strategy=authn_provider,
ssl_verification_mode=ssl_verification_mode)

client.login()

Expected Results

it should return the login info, not the error info

Actual Results

ubuntu@host:/data/dev/conjur_api$ python3.10 auth.py
/data/dev/conjur_api/auth.py:36: RuntimeWarning: coroutine 'Client.login' was never awaited
client.login()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Reproducible

  • Always
  • Sometimes
  • Non-Reproducible

Version/Tag number

What version of the product are you running? Any version info that you can
share is helpful. For example, you might give the version from Docker logs,
the Docker tag, a specific download URL, the output of the /info route, etc.

Environment setup

  • Can you describe the environment in which this product is running? Is it running on a VM / in a container / in a cloud?
  • Which cloud provider? Which container orchestrator (including version)?
  • The more info you can share about your runtime environment, the better we may be able to reproduce the issue.

Additional Information

Add any other context about the problem here.

@wlwwu wlwwu added the kind/bug label Mar 8, 2024
@wlwwu
Copy link
Author

wlwwu commented Mar 8, 2024

Traceback (most recent call last):
File "/data/dev/conjur_api/auth.py", line 39, in
asyncio.run(login())
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/data/dev/conjur_api/auth.py", line 37, in login
await client.login()
File "/home/ubuntu/.local/lib/python3.10/site-packages/conjur_api/client.py", line 92, in login
return await self._api.login()
File "/home/ubuntu/.local/lib/python3.10/site-packages/conjur_api/http/api.py", line 100, in login
return await self.authn_strategy.login(
File "/home/ubuntu/.local/lib/python3.10/site-packages/conjur_api/providers/authn_authentication_strategy.py", line 47, in login
raise MissingRequiredParameterException("password is required for login")
conjur_api.errors.errors.MissingRequiredParameterException: password is required for login

@markri
Copy link

markri commented Sep 12, 2024

I fell into the same "trap", not knowing there was such a thing as the asyncio library. You need to wrap your logic into an async def function and use await on client methods. Something like this:

import asyncio

def main():
  client = asyncio.run(get_client())

async def get_client():
  # Setup your conjur client here
  return await client.login()

if __name__ == "__main__":
  main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants