1Password on Mastodon

Allow defaults to be specified, or env not to be set, if vault or slot not found with op run

jonb1jonb1
Community Member

I'm using op run combined with a .env file to load our development configuration, but we have quite a bit of optional configuration. Some devs may need part of the config, other devs might need other parts. In order to make this simple, it would be nice if when using the op:// in an .env file with op run you could tell the command to ignore missing vaults or slots and just not set those environment variables, maybe printing a warning? Would be nice to do this reference by reference in the file so some could be required and other config optional, but a global flag on the op run command would be better than nothing here too. Bonus points for being able to specify a default value other than empty/not set for each environment variable reference in the .env file.

Using CLI version 2.6.2 and didn't see a way to do this, but maybe I'm missing something? Right now I just get could not resolve item UUID if I have a slot that isn't in my vault


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Browser:_ Not Provided

Comments

  • jonb1jonb1
    Community Member

    I suppose the same would apply to cases where the slot existed but some field didn't

  • andi.t_1Pandi.t_1P

    Team Member

    Hi @jonb1 , we do currently support default variables in both op run (in parsing .env files) and op inject. The syntax is ${VAR_NAME:-defaultValue}. In the case where VAR_NAME is not found defaultValue will be the used value.

    Does this help?

    Best,
    Andi

  • jonb1jonb1
    Community Member

    Thanks for the comment, but not sure this helps, unless I'm misunderstanding something.

    If I have a line in my .env file like this:
    DB_USERNAME="op://${OP_VAULT:-dev}/db/username"
    how would I make it so the DB_USERNAME was set to "jonb1" (for instance) if the vault doesn't exist?

    In this case I get [ERROR] 2023/01/02 19:32:10 could not resolve item UUID for item db

    Something like this:
    DB_USER_NAME="${op://dev/db/username:-jonb1}"
    gives expected character ':' and op://dev/db/username isn't really a VAR_NAME anyway.

    It's not that I want a default value for an variable, but a default value if the resolution of the vault/slot/attribute doesn't work for some reason.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file