Is there a way to use the credentials from the cli...
# infisical-help
h
Is there a way to use the credentials from the cli login in code for local dev? Basically I want to enforce that engineers to
infisical login
on their local machines, and then they can get the dev secrets from infisical? Currently we read them in with client id/client secret, but I would rather just have engineers get an account, get the cli and hit
infisical login
and then ready to go, no more credentials needed.
Basically, I would like to load secrets like this
Copy code
def _infisical_client() -> InfisicalSDKClient:
    global _INFISICAL_CLIENT
    if _INFISICAL_CLIENT is None:
        _INFISICAL_CLIENT = InfisicalSDKClient(host="<https://app.infisical.com>")

        if ENV.is_dev():
            # somehow use token/auth from separately running infisical login
            pass
        else:
            _INFISICAL_CLIENT.auth.universal_auth.login(
                client_id=os.environ["INFISICAL_CLIENT_ID"],
                client_secret=os.environ["INFISICAL_CLIENT_SECRET"],
            )
        return _INFISICAL_CLIENT
cc @Vlad (Infisical) any ideas here?
Hey vlad, no worries, this isn't super urgent (seeing as I am getting back to you two months later hahaha) I am familiar with this, however, we basically run scripts that use env vars all the time with different entry points setup ad-hoc so to speak. The problem with this approach is that everytime we run a script, we need to run it with infisical run which is a pain. We have some pythong code that runs that basically injects all the secrets into the environment at boot. I know this is a little funky and what the infisical run was designed for, however, it works well in most cases. And so what I am after is basically allowing that sdk client to use the cli auth and work essentially the same way as prod, just with the cli token instead... Does that make more sense? Here is basically what we do, and we use the client from the above snippet, so then engineers don't have to worry about infisical run when developing locally, that is abstracted away. All they would have to do is run infisical login once, and then they wouldn't even need credentials in their .env file which would be super awesome.
Copy code
def _set_infisical_vars():
    # don't provide any infisical shit if we're in test or build
    if (
        ENV == Environment.BUILD
        or ENV == Environment.TEST
        or ENV == Environment.PROD_MIGRATION
    ):
        return

    _client = _infisical_client()
    match ENV:
        case Environment.PROD | Environment.PROD_MIGRATION | Environment.DEV_PROD_RW:
            inf_environ = "prod"
        case Environment.STAGING:
            inf_environ = "staging"
        case Environment.DEV:
            inf_environ = "dev"

    for secret in _client.secrets.list_secrets(
        project_slug="quanta",
        environment_slug=inf_environ,
        secret_path="/",
        recursive=True,
    ).secrets:
        os.environ[secret.secretKey] = secret.secretValue
v
Looping in @Daniel Hougaard to consider this!
h
thankyou
@Daniel Hougaard let me know if you have any questions on this, I think this would be super slick
d
Hi @Hyden Polikoff, thank you for reaching out! This isn't something we support as of right now. However we have raw token auth which you can use like:
client.auth.token_auth.login(token="<your-token>")
. You can get the token directly from the Infisical UI like in the picture I've attached. We'll take a closer look at your request, and I do agree that it would be a neat addition!
h
Ah makes sense. Yeah not quite what I'm looking for but good to know. I think just having anyone do
infisical login
and then they are ready to go would be so slick, then our app just knows to look at wherever that token sits in local dev