credentials

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRefetchPercent = 90.0
)

Variables

View Source
var (
	ErrInvalidInput      = fmt.Errorf("invalid input")
	ErrNilRequest        = fmt.Errorf("nil request")
	ErrNoToken           = fmt.Errorf("no token")
	ErrTokenExpired      = fmt.Errorf("token expired")
	ErrFetchNotAttempted = fmt.Errorf("fetch not attempted")
	ErrFetchFailed       = fmt.Errorf("fetch failed")
)

Functions

This section is empty.

Types

type Credentials

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

Notes:

  • The network interface is set via the http.Client.
  • If v4, v6 or both are desired, it is set via the http.Client.
  • The timeout is set via the http.Client.
  • The maximum redirect count is set via the http.Client.
  • mTLS is set via the http.Client.
  • The TLS version is set via the http.Client.

func New

func New(opts ...Option) (*Credentials, error)

New creates a new credentials service object.

func (*Credentials) Credentials

func (c *Credentials) Credentials() (string, time.Time, error)

func (*Credentials) Decorate

func (c *Credentials) Decorate(headers http.Header) error

Decorate decorates the headers with the credentials. If the credentials are not valid, an error is returned.

func (*Credentials) MarkInvalid

func (c *Credentials) MarkInvalid(ctx context.Context)

MarkInvalid marks the credentials as invalid and causes the service to immediately attempt to fetch new credentials.

func (*Credentials) Start

func (c *Credentials) Start()

Start starts the credentials service.

func (*Credentials) Stop

func (c *Credentials) Stop()

Stop stops the credentials service.

func (*Credentials) WaitUntilFetched

func (c *Credentials) WaitUntilFetched(ctx context.Context)

WaitUntilFetched blocks until an attempt to fetch the credentials has been made or the context is canceled.

func (*Credentials) WaitUntilValid

func (c *Credentials) WaitUntilValid(ctx context.Context)

WaitUntilValid blocks until the credentials are valid or the context is canceled.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is the interface implemented by types that can be used to configure the credentials.

func AddDecorateListener

func AddDecorateListener(listener event.DecorateListener, cancel ...*event.CancelListenerFunc) Option

AddDecorateListener adds a listener for decorate events. If the optional cancel parameter is provided, it is set to a function that can be used to cancel the listener.

func AddFetchListener

func AddFetchListener(listener event.FetchListener, cancel ...*event.CancelListenerFunc) Option

AddFetchListener adds a listener for fetch events. If the optional cancel parameter is provided, it is set to a function that can be used to cancel the listener.

func AssumedLifetime

func AssumedLifetime(lifetime time.Duration) Option

AssumedLifetime is the lifetime of the credentials that is assumed if the credentials service does not return a lifetime. A value of zero means that no assumed lifetime is used. The default is zero.

func BootRetryWait

func BootRetryWait(bootRetryWait time.Duration) Option

BootRetryWait is the time to wait before retrying the request. Any value less than or equal to zero is treated as zero.

func FirmwareVersion

func FirmwareVersion(firmwareVersion string) Option

FirmwareVersion is the firmware version of the device.

func HTTPClient

func HTTPClient(client *http.Client) Option

HTTPClient is the HTTP client used to fetch the credentials.

func HardwareManufacturer

func HardwareManufacturer(hardwareManufacturer string) Option

HardwareManufacturer is the hardware manufacturer of the device.

func HardwareModel

func HardwareModel(hardwareModel string) Option

HardwareModel is the hardware model of the device.

func IgnoreBody

func IgnoreBody() Option

IgnoreBody is a flag that indicates whether the body of the response should be ignored instead of examined for an expiration time. The default is to examine the body.

func LastRebootReason

func LastRebootReason(lastRebootReason string) Option

LastRebootReason is the reason for the most recent reboot of the device.

func LastReconnectReason

func LastReconnectReason(lastReconnectReason func() string) Option

LastReconnectReason is the reason for the most recent reconnect of the device. This is a dynamic value that is obtained by calling the function provided.

func LocalStorage

func LocalStorage(fs fs.FS, filename string, perm iofs.FileMode) Option

LocalStorage is the local storage used to cache the credentials.

The filename (and path) is relative to the provided filesystem.

func MacAddress

func MacAddress(macAddress wrp.DeviceID) Option

MacAddress is the MAC address of the device.

func NowFunc

func NowFunc(nowFunc func() time.Time) Option

NowFunc is the function used to obtain the current time.

func PartnerID

func PartnerID(partnerID func() string) Option

PartnerID is the partner ID of the device. This is a dynamic value that is obtained by calling the function provided.

func RefetchPercent

func RefetchPercent(percent float64) Option

RefetchPercent is the percentage of the lifetime of the credentials that must pass before a refetch is attempted. The accepted range is 0.0 to 100.0. If 0.0 is specified the default is used. The default is 90.0.

func Required

func Required() Option

Required is a flag that indicates whether the credentials are required to successfully decorate a request. The default is optional.

func SerialNumber

func SerialNumber(serialNumber string) Option

SerialNumber is the serial number of the device.

func URL

func URL(url string) Option

URL is the URL of the credential service.

func XmidtProtocol

func XmidtProtocol(xmidtProtocol string) Option

XmidtProtocol is the protocol version used by the device to communicate with the Xmidt cluster.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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