/go-1password-cli

Golang wrapper around 1Passwords `op` CLI

Primary LanguageGoMIT LicenseMIT

go-1password-cli

Super thin wrapper around 1passwords op CLI tool.

Note: This is not for the secret automation API, but for the CLI tool. There is no authentication, you need to have the op CLI tool installed and logged in.

1Password will prompt you if you want to allow access on usage.

Installation

go get github.com/dvcrn/go-1password-cli

Usage

package main

import (
    "github.com/dvcrn/go-1password-cli/op"
)

func main() {
	client := op.NewOpClient()

	// get all vaults
	vaults, err := client.Vaults()

	// get a specific vault
	vault, err := client.Vault("Private")
	vault, err := client.Vault("<vaultID>")

	// get item
	item, err := client.Item("Netflix")
	item, err := client.Item("<itemID>")
}

API Reference

type Item

type Item struct {
    AdditionalInformation string    `json:"additional_information,omitempty"`
    Category              string    `json:"category"`
    CreatedAt             time.Time `json:"created_at"`
    Favorite              bool      `json:"favorite,omitempty"`
    ID                    string    `json:"id"`
    LastEditedBy          string    `json:"last_edited_by"`
    Tags                  []string  `json:"tags,omitempty"`
    Title                 string    `json:"title"`
    UpdatedAt             time.Time `json:"updated_at"`
    Urls                  []struct {
        Href    string `json:"href"`
        Label   string `json:"label,omitempty"`
        Primary bool   `json:"primary,omitempty"`
    }   `json:"urls,omitempty"`
    Vault struct {
        ID   string `json:"id"`
        Name string `json:"name"`
    }   `json:"vault"`
    Version int `json:"version"`
}

type Vault

type Vault struct {
    ContentVersion int    `json:"content_version"`
    ID             string `json:"id"`
    Name           string `json:"name"`
}

type OpClient

type OpClient struct{}

func NewOpClient

func NewOpClient() *OpClient

func (*OpClient) Item

func (c *OpClient) Item(itemIDOrName string) (*Item, error)

Item returns an item by its ID or name, across all Vaults the user has access to To get items scoped to a specific Vault, use VaultItem()

func (*OpClient) ReadItemField

func (c *OpClient) ReadItemField(vaultIdOrName string, itemIdOrName string, fieldName string) (string, error)

ReadItemField does a lookup of a specific field within an item, within a vault This is equivalent to op read op://<vault>/<item>/<field>

func (*OpClient) EditItemField

func (c *OpClient) EditItemField(vaultIdOrName string, itemIdOrName string, assignments ...Assignment) (*Item, error)

EditItemField does a lookup of a specific field within an item, within a vault and edit the fields in the item. This is equivalent to op item edit field=value ...

func (*OpClient) Vault

func (c *OpClient) Vault(vaultIDOrName string) (*Vault, error)

Vault retrieves a vault by its ID or name If you have a Vault named "Private", you can specify this as either "Private" or with its ID

func (*OpClient) VaultItem

func (c *OpClient) VaultItem(itemIDOrName string, vaultIDOrName string) (*Item, error)

VaultItem returns an item by it's ID or name, within the specified Vault To get items across all Vaults, use Item()

func (*OpClient) Vaults

func (c *OpClient) Vaults() ([]*Vault, error)

Vaults returns a list of all vaults in the current 1Password account