I'm having trouble thinking of the best way to approach this, but I want to login to confluent cloud from Python.
I have a function which retrieves the user/pass to log into Confluent, I'd then like a function to login, and then a function to do what I want with the cluster..
def login():
email, password = get_secret()
env_vars = os.environ.copy()
env_vars["CONFLUENT_CLOUD_EMAIL"] = email
env_vars["CONFLUENT_CLOUD_PASSWORD"] = password
subprocess.run("confluent login", shell=True, env=env_vars)
subprocess.run("confluent cluster list", shell=True)
I'm testing by just using subprocess.run()
within the same function, and of course.. the second command fails, saying not logged in! Because when the first subprocess run closes, it ends the session.
I've tinkered with having Popen
outside of the functions, something like;
p = subprocess.Popen("/bin/sh", env=env_vars, stdin=subprocess.PIPE, stdout=subprocess.PIPE
Then inside the relevant function just using something like p.stdin.write("command")
, but that doesn't work either.
I'm scratching my head as to the best way to achieve this.
this is how I have been doing, its one time login that will save your credentials in $HOME/.netrc, then you shell out
confluent
how you want.