onetimesecret

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package onetimesecret is a Go client that wraps the REST api of https://onetimesecret.com.

Index

Constants

View Source
const (
	DefaultBaseURL         = "https://onetimesecret.com/api/v1" // The default base url for the onetimesecret.com api.
	StatusEndpoint         = "status"                           // The status endpoint.
	ShareEndpoint          = "share"                            // The share endpoint.
	GenerateEndpoint       = "generate"                         // The generate endpoint.
	SecretEndpoint         = "secret"                           // The secret endpoint.
	MetadataEndpoint       = "private"                          // The private endpoint.
	BurnEndpoint           = "burn"                             // The burn endpoint.
	RecentMetadataEndpoint = "recent"                           // The recent metadata endpoint.
)

Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type BurnSecretResponse

type BurnSecretResponse struct {
	CustID             string   `json:"custid"`              // The requestors user id
	MetadataKey        string   `json:"metadata_key"`        // The unique key for the metadata. DO NOT share this.
	SecretKey          string   `json:"secret_key"`          // The unique key for the secret you created. This is key that you can share.
	TTL                int      `json:"ttl"`                 // The time-to-live that was specified (i.e. not the time remaining)
	MetadataTTL        int      `json:"metadata_ttl"`        // The remaining time (in seconds) that the metadata has left to live.
	SecretTTL          int      `json:"secret_ttl"`          // The remaining time (in seconds) that the secret has left to live.
	Recipient          []string `json:"recipient"`           // If a recipient was specified, this is an obfuscated version of the email address.
	Created            int64    `json:"created"`             // Time the metadata was created in unix time (UTC)
	Updated            int64    `json:"updated"`             // Time the metadata was last updated in unix time (UTC)
	PassphraseRequired bool     `json:"passphrase_required"` // If a passphrase was provided when the secret was created, this will be true. Otherwise false, obviously.
}

BurnSecretResponse represents the object returned from the api when burning a secret

type Client

type Client struct {
	BaseURL    string     // The base url of the api.
	Username   string     // The username of the requesting user.
	APIKey     string     // The api key of the requesting user.
	HTTPClient HTTPClient // A http.Client instance.
}

Client represents a onetimesecret http client instance.

func NewClient

func NewClient(options ...ClientOption) *Client

NewClient creates a new instance of the onetimesecret http client

func (*Client) BurnSecret

func (c *Client) BurnSecret(ctx context.Context, metadataKey string) (*BurnSecretResponse, error)

BurnSecret will burn an unred secret.

func (*Client) GenerateSecret

func (c *Client) GenerateSecret(ctx context.Context, passphrase string, ttlSeconds int, recipient string) (*GenerateSecretResponse, error)

GenerateSecret creates a short, unique secret. This is useful for temporary passwords, one-time pads, salts, etc.

func (*Client) GetMetadata

func (c *Client) GetMetadata(ctx context.Context, metadataKey string) (*GetMetadataResponse, error)

GetMetadata retrieves metadata about a secret. The metadata is intended to be used by the creator of the secret (i.e. not the recipient) and should generally be kept private. You can safely use the metadata key to retrieve basic information about the secret itself (e.g. if or when it was viewed) since the metadata key is different from the secret key.

func (*Client) GetRecentMetadata

func (c *Client) GetRecentMetadata(ctx context.Context) (*[]GetRecentMetadataResponse, error)

GetRecentMetadata returns a list of recent metadata.

func (*Client) GetStatus

func (c *Client) GetStatus(ctx context.Context) (*GetStatusResponse, error)

GetStatus returns the current status of the system.

func (*Client) RetrieveSecret

func (c *Client) RetrieveSecret(ctx context.Context, secretKey string, passphrase string) (*RetrieveSecretResponse, error)

RetrieveSecret returns a secret from the onetimesecret api.

func (*Client) ShareSecret

func (c *Client) ShareSecret(ctx context.Context, secret string, passphrase string, ttlSeconds int, recipient string) (*ShareSecretResponse, error)

ShareSecret stores a secret value.

type ClientOption

type ClientOption func(*Client)

ClientOption is the base struct for client options.

func WithAPIKey

func WithAPIKey(apiKey string) ClientOption

WithAPIKey overrides the clients default api key property

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the clients default base url property

func WithHTTPClient

func WithHTTPClient(client HTTPClient) ClientOption

WithHTTPClient overrides the default http client property

func WithUsername

func WithUsername(username string) ClientOption

WithUsername overrides the clients default username property

type GenerateSecretResponse

type GenerateSecretResponse struct {
	CustID             string   `json:"custid"`              // The requestors user id
	MetadataKey        string   `json:"metadata_key"`        // The unique key for the metadata. DO NOT share this.
	SecretKey          string   `json:"secret_key"`          // The unique key for the secret you created. This is key that you can share.
	TTL                int      `json:"ttl"`                 // The time-to-live that was specified (i.e. not the time remaining)
	MetadataTTL        int      `json:"metadata_ttl"`        // The remaining time (in seconds) that the metadata has left to live.
	SecretTTL          int      `json:"secret_ttl"`          // The remaining time (in seconds) that the secret has left to live.
	Recipient          []string `json:"recipient"`           // If a recipient was specified, this is an obfuscated version of the email address.
	Created            int64    `json:"created"`             // Time the metadata was created in unix time (UTC)
	Updated            int64    `json:"updated"`             // Time the metadata was last updated in unix time (UTC)
	PassphraseRequired bool     `json:"passphrase_required"` // If a passphrase was provided when the secret was created, this will be true. Otherwise false, obviously.
	Value              string   `json:"value"`               // The secret
}

GenerateSecretResponse represents the object returned from the api when generating a secret.

type GetMetadataResponse

type GetMetadataResponse struct {
	CustID             string   `json:"custid"`              // The requestors user id
	MetadataKey        string   `json:"metadata_key"`        // The unique key for the metadata. DO NOT share this.
	SecretKey          string   `json:"secret_key"`          // The unique key for the secret you created. This is key that you can share.
	TTL                int      `json:"ttl"`                 // The time-to-live that was specified (i.e. not the time remaining)
	MetadataTTL        int      `json:"metadata_ttl"`        // The remaining time (in seconds) that the metadata has left to live.
	SecretTTL          int      `json:"secret_ttl"`          // The remaining time (in seconds) that the secret has left to live.
	Recipient          []string `json:"recipient"`           // If a recipient was specified, this is an obfuscated version of the email address.
	Created            int64    `json:"created"`             // Time the metadata was created in unix time (UTC)
	Updated            int64    `json:"updated"`             // Time the metadata was last updated in unix time (UTC)
	PassphraseRequired bool     `json:"passphrase_required"` // If a passphrase was provided when the secret was created, this will be true. Otherwise false, obviously.
}

GetMetadataResponse represents the object returned from the api when requesting metadata for a secret.

type GetRecentMetadataResponse

type GetRecentMetadataResponse struct {
	CustID             string   `json:"custid"`              // The requestors user id
	MetadataKey        string   `json:"metadata_key"`        // The unique key for the metadata. DO NOT share this.
	SecretKey          string   `json:"secret_key"`          // The unique key for the secret you created. This is key that you can share.
	TTL                int      `json:"ttl"`                 // The time-to-live that was specified (i.e. not the time remaining)
	MetadataTTL        int      `json:"metadata_ttl"`        // The remaining time (in seconds) that the metadata has left to live.
	SecretTTL          int      `json:"secret_ttl"`          // The remaining time (in seconds) that the secret has left to live.
	Recipient          []string `json:"recipient"`           // If a recipient was specified, this is an obfuscated version of the email address.
	Created            int64    `json:"created"`             // Time the metadata was created in unix time (UTC)
	Updated            int64    `json:"updated"`             // Time the metadata was last updated in unix time (UTC)
	PassphraseRequired bool     `json:"passphrase_required"` // If a passphrase was provided when the secret was created, this will be true. Otherwise false, obviously.
}

GetRecentMetadataResponse represents the object returned from the api when requesting recent metadata.

type GetStatusResponse

type GetStatusResponse struct {
	Status string `json:"status"` //  The current system status. One of: nominal, offline.
}

GetStatusResponse represents the object returned from the api when requesting system status.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is used to abstract the requirement for http.Client

type RetrieveSecretResponse

type RetrieveSecretResponse struct {
	SecretKey string `json:"secret_key"` // The unique key for the secret you created. This is key that you can share.
	Value     string `json:"value"`      // The secret.
}

RetrieveSecretResponse represents the object returned from the api when requesting an existing secret.

type ShareSecretResponse

type ShareSecretResponse struct {
	CustID             string   `json:"custid"`              // The requestors user id
	MetadataKey        string   `json:"metadata_key"`        // The unique key for the metadata. DO NOT share this.
	SecretKey          string   `json:"secret_key"`          // The unique key for the secret you created. This is key that you can share.
	TTL                int      `json:"ttl"`                 // The time-to-live that was specified (i.e. not the time remaining)
	MetadataTTL        int      `json:"metadata_ttl"`        // The remaining time (in seconds) that the metadata has left to live.
	SecretTTL          int      `json:"secret_ttl"`          // The remaining time (in seconds) that the secret has left to live.
	Recipient          []string `json:"recipient"`           // If a recipient was specified, this is an obfuscated version of the email address.
	Created            int64    `json:"created"`             // Time the metadata was created in unix time (UTC)
	Updated            int64    `json:"updated"`             // Time the metadata was last updated in unix time (UTC)
	PassphraseRequired bool     `json:"passphrase_required"` // If a passphrase was provided when the secret was created, this will be true. Otherwise false, obviously.
}

ShareSecretResponse represents the object returned from the api when sharing a secret.

Jump to

Keyboard shortcuts

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