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.
go get github.com/dvcrn/go-1password-cli
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>")
}
- type Vault
- type Item
- type OpClient
- func NewOpClient() *OpClient
- func (c *OpClient) Item(itemIDOrName string) (*Item, error)
- func (c *OpClient) LookupField(vaultIdOrName string, itemIdOrName string, fieldName string) (string, error)
- func (c *OpClient) Vault(vaultIDOrName string) (*Vault, error)
- func (c *OpClient) VaultItem(itemIDOrName string, vaultIDOrName string) (*Item, error)
- func (c *OpClient) Vaults() ([]*Vault, error)
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 struct {
ContentVersion int `json:"content_version"`
ID string `json:"id"`
Name string `json:"name"`
}
type OpClient struct{}
func NewOpClient() *OpClient
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 (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 (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 (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 (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 (c *OpClient) Vaults() ([]*Vault, error)
Vaults returns a list of all vaults in the current 1Password account