Documentation ¶
Overview ¶
Package onetimesecret is a Go client that wraps the REST api of https://onetimesecret.com.
Index ¶
- Constants
- type BurnSecretResponse
- type Client
- func (c *Client) BurnSecret(ctx context.Context, metadataKey string) (*BurnSecretResponse, error)
- func (c *Client) GenerateSecret(ctx context.Context, passphrase string, ttlSeconds int, recipient string) (*GenerateSecretResponse, error)
- func (c *Client) GetMetadata(ctx context.Context, metadataKey string) (*GetMetadataResponse, error)
- func (c *Client) GetRecentMetadata(ctx context.Context) (*[]GetRecentMetadataResponse, error)
- func (c *Client) GetStatus(ctx context.Context) (*GetStatusResponse, error)
- func (c *Client) RetrieveSecret(ctx context.Context, secretKey string, passphrase string) (*RetrieveSecretResponse, error)
- func (c *Client) ShareSecret(ctx context.Context, secret string, passphrase string, ttlSeconds int, ...) (*ShareSecretResponse, error)
- type ClientOption
- type GenerateSecretResponse
- type GetMetadataResponse
- type GetRecentMetadataResponse
- type GetStatusResponse
- type HTTPClient
- type RetrieveSecretResponse
- type ShareSecretResponse
Constants ¶
const ( DefaultBaseURL = "https://onetimesecret.com/api/v1" // The default base url for the onetimesecret.com api. StatusEndpoint = "status" // The status 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 ¶
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 ¶
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.
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 ¶
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 {}
ShareSecretResponse represents the object returned from the api when sharing a secret.