ots

package module
v0.0.0-...-56373d7 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 9 Imported by: 0

README

ots

Documentation

Index

Constants

View Source
const (
	// StateNew means that secret is not received or viewed.
	StateNew = "new"
	// StateViewed means that secret metadata is already viewed.
	StateViewed = "viewed"
	// StateReceived means that secret is received.
	StateReceived = "received"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client of service.

func New

func New(userName, apiKey string, opts ...ClientOption) *Client

New returns new client instance.

func (*Client) Burn

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

Burn a secret by metadata key.

func (*Client) Generate

func (c *Client) Generate(ctx context.Context, opts ...GenerateOption) (Metadata, error)

Generate a secret.

func (*Client) Metadata

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

Metadata returns metadata by metadata key.

func (*Client) Secret

func (c *Client) Secret(ctx context.Context, secretKey string, opts ...SecretOption) (Secret, error)

Secret returns secret by secret key.

func (*Client) Share

func (c *Client) Share(ctx context.Context, secret string, opts ...ShareOption) (Metadata, error)

Share a secret.

func (*Client) Status

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

Status returns API status.

type ClientOption

type ClientOption func(*Client)

ClientOption client option.

func WithHTTPClient

func WithHTTPClient(httpClient HTTPClient) ClientOption

WithHTTPClient to set custom HTTP client.

type Duration

type Duration time.Duration

Duration type.

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns value as time.Duration.

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON marshal duration to json value.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(s []byte) (err error)

UnmarshalJSON unmarshal duration from json value.

type Error

type Error struct {
	Message    string
	StatusCode int
}

Error API error.

func (Error) Error

func (e Error) Error() string

Error returns error as a string.

type GenerateOption

type GenerateOption func(url.Values)

GenerateOption generate option.

func GeneratePassphrase

func GeneratePassphrase(passPhrase string) GenerateOption

GeneratePassphrase generate a secret with a passphrase.

func GenerateRecipient

func GenerateRecipient(recipient string) GenerateOption

GenerateRecipient generate a secret and send it to recipient.

func GenerateTTL

func GenerateTTL(ttl time.Duration) GenerateOption

GenerateTTL generate a secret with TTL.

type HTTPClient

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

HTTPClient interface.

type Metadata

type Metadata struct {
	CustID             string   `json:"custid"`
	Value              *string  `json:"value,omitempty"`
	MetadataKey        string   `json:"metadata_key"`
	SecretKey          string   `json:"secret_key"`
	TTL                Duration `json:"ttl"`
	MetadataTTL        Duration `json:"metadata_ttl,omitempty"`
	SecretTTL          Duration `json:"secret_ttl,omitempty"`
	State              State    `json:"state"`
	Recipient          []string `json:"recipient,omitempty"`
	PassphraseRequired bool     `json:"passphrase_required"`
	Created            Time     `json:"created"`
	Updated            Time     `json:"updated"`
	Received           *Time    `json:"received,omitempty"`
}

Metadata of a secret.

type Secret

type Secret struct {
	SecretKey string `json:"secret_key"`
	Value     string `json:"value"`
}

Secret value.

type SecretOption

type SecretOption func(url.Values)

SecretOption secret option.

func SecretPassphrase

func SecretPassphrase(passPhrase string) SecretOption

SecretPassphrase set a passphrase to receive a secret.

type ShareOption

type ShareOption func(url.Values)

ShareOption share option.

func SharePassphrase

func SharePassphrase(passPhrase string) ShareOption

SharePassphrase share a secret with a passphrase.

func ShareRecipient

func ShareRecipient(recipient string) ShareOption

ShareRecipient share a secret and send it to recipient.

func ShareTTL

func ShareTTL(ttl time.Duration) ShareOption

ShareTTL share a secret with TTL.

type State

type State string

State metadata state.

type Status

type Status int

Status API status.

const (
	// Offline means API is offline.
	Offline Status = iota
	// Nominal means API works fine.
	Nominal
)

type Time

type Time time.Time

Time type.

func (*Time) MarshalJSON

func (t *Time) MarshalJSON() ([]byte, error)

MarshalJSON marshal time to json value.

func (Time) Time

func (t Time) Time() time.Time

Time returns value as time.Time.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(s []byte) error

UnmarshalJSON unmarshal time from json value.

Jump to

Keyboard shortcuts

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