Is there a way to pass credentials dynamically while executing `op create item...`

NicketUttarwar
NicketUttarwar
Community Member

Hi 1Password Team,

I'm trying to automate the process of creating credentials for my team, and I need some advice on how to do it without a file.

op get template login gives me the template to create a new login, and so far the only working solution i've found is putting+editing the json in a file, and cat'ing it out while encoding as mentioned here - https://discussions.agilebits.com/discussion/82343/creating-a-new-item-fails-with-error-illegal-base64-data-at-input-byte
op create item login $(cat upass.json | op encode) --title="Nick's DB Credentials" --vault="MyVaultName"

Is there a way to pass these json variables dynamically in a single run command, like:

op create item login $(op get template login | op encode) --title="Nick's DB Credentials" --vault="MyVaultName" --username="user123" --password="pass123"

Or even

op create item login $({"notesPlain":"","sections":[],"passwordHistory":[],"fields":[{"value":"user123","name":"username","type":"T","designation":"username"},{"value":"pass123","name":"password","type":"P","designation":"password"}]} | op encode) --title="Nick's DB Credentials" --vault="MyVaultName"


1Password Version: 0.5.5 (CLI)
Extension Version: Not Provided
OS Version: Not Provided
Sync Type: Not Provided
Referrer: forum-search:create item login

Comments

  • NicketUttarwar
    NicketUttarwar
    Community Member

    Hi @Ben, any chance we can get some more eyes on this. Thanks

  • MrC
    MrC
    Volunteer Moderator
    edited March 2019

    @NicketUttarwar ,

    You can use something like jq, or a scripting language such as Python or Perl to create a filter program that decodes the JSON template, fills in the values for the fields you want to fill, and re-encodes the structure as JSON. You can parameterize this program to pass values. So your work flow would be something like:

    op create item login $(op get template login | yourJSONfilter --user user123 --pass pass123 | op encode)  --title="Nick's DB Credentials" --vault="MyVaultName"
    
  • NicketUttarwar
    NicketUttarwar
    Community Member

    That would probably work. Thanks!

  • cohix
    cohix
    1Password Alumni

    @NicketUttarwar MrC is correct that the only way to do this right now is using a tool such as JQ. We (as a team) are unhappy with the way that op handles items, and we are planning on totally overhauling it to allow for workflows such as the one you're describing. I don't have a timeline on when this will be available, but rest assured it's a problem we know about and we are going to be doing something about it.

  • NicketUttarwar
    NicketUttarwar
    Community Member

    I'm glad to hear that. This current version isn't really ready for my team to bake into automation, but i'm looking forward to the next iterations that will be. Thanks for your candor @cohix

  • cohix
    cohix
    1Password Alumni

    @NicketUttarwar Absolutely, we want to be open with everyone while we build this tool, especially while it's still in beta, and feedback like this is exactly what we need.

This discussion has been closed.