onepassword

package module
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 7 Imported by: 9

README ¶

1Password Go SDK

Build integrations that programmatically access your secrets in 1Password.

Documentation | Examples


🚀 Get started

To use the 1Password Go SDK in your project:

  1. Create a service account and give it the appropriate permissions in the vaults where the items you want to use with the SDK are saved.

  2. Provision your service account token. We recommend provisioning your token from the environment. For example, to export your token to the OP_SERVICE_ACCOUNT_TOKEN environment variable:

    macOS or Linux

    export OP_SERVICE_ACCOUNT_TOKEN=<your-service-account-token>
    

    Windows

    $Env:OP_SERVICE_ACCOUNT_TOKEN = "<your-service-account-token>"
    
  3. Install the 1Password Go SDK in your project:

    go get github.com/1password/onepassword-sdk-go
    
  4. Use the Go SDK in your project:

import (
    "context"
    "os"

    "github.com/1password/onepassword-sdk-go"
)

func main() {
    token := os.Getenv("OP_SERVICE_ACCOUNT_TOKEN")

    client, err := onepassword.NewClient(
                context.TODO(),
                onepassword.WithServiceAccountToken(token),
                // TODO: Set the following to your own integration name and version.
                onepassword.WithIntegrationInfo("My 1Password Integration", "v1.0.0"),
    )
    if err != nil {
	// handle err
    }
    secret, err := client.Secrets.Resolve(context.TODO(), "op://vault/item/field")
    if err != nil {
        // handle err
    }
    // do something with the secret
}

Make sure to use secret reference URIs with the syntax op://vault/item/field to securely load secrets from 1Password into your code.

Supported functionality

1Password SDKs are in active development. We're keen to hear what you'd like to see next. Let us know by upvoting or filing an issue.

Item management

Operations:

Field types:

  • API Keys
  • Passwords
  • Concealed fields
  • Text fields
  • Notes
  • SSH private keys, public keys, fingerprint and key type (partially supported: supported in resolving secret references, not yet supported in item create/get/update)
  • One-time passwords
  • URLs
  • Websites (used to suggest and autofill logins)
  • Phone numbers
  • Credit card types
  • Credit card numbers
  • Emails
  • References to other items
  • Address
  • Date / MM/YY
  • Files attachments and Document items (#108)

Vault management

  • Retrieve vaults
  • Create vaults
  • Update vaults
  • Delete vaults
  • List vaults

User & access management

  • Provision users
  • Retrieve users
  • List users
  • Suspend users
  • Create groups
  • Update group membership
  • Update vault access & permissions

Compliance & reporting

Authentication

📖 Learn more

Documentation ¶

Overview ¶

Code generated by typeshare 1.13.2. DO NOT EDIT.

Index ¶

Constants ¶

View Source
const (
	DefaultIntegrationName    = "Unknown"
	DefaultIntegrationVersion = "Unknown"
)

Variables ¶

View Source
var (
	ErrorIteratorDone = errors.New("end of iterator")
)
View Source
var Secrets = secretsUtil{}

Functions ¶

This section is empty.

Types ¶

type AllowedRecipientType ¶ added in v0.1.6

type AllowedRecipientType string

The allowed recipient types of item sharing, enforced by account policy

const (
	// Recipients can be specified by email address
	AllowedRecipientTypeEmail AllowedRecipientType = "Email"
	// Recipients can be specified by domain
	AllowedRecipientTypeDomain AllowedRecipientType = "Domain"
)

type AllowedType ¶ added in v0.1.6

type AllowedType string

The allowed types of item sharing, enforced by account policy

const (
	// Allows creating share links with specific recipients
	AllowedTypeAuthenticated AllowedType = "Authenticated"
	// Allows creating public share links
	AllowedTypePublic AllowedType = "Public"
)

type AutofillBehavior ¶ added in v0.1.3

type AutofillBehavior string

Controls the auto-fill behavior of a website.

For more information, visit https://support.1password.com/autofill-behavior/

const (
	// Auto-fill any page that’s part of the website, including subdomains
	AutofillBehaviorAnywhereOnWebsite AutofillBehavior = "AnywhereOnWebsite"
	// Auto-fill only if the domain (hostname and port) is an exact match.
	AutofillBehaviorExactDomain AutofillBehavior = "ExactDomain"
	// Never auto-fill on this website
	AutofillBehaviorNever AutofillBehavior = "Never"
)

type Client ¶

type Client struct {
	Secrets SecretsSource
	Items   ItemsSource
	Vaults  VaultsSource
	// contains filtered or unexported fields
}

Client represents an instance of the 1Password Go SDK client.

func NewClient ¶

func NewClient(ctx context.Context, opts ...ClientOption) (*Client, error)

NewClient returns a 1Password Go SDK client using the provided ClientOption list.

type ClientOption ¶

type ClientOption func(client *Client) error

func WithIntegrationInfo ¶

func WithIntegrationInfo(name string, version string) ClientOption

WithIntegrationInfo specifies the name and version of the integration built using the 1Password Go SDK. If you don't know which name and version to use, use `DefaultIntegrationName` and `DefaultIntegrationVersion`, respectively.

func WithServiceAccountToken ¶

func WithServiceAccountToken(token string) ClientOption

WithServiceAccountToken specifies the [1Password Service Account](https://developer.1password.com/docs/service-accounts) token to use to authenticate the SDK client. Read more about how to get started with service accounts: https://developer.1password.com/docs/service-accounts/get-started/#create-a-service-account

type GeneratePasswordResponse ¶ added in v0.1.5

type GeneratePasswordResponse struct {
	// The generated password.
	Password string `json:"password"`
}

For future use, if we want to return more information about the generated password. Currently, it only returns the password itself.

type Item ¶

type Item struct {
	// The item's ID
	ID string `json:"id"`
	// The item's title
	Title string `json:"title"`
	// The item's category
	Category ItemCategory `json:"category"`
	// The ID of the vault where the item is saved
	VaultID string `json:"vaultId"`
	// The item's fields
	Fields []ItemField `json:"fields"`
	// The item's sections
	Sections []ItemSection `json:"sections"`
	// The notes of the item
	Notes string `json:"notes"`
	// The item's tags
	Tags []string `json:"tags"`
	// The websites used for autofilling for items of the Login and Password categories.
	Websites []Website `json:"websites"`
	// The item's version
	Version uint32 `json:"version"`
}

Represents a 1Password item.

type ItemCategory ¶

type ItemCategory string
const (
	ItemCategoryLogin                ItemCategory = "Login"
	ItemCategorySecureNote           ItemCategory = "SecureNote"
	ItemCategoryCreditCard           ItemCategory = "CreditCard"
	ItemCategoryCryptoWallet         ItemCategory = "CryptoWallet"
	ItemCategoryIdentity             ItemCategory = "Identity"
	ItemCategoryPassword             ItemCategory = "Password"
	ItemCategoryDocument             ItemCategory = "Document"
	ItemCategoryAPICredentials       ItemCategory = "ApiCredentials"
	ItemCategoryBankAccount          ItemCategory = "BankAccount"
	ItemCategoryDatabase             ItemCategory = "Database"
	ItemCategoryDriverLicense        ItemCategory = "DriverLicense"
	ItemCategoryEmail                ItemCategory = "Email"
	ItemCategoryMedicalRecord        ItemCategory = "MedicalRecord"
	ItemCategoryMembership           ItemCategory = "Membership"
	ItemCategoryOutdoorLicense       ItemCategory = "OutdoorLicense"
	ItemCategoryPassport             ItemCategory = "Passport"
	ItemCategoryRewards              ItemCategory = "Rewards"
	ItemCategoryRouter               ItemCategory = "Router"
	ItemCategoryServer               ItemCategory = "Server"
	ItemCategorySSHKey               ItemCategory = "SshKey"
	ItemCategorySocialSecurityNumber ItemCategory = "SocialSecurityNumber"
	ItemCategorySoftwareLicense      ItemCategory = "SoftwareLicense"
	ItemCategoryPerson               ItemCategory = "Person"
	ItemCategoryUnsupported          ItemCategory = "Unsupported"
)

type ItemCreateParams ¶

type ItemCreateParams struct {
	// The item's category
	Category ItemCategory `json:"category"`
	// The ID of the vault where the item is saved
	VaultID string `json:"vaultId"`
	// The item's title
	Title string `json:"title"`
	// The item's fields
	Fields []ItemField `json:"fields,omitempty"`
	// The item's sections
	Sections []ItemSection `json:"sections,omitempty"`
	// The item's notes
	Notes *string `json:"notes,omitempty"`
	// The item's tags
	Tags []string `json:"tags,omitempty"`
	// The websites used for autofilling for items of the Login and Password categories.
	Websites []Website `json:"websites,omitempty"`
}

type ItemField ¶

type ItemField struct {
	// The field's ID
	ID string `json:"id"`
	// The field's title
	Title string `json:"title"`
	// The ID of the section containing the field. Built-in fields such as usernames and passwords don't require a section.
	SectionID *string `json:"sectionId,omitempty"`
	// The field's type
	FieldType ItemFieldType `json:"fieldType"`
	// The string representation of the field's value
	Value string `json:"value"`
	// Field type-specific attributes.
	Details *ItemFieldDetails `json:"details,omitempty"`
}

Represents a field within an item.

type ItemFieldDetails ¶

type ItemFieldDetails struct {
	Type ItemFieldDetailsTypes `json:"type"`
	// contains filtered or unexported fields
}

func NewItemFieldDetailsTypeVariantOTP ¶

func NewItemFieldDetailsTypeVariantOTP(content *OTPFieldDetails) ItemFieldDetails

func (ItemFieldDetails) MarshalJSON ¶

func (i ItemFieldDetails) MarshalJSON() ([]byte, error)

func (ItemFieldDetails) OTP ¶

func (*ItemFieldDetails) UnmarshalJSON ¶

func (i *ItemFieldDetails) UnmarshalJSON(data []byte) error

type ItemFieldDetailsTypes ¶

type ItemFieldDetailsTypes string

Field type-specific attributes.

const (
	// The computed OTP code and other details
	ItemFieldDetailsTypeVariantOTP ItemFieldDetailsTypes = "Otp"
)

type ItemFieldType ¶

type ItemFieldType string
const (
	ItemFieldTypeText             ItemFieldType = "Text"
	ItemFieldTypeConcealed        ItemFieldType = "Concealed"
	ItemFieldTypeCreditCardType   ItemFieldType = "CreditCardType"
	ItemFieldTypeCreditCardNumber ItemFieldType = "CreditCardNumber"
	ItemFieldTypePhone            ItemFieldType = "Phone"
	ItemFieldTypeURL              ItemFieldType = "Url"
	ItemFieldTypeTOTP             ItemFieldType = "Totp"
	ItemFieldTypeEmail            ItemFieldType = "Email"
	ItemFieldTypeReference        ItemFieldType = "Reference"
	ItemFieldTypeUnsupported      ItemFieldType = "Unsupported"
)

type ItemOverview ¶

type ItemOverview struct {
	// The item's ID
	ID string `json:"id"`
	// The item's title
	Title string `json:"title"`
	// The item's category
	Category ItemCategory `json:"category"`
	// The ID of the vault where the item is saved
	VaultID string `json:"vaultId"`
	// The websites used for autofilling for items of the Login and Password categories.
	Websites []Website `json:"websites"`
}

Represents a decrypted 1Password item.

type ItemSection ¶

type ItemSection struct {
	// The section's unique ID
	ID string `json:"id"`
	// The section's title
	Title string `json:"title"`
}

A section groups together multiple fields in an item.

type ItemShareAccountPolicy ¶ added in v0.1.6

type ItemShareAccountPolicy struct {
	// The maximum duration that an item can be shared for
	MaxExpiry ItemShareDuration `json:"maxExpiry"`
	// The default duration that an item is shared for
	DefaultExpiry ItemShareDuration `json:"defaultExpiry"`
	// The maximum number of times an item can be viewed. A null value means unlimited views
	MaxViews *uint32 `json:"maxViews,omitempty"`
	// The allowed types of item sharing - either "Authenticated" (share to specific users) or "Public" (share to anyone with a link)
	AllowedTypes []AllowedType `json:"allowedTypes"`
	// The allowed recipient types of item sharing - either "Email" or "Domain"
	AllowedRecipientTypes []AllowedRecipientType `json:"allowedRecipientTypes"`
}

The account policy for sharing items, set by your account owner/admin This policy is enforced server-side when sharing items

type ItemShareDuration ¶ added in v0.1.6

type ItemShareDuration string

The valid duration options for sharing an item

const (
	// The share will expire in one hour
	ItemShareDurationOneHour ItemShareDuration = "OneHour"
	// The share will expire in one day
	ItemShareDurationOneDay ItemShareDuration = "OneDay"
	// The share will expire in seven days
	ItemShareDurationSevenDays ItemShareDuration = "SevenDays"
	// The share will expire in fourteen days
	ItemShareDurationFourteenDays ItemShareDuration = "FourteenDays"
	// The share will expire in thirty days
	ItemShareDurationThirtyDays ItemShareDuration = "ThirtyDays"
)

type ItemShareParams ¶ added in v0.1.6

type ItemShareParams struct {
	// Emails or domains of the item share recipients. If not provided, everyone with the share link will have access
	Recipients []ValidRecipient `json:"recipients,omitempty"`
	// The duration of the share in seconds. If not provided, defaults to the account policy's default expiry
	ExpireAfter *ItemShareDuration `json:"expireAfter,omitempty"`
	// Whether the item can only be viewed once per recipient
	OneTimeOnly bool `json:"oneTimeOnly"`
}

The configuration options for sharing an item These must respect the account policy on item sharing

type ItemsSharesSource ¶ added in v0.1.6

type ItemsSharesSource struct {
	// contains filtered or unexported fields
}

func NewItemsSharesSource ¶ added in v0.1.6

func NewItemsSharesSource(inner internal.InnerClient) *ItemsSharesSource

func (ItemsSharesSource) Create ¶ added in v0.1.6

Create a new item sharing link.

func (ItemsSharesSource) GetAccountPolicy ¶ added in v0.1.6

func (i ItemsSharesSource) GetAccountPolicy(ctx context.Context, vaultID string, itemID string) (ItemShareAccountPolicy, error)

Get the item sharing policy of your account.

func (ItemsSharesSource) ValidateRecipients ¶ added in v0.1.6

func (i ItemsSharesSource) ValidateRecipients(ctx context.Context, policy ItemShareAccountPolicy, recipients []string) ([]ValidRecipient, error)

Validate the recipients of an item sharing link.

type ItemsSource ¶

type ItemsSource struct {
	Shares ItemsSharesSource
	// contains filtered or unexported fields
}

The Items API holds all operations the SDK client can perform on 1Password items.

func NewItemsSource ¶

func NewItemsSource(inner internal.InnerClient) *ItemsSource

func (ItemsSource) Archive ¶ added in v0.1.6

func (i ItemsSource) Archive(ctx context.Context, vaultID string, itemID string) error

Archive an item.

func (ItemsSource) Create ¶

func (i ItemsSource) Create(ctx context.Context, params ItemCreateParams) (Item, error)

Create a new item.

func (ItemsSource) Delete ¶

func (i ItemsSource) Delete(ctx context.Context, vaultID string, itemID string) error

Delete an item.

func (ItemsSource) Get ¶

func (i ItemsSource) Get(ctx context.Context, vaultID string, itemID string) (Item, error)

Get an item by vault and item ID

func (ItemsSource) ListAll ¶

func (i ItemsSource) ListAll(ctx context.Context, vaultID string) (*Iterator[ItemOverview], error)

List all items

func (ItemsSource) Put ¶

func (i ItemsSource) Put(ctx context.Context, item Item) (Item, error)

Update an existing item.

type Iterator ¶

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

Iterator defines a generic iterator

func NewIterator ¶

func NewIterator[T any](items []T) *Iterator[T]

NewIterator creates a new iterator for the given slice

func (*Iterator[T]) Next ¶

func (it *Iterator[T]) Next() (*T, error)

Next returns the next item from the iterator

type OTPFieldDetails ¶

type OTPFieldDetails struct {
	// The OTP code, if successfully computed
	Code *string `json:"code,omitempty"`
	// The error message, if the OTP code could not be computed
	ErrorMessage *string `json:"errorMessage,omitempty"`
}

Additional attributes for OTP fields.

type PasswordRecipe ¶ added in v0.1.5

type PasswordRecipe struct {
	Type PasswordRecipeTypes `json:"type"`
	// contains filtered or unexported fields
}

func NewPasswordRecipeTypeVariantMemorable ¶ added in v0.1.5

func NewPasswordRecipeTypeVariantMemorable(content *PasswordRecipeMemorableInner) PasswordRecipe

func NewPasswordRecipeTypeVariantPin ¶ added in v0.1.5

func NewPasswordRecipeTypeVariantPin(content *PasswordRecipePinInner) PasswordRecipe

func NewPasswordRecipeTypeVariantRandom ¶ added in v0.1.5

func NewPasswordRecipeTypeVariantRandom(content *PasswordRecipeRandomInner) PasswordRecipe

func (PasswordRecipe) MarshalJSON ¶ added in v0.1.5

func (p PasswordRecipe) MarshalJSON() ([]byte, error)

func (PasswordRecipe) Memorable ¶ added in v0.1.5

func (PasswordRecipe) Pin ¶ added in v0.1.5

func (PasswordRecipe) Random ¶ added in v0.1.5

func (*PasswordRecipe) UnmarshalJSON ¶ added in v0.1.5

func (p *PasswordRecipe) UnmarshalJSON(data []byte) error

type PasswordRecipeMemorableInner ¶ added in v0.1.5

type PasswordRecipeMemorableInner struct {
	// The type of separator between chunks.
	SeparatorType SeparatorType `json:"separatorType"`
	// Uppercase one randomly selected chunk.
	Capitalize bool `json:"capitalize"`
	// The type of word list used.
	WordListType WordListType `json:"wordListType"`
	// The number of "words" (words or syllables).
	WordCount uint32 `json:"wordCount"`
}

Generated type representing the anonymous struct variant `Memorable` of the `PasswordRecipe` Rust enum

type PasswordRecipePinInner ¶ added in v0.1.5

type PasswordRecipePinInner struct {
	// Number of digits in the PIN.
	Length uint32 `json:"length"`
}

Generated type representing the anonymous struct variant `Pin` of the `PasswordRecipe` Rust enum

type PasswordRecipeRandomInner ¶ added in v0.1.5

type PasswordRecipeRandomInner struct {
	// Include at least one digit in the password.
	IncludeDigits bool `json:"includeDigits"`
	// Include at least one symbol in the password.
	IncludeSymbols bool `json:"includeSymbols"`
	// The length of the password.
	Length uint32 `json:"length"`
}

Generated type representing the anonymous struct variant `Random` of the `PasswordRecipe` Rust enum

type PasswordRecipeTypes ¶ added in v0.1.5

type PasswordRecipeTypes string
const (
	PasswordRecipeTypeVariantMemorable PasswordRecipeTypes = "Memorable"
	PasswordRecipeTypeVariantPin       PasswordRecipeTypes = "Pin"
	PasswordRecipeTypeVariantRandom    PasswordRecipeTypes = "Random"
)

type RateLimitExceededError ¶ added in v0.1.7

type RateLimitExceededError struct {
	// contains filtered or unexported fields
}

func (*RateLimitExceededError) Error ¶ added in v0.1.7

func (e *RateLimitExceededError) Error() string

type SecretsSource ¶

type SecretsSource struct {
	// contains filtered or unexported fields
}

The Secrets API includes all operations the SDK client can perform on secrets. Use secret reference URIs to securely load secrets from 1Password: op://<vault-name>/<item-name>[/<section-name>]/<field-name>

func NewSecretsSource ¶

func NewSecretsSource(inner internal.InnerClient) *SecretsSource

func (SecretsSource) Resolve ¶

func (s SecretsSource) Resolve(ctx context.Context, secretReference string) (string, error)

Resolve returns the secret the provided secret reference points to.

type SeparatorType ¶ added in v0.1.5

type SeparatorType string
const (
	// Randomly selected digits.
	// E.g, "`correct4horse0battery1staple`"
	SeparatorTypeDigits SeparatorType = "digits"
	// Randomly selected digits and symbols.
	// This is useful to get word-based passwords to meet complexity requirements
	// E.g, "`correct4horse-battery1staple`"
	SeparatorTypeDigitsAndSymbols SeparatorType = "digitsAndSymbols"
	// Spaces, like the original Diceware.
	// Great for mobile keyboards, not so great when people can overhear you type the password.
	// E.g, "`correct horse battery staple`"
	SeparatorTypeSpaces SeparatorType = "spaces"
	// Hyphens "`-`".
	// E.g, "`correct-horse-battery-staple`"
	SeparatorTypeHyphens SeparatorType = "hyphens"
	// "`_`".
	// E.g, "`correct_horse_battery_staple`"
	SeparatorTypeUnderscores SeparatorType = "underscores"
	// Period (full stop) "`.`".
	// E.g, "`correct.horse.battery.staple`"
	SeparatorTypePeriods SeparatorType = "periods"
	// Comma "`,`".
	// E.g, "`correct,horse,battery,staple`"
	SeparatorTypeCommas SeparatorType = "commas"
)

type ValidRecipient ¶ added in v0.1.6

type ValidRecipient struct {
	Type ValidRecipientTypes `json:"type"`
	// contains filtered or unexported fields
}

func NewValidRecipientTypeVariantDomain ¶ added in v0.1.6

func NewValidRecipientTypeVariantDomain(content *ValidRecipientDomainInner) ValidRecipient

func NewValidRecipientTypeVariantEmail ¶ added in v0.1.6

func NewValidRecipientTypeVariantEmail(content *ValidRecipientEmailInner) ValidRecipient

func (ValidRecipient) Domain ¶ added in v0.1.6

func (ValidRecipient) Email ¶ added in v0.1.6

func (ValidRecipient) MarshalJSON ¶ added in v0.1.6

func (v ValidRecipient) MarshalJSON() ([]byte, error)

func (*ValidRecipient) UnmarshalJSON ¶ added in v0.1.6

func (v *ValidRecipient) UnmarshalJSON(data []byte) error

type ValidRecipientDomainInner ¶ added in v0.1.6

type ValidRecipientDomainInner struct {
	Domain string `json:"domain"`
}

Generated type representing the anonymous struct variant `Domain` of the `ValidRecipient` Rust enum

type ValidRecipientEmailInner ¶ added in v0.1.6

type ValidRecipientEmailInner struct {
	Email string `json:"email"`
}

Generated type representing the anonymous struct variant `Email` of the `ValidRecipient` Rust enum

type ValidRecipientTypes ¶ added in v0.1.6

type ValidRecipientTypes string

The validated recipient of an item share

const (
	// This exact email address
	ValidRecipientTypeVariantEmail ValidRecipientTypes = "Email"
	// Anyone with an email address from the specified domain
	ValidRecipientTypeVariantDomain ValidRecipientTypes = "Domain"
)

type VaultOverview ¶

type VaultOverview struct {
	// The vault's ID
	ID string `json:"id"`
	// The vault's title
	Title string `json:"title"`
}

Represents a decrypted 1Password vault.

type VaultsSource ¶

type VaultsSource struct {
	// contains filtered or unexported fields
}

The Vaults API holds all the operations the SDK client can perform on 1Password vaults.

func NewVaultsSource ¶

func NewVaultsSource(inner internal.InnerClient) *VaultsSource

func (VaultsSource) ListAll ¶

List all vaults

type Website ¶ added in v0.1.3

type Website struct {
	// The website URL
	URL string `json:"url"`
	// The label of the website, e.g. 'website', 'sign-in address'
	Label string `json:"label"`
	// The auto-fill behavior of the website
	//
	// For more information, visit https://support.1password.com/autofill-behavior/
	AutofillBehavior AutofillBehavior `json:"autofillBehavior"`
}

type WordListType ¶ added in v0.1.5

type WordListType string
const (
	// Agile wordlist
	WordListTypeFullWords WordListType = "fullWords"
	// English-like syllables
	WordListTypeSyllables WordListType = "syllables"
	// Three (random) letter "words"
	WordListTypeThreeLetters WordListType = "threeLetters"
)

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL