Documentation ¶
Overview ¶
Package keygen allows programs to license and remotely update themselves using the keygen.sh service.
Index ¶
- Constants
- Variables
- func VerifyWebhook(request *http.Request) error
- type Artifact
- type CheckoutOption
- type CheckoutOptions
- type Client
- func (c *Client) Delete(ctx context.Context, path string, params interface{}, model interface{}) (*Response, error)
- func (c *Client) Get(ctx context.Context, path string, params interface{}, model interface{}) (*Response, error)
- func (c *Client) Patch(ctx context.Context, path string, params interface{}, model interface{}) (*Response, error)
- func (c *Client) Post(ctx context.Context, path string, params interface{}, model interface{}) (*Response, error)
- func (c *Client) Put(ctx context.Context, path string, params interface{}, model interface{}) (*Response, error)
- type ClientOptions
- type Component
- func (c Component) GetData() interface{}
- func (c Component) GetID() string
- func (c Component) GetType() string
- func (c *Component) SetData(to func(target interface{}) error) error
- func (c *Component) SetID(id string) error
- func (c *Component) SetType(t string) error
- func (c Component) UseExperimentalEmbeddedRelationshipData() bool
- type Components
- type Entitlement
- type EntitlementCode
- type Entitlements
- type EnvironmentError
- type Error
- type ErrorCode
- type HeartbeatStatusCode
- type LeveledLogger
- type License
- func (l *License) Activate(ctx context.Context, fingerprint string, components ...Component) (*Machine, error)
- func (l *License) Checkout(ctx context.Context, options ...CheckoutOption) (*LicenseFile, error)
- func (l *License) Deactivate(ctx context.Context, id string) error
- func (l *License) Entitlements(ctx context.Context) (Entitlements, error)
- func (l *License) Machine(ctx context.Context, id string) (*Machine, error)
- func (l *License) Machines(ctx context.Context) (Machines, error)
- func (l *License) SetData(to func(target interface{}) error) error
- func (l *License) SetID(id string) error
- func (l *License) SetRelationships(relationships map[string]interface{}) error
- func (l *License) SetType(t string) error
- func (l *License) Validate(ctx context.Context, fingerprints ...string) error
- func (l *License) Verify() ([]byte, error)
- type LicenseFile
- func (lic *LicenseFile) Decrypt(key string) (*LicenseFileDataset, error)
- func (lic *LicenseFile) SetData(to func(target interface{}) error) error
- func (lic *LicenseFile) SetID(id string) error
- func (lic *LicenseFile) SetRelationships(relationships map[string]interface{}) error
- func (lic *LicenseFile) SetType(t string) error
- func (lic *LicenseFile) Verify() error
- type LicenseFileDataset
- type LicenseFileError
- type LicenseKeyError
- type LicenseTokenError
- type LogLevel
- type LoggerOptions
- type Machine
- func (m *Machine) Checkout(ctx context.Context, options ...CheckoutOption) (*MachineFile, error)
- func (m *Machine) Components(ctx context.Context) (Components, error)
- func (m *Machine) Deactivate(ctx context.Context) error
- func (m Machine) GetData() interface{}
- func (m Machine) GetID() string
- func (m Machine) GetType() string
- func (m *Machine) Monitor(ctx context.Context) error
- func (m *Machine) Processes(ctx context.Context) (Processes, error)
- func (m *Machine) SetData(to func(target interface{}) error) error
- func (m *Machine) SetID(id string) error
- func (m *Machine) SetType(t string) error
- func (m *Machine) Spawn(ctx context.Context, pid string) (*Process, error)
- type MachineFile
- func (lic *MachineFile) Decrypt(key string) (*MachineFileDataset, error)
- func (lic *MachineFile) SetData(to func(target interface{}) error) error
- func (lic *MachineFile) SetID(id string) error
- func (lic *MachineFile) SetRelationships(relationships map[string]interface{}) error
- func (lic *MachineFile) SetType(t string) error
- func (lic *MachineFile) Verify() error
- type MachineFileDataset
- type MachineFileError
- type Machines
- type NotAuthorizedError
- type NotFoundError
- type Process
- func (p Process) GetData() interface{}
- func (p Process) GetID() string
- func (p Process) GetType() string
- func (p *Process) Kill(ctx context.Context) error
- func (p *Process) SetData(to func(target interface{}) error) error
- func (p *Process) SetID(id string) error
- func (p *Process) SetType(t string) error
- type ProcessStatusCode
- type Processes
- type RateLimitError
- type Release
- type Response
- type SchemeCode
- type UpgradeOptions
- type ValidationCode
- type ValidationResult
- type ValidationScope
Constants ¶
const (
// The current version of the SDK.
SDKVersion = "3.2.0"
)
Variables ¶
var ( ErrReleaseLocationMissing = errors.New("release has no download URL") ErrUpgradeNotAvailable = errors.New("no upgrades available (already up-to-date)") ErrResponseSignatureMissing = errors.New("response signature is missing") ErrResponseSignatureInvalid = errors.New("response signature is invalid") ErrResponseDigestMissing = errors.New("response digest is missing") ErrResponseDigestInvalid = errors.New("response digest is invalid") ErrResponseDateMissing = errors.New("response date is missing") ErrResponseDateInvalid = errors.New("response date is invalid") ErrResponseDateTooOld = errors.New("response date is too old") ErrRequestSignatureMissing = errors.New("request signature is missing") ErrRequestSignatureInvalid = errors.New("request signature is invalid") ErrRequestDigestMissing = errors.New("request digest is missing") ErrRequestDigestInvalid = errors.New("request digest is invalid") ErrRequestDateMissing = errors.New("request date is missing") ErrRequestDateInvalid = errors.New("request date is invalid") ErrRequestDateTooOld = errors.New("request date is too old") ErrPublicKeyMissing = errors.New("public key is missing") ErrPublicKeyInvalid = errors.New("public key is invalid") ErrValidationFingerprintMissing = errors.New("validation fingerprint scope is missing") ErrValidationComponentsMissing = errors.New("validation components scope is missing") ErrValidationProductMissing = errors.New("validation product scope is missing") ErrHeartbeatPingFailed = errors.New("heartbeat ping failed") ErrHeartbeatRequired = errors.New("heartbeat is required") ErrHeartbeatDead = errors.New("heartbeat is dead") ErrMachineAlreadyActivated = errors.New("machine is already activated") ErrMachineLimitExceeded = errors.New("machine limit has been exceeded") ErrMachineNotFound = errors.New("machine no longer exists") ErrProcessNotFound = errors.New("process no longer exists") ErrMachineFileNotSupported = errors.New("machine file is not supported") ErrMachineFileNotEncrypted = errors.New("machine file is not encrypted") ErrMachineFileNotGenuine = errors.New("machine file is not genuine") ErrMachineFileExpired = errors.New("machine file is expired") ErrComponentNotActivated = errors.New("component is not activated") ErrComponentAlreadyActivated = errors.New("component is already activated") ErrComponentConflict = errors.New("component is duplicated") ErrProcessLimitExceeded = errors.New("process limit has been exceeded") ErrLicenseSchemeNotSupported = errors.New("license scheme is not supported") ErrLicenseSchemeMissing = errors.New("license scheme is missing") ErrLicenseKeyMissing = errors.New("license key is missing") ErrLicenseKeyNotGenuine = errors.New("license key is not genuine") ErrLicenseNotActivated = errors.New("license is not activated") ErrLicenseNotAllowed = errors.New("license authentication is not allowed by policy") ErrLicenseExpired = errors.New("license is expired") ErrLicenseSuspended = errors.New("license is suspended") ErrLicenseTooManyMachines = errors.New("license has too many machines") ErrLicenseTooManyCores = errors.New("license has too many cores") ErrLicenseTooManyProcesses = errors.New("license has too many processes") ErrLicenseNotSigned = errors.New("license is not signed") ErrLicenseInvalid = errors.New("license is invalid") ErrLicenseFileNotSupported = errors.New("license file is not supported") ErrLicenseFileNotEncrypted = errors.New("license file is not encrypted") ErrLicenseFileNotGenuine = errors.New("license file is not genuine") ErrLicenseFileExpired = errors.New("license file is expired") ErrLicenseFileSecretMissing = errors.New("license file secret is missing") ErrTokenNotAllowed = errors.New("token authentication is not allowed by policy") ErrTokenFormatInvalid = errors.New("token format is invalid") ErrTokenInvalid = errors.New("token is invalid") ErrTokenExpired = errors.New("token is expired") ErrSystemClockUnsynced = errors.New("system clock is out of sync") )
General errors
var ( // APIURL is the URL of the API service backend. APIURL = "https://api.keygen.sh" // APIVersion is the currently supported API version. APIVersion = "1.7" // APIPrefix is the major version prefix included in all API URLs. APIPrefix = "v1" // Account is the Keygen account identifier used globally in the SDK. Account string // Product is the Keygen product identifier used globally in the SDK. Product string // Package is the Keygen package identifier used globally in the SDK. Package string // Environment is the Keygen environment identifier used globally in the SDK. Environment string // LicenseKey is the end-user's license key used in the SDK. LicenseKey string // Token is the end-user's API token used in the SDK. Token string // PublicKey is the Keygen public key used for verifying license keys // and API response signatures. PublicKey string // UserAgent defines the user-agent string sent to the API backend, // uniquely identifying an integration. UserAgent string // Logger is a leveled logger implementation used for printing debug, // informational, warning, and error messages. Logger LeveledLogger = NewLogger(LogLevelError) // Program is the name of the current program, used when installing // upgrades. Defaults to the current program name. Program = filepath.Base(os.Args[0]) // MaxClockDrift is the maximum allowable difference between the // server time Keygen's API sent a request or response and the // current system time, to prevent clock-tampering and replay // attacks. Set to -1 to disable. MaxClockDrift = time.Duration(5) * time.Minute // HTTPClient is the internal HTTP client used by the SDK for API // requests. Set this to a custom HTTP client, to implement e.g. // automatic retries, rate limiting checks, or for tests. HTTPClient = cleanhttp.DefaultPooledClient() )
var ( // Ext is the release artifact filename extension used when installing // upgrades. By default, binaries do not have an extension. Ext = "" )
Functions ¶
func VerifyWebhook ¶
VerifyWebhook verifies the signature of a webhook request sent from Keygen. The webhook event should be considered invalid if an error is returned.
Example:
func main() { http.HandleFunc("/webhooks", func(w http.ResponseWriter, r *http.Request) { if err := keygen.VerifyWebhook(r); err != nil { w.WriteHeader(http.StatusBadRequest) return } w.WriteHeader(http.StatusNoContent) }) http.ListenAndServe(":8081", nil) }
Types ¶
type Artifact ¶
type Artifact struct { ID string `json:"-"` Type string `json:"-"` Filename string `json:"filename"` Filetype string `json:"filetype"` Filesize int64 `json:"filesize"` Platform string `json:"platform"` Arch string `json:"arch"` Signature string `json:"signature"` Checksum string `json:"checksum"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` ReleaseId string `json:"-"` URL string `json:"-"` }
Artifact represents a Keygen artifact object.
func (*Artifact) SetRelationships ¶
SetRelationships implements the jsonapi.UnmarshalRelationship interface.
type CheckoutOption ¶
type CheckoutOption func(*CheckoutOptions) error
func CheckoutInclude ¶
func CheckoutInclude(includes ...string) CheckoutOption
func CheckoutTTL ¶
func CheckoutTTL(ttl time.Duration) CheckoutOption
type CheckoutOptions ¶
type Client ¶
type Client struct { HTTPClient *http.Client ClientOptions // contains filtered or unexported fields }
Client represents the internal HTTP client and config used for API requests.
func NewClientWithOptions ¶
func NewClientWithOptions(options *ClientOptions) *Client
NewClientWithOptions creates a new client with custom settings.
func (*Client) Delete ¶
func (c *Client) Delete(ctx context.Context, path string, params interface{}, model interface{}) (*Response, error)
Delete is a convenience helper for performing DELETE requests.
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, path string, params interface{}, model interface{}) (*Response, error)
Get is a convenience helper for performing GET requests.
func (*Client) Patch ¶
func (c *Client) Patch(ctx context.Context, path string, params interface{}, model interface{}) (*Response, error)
Patch is a convenience helper for performing PATCH requests.
type ClientOptions ¶
type ClientOptions struct { Account string Environment string LicenseKey string Token string PublicKey string UserAgent string APIVersion string APIPrefix string APIURL string }
ClientOptions stores config options used in API requests.
type Component ¶
type Component struct { ID string `json:"-"` Type string `json:"-"` Fingerprint string `json:"fingerprint"` Name string `json:"name"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` Metadata map[string]interface{} `json:"metadata"` MachineID string `json:"-"` }
Component represents a Keygen component object.
func (Component) GetData ¶
func (c Component) GetData() interface{}
GetData implements the jsonapi.MarshalData interface.
func (Component) UseExperimentalEmbeddedRelationshipData ¶
type Components ¶
type Components []Component
Components represents an array of component objects.
func (*Components) SetData ¶
func (c *Components) SetData(to func(target interface{}) error) error
SetData implements the jsonapi.UnmarshalData interface.
type Entitlement ¶
type Entitlement struct { ID string `json:"-"` Type string `json:"-"` Code EntitlementCode `json:"code"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` Metadata map[string]interface{} `json:"metadata"` }
Entitlement represents a Keygen entitlement object.
func (*Entitlement) SetData ¶
func (e *Entitlement) SetData(to func(target interface{}) error) error
SetData implements the jsonapi.UnmarshalData interface.
func (*Entitlement) SetID ¶
func (e *Entitlement) SetID(id string) error
SetID implements the jsonapi.UnmarshalResourceIdentifier interface.
func (*Entitlement) SetType ¶
func (e *Entitlement) SetType(t string) error
SetType implements the jsonapi.UnmarshalResourceIdentifier interface.
type EntitlementCode ¶
type EntitlementCode string
type Entitlements ¶
type Entitlements []Entitlement
Entitlements represents an array of entitlement objects.
func (*Entitlements) SetData ¶
func (e *Entitlements) SetData(to func(target interface{}) error) error
SetData implements the jsonapi.UnmarshalData interface.
type EnvironmentError ¶
type EnvironmentError struct{ Err *Error }
EnvironmentError represents an API environment error due to an invalid environment.
func (*EnvironmentError) Error ¶
func (e *EnvironmentError) Error() string
func (*EnvironmentError) Unwrap ¶
func (e *EnvironmentError) Unwrap() error
type ErrorCode ¶
type ErrorCode string
ErrorCode defines various error codes that are handled explicitly.
const ( ErrorCodeEnvironmentInvalid ErrorCode = "ENVIRONMENT_INVALID" ErrorCodeEnvironmentNotSupported ErrorCode = "ENVIRONMENT_NOT_SUPPORTED" ErrorCodeTokenFormatInvalid ErrorCode = "TOKEN_FORMAT_INVALID" ErrorCodeTokenInvalid ErrorCode = "TOKEN_INVALID" ErrorCodeTokenExpired ErrorCode = "TOKEN_EXPIRED" ErrorCodeTokenNotAllowed ErrorCode = "TOKEN_NOT_ALLOWED" ErrorCodeLicenseInvalid ErrorCode = "LICENSE_INVALID" ErrorCodeLicenseExpired ErrorCode = "LICENSE_EXPIRED" ErrorCodeLicenseSuspended ErrorCode = "LICENSE_SUSPENDED" ErrorCodeLicenseNotAllowed ErrorCode = "LICENSE_NOT_ALLOWED" ErrorCodeFingerprintTaken ErrorCode = "FINGERPRINT_TAKEN" ErrorCodeMachineLimitExceeded ErrorCode = "MACHINE_LIMIT_EXCEEDED" ErrorCodeProcessLimitExceeded ErrorCode = "MACHINE_PROCESS_LIMIT_EXCEEDED" ErrorCodeComponentFingerprintConflict ErrorCode = "COMPONENTS_FINGERPRINT_CONFLICT" ErrorCodeComponentFingerprintTaken ErrorCode = "COMPONENTS_FINGERPRINT_TAKEN" ErrorCodeMachineHeartbeatDead ErrorCode = "MACHINE_HEARTBEAT_DEAD" ErrorCodeProcessHeartbeatDead ErrorCode = "PROCESS_HEARTBEAT_DEAD" ErrorCodeNotFound ErrorCode = "NOT_FOUND" )
type HeartbeatStatusCode ¶
type HeartbeatStatusCode string
const ( HeartbeatStatusCodeNotStarted HeartbeatStatusCode = "NOT_STARTED" HeartbeatStatusCodeAlive HeartbeatStatusCode = "ALIVE" HeartbeatStatusCodeDead HeartbeatStatusCode = "DEAD" HeartbeatStatusCodeResurrected HeartbeatStatusCode = "RESURRECTED" )
type LeveledLogger ¶
type LeveledLogger interface { // Errorf logs a warning message using Printf conventions. Errorf(format string, v ...interface{}) // Warnf logs a warning message using Printf conventions. Warnf(format string, v ...interface{}) // Infof logs an informational message using Printf conventions. Infof(format string, v ...interface{}) // Debugf logs a debug message using Printf conventions. Debugf(format string, v ...interface{}) }
LeveledLogger provides a basic leveled logging interface for printing debug, informational, warning, and error messages.
func NewLogger ¶ added in v3.2.0
func NewLogger(level LogLevel) LeveledLogger
NewClient creates a new leveled logger with default log streams to stdout and stderr.
func NewLoggerWithOptions ¶ added in v3.2.0
func NewLoggerWithOptions(level LogLevel, options *LoggerOptions) LeveledLogger
NewLoggerWithOptions creates a new leveled logger with custom log streams.
func NewNilLogger ¶ added in v3.2.0
func NewNilLogger() LeveledLogger
NewNilLogger creates a new leveled logger with discarded log steams.
type License ¶
type License struct { ID string `json:"-"` Type string `json:"-"` Name string `json:"name"` Key string `json:"key"` Expiry *time.Time `json:"expiry"` Scheme SchemeCode `json:"scheme"` RequireHeartbeat bool `json:"requireHeartbeat"` LastValidated *time.Time `json:"lastValidated"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` Metadata map[string]interface{} `json:"metadata"` PolicyId string `json:"-"` LastValidation *ValidationResult `json:"-"` }
License represents a Keygen license object.
func Validate ¶
Validate performs a license validation using the current Token, scoped to any provided fingerprints. The first fingerprint should be a machine fingerprint, and the rest are optional component fingerprints. It returns a License, and an error if the license is invalid, e.g. ErrLicenseNotActivated or ErrLicenseExpired.
func (*License) Activate ¶
func (l *License) Activate(ctx context.Context, fingerprint string, components ...Component) (*Machine, error)
Activate performs a machine activation for the license, identified by the provided fingerprint. If the activation is successful, the new machine will be returned. An error will be returned if the activation fails, e.g. ErrMachineLimitExceeded or ErrMachineAlreadyActivated.
func (*License) Checkout ¶
func (l *License) Checkout(ctx context.Context, options ...CheckoutOption) (*LicenseFile, error)
Checkout generates an encrypted license file. Returns a LicenseFile.
func (*License) Deactivate ¶
Deactivate performs a machine deactivation, identified by the provided ID. The ID can be the machine's UUID or the machine's fingerprint. An error will be returned if the machine deactivation fails.
func (*License) Entitlements ¶
func (l *License) Entitlements(ctx context.Context) (Entitlements, error)
Machines lists up to 100 entitlements for the license.
func (*License) Machine ¶
Machine retreives a machine, identified by the provided ID. The ID can be the machine's UUID or the machine's fingerprint. An error will be returned if it does not exist.
func (*License) SetRelationships ¶
SetRelationships implements the jsonapi.UnmarshalRelationship interface.
func (*License) Validate ¶
Validate performs a license validation, scoped to an optional device fingerprint and an optional array of hardware component fingerprints. It returns an error if the license is invalid, e.g. ErrLicenseNotActivated, ErrLicenseExpired or ErrLicenseTooManyMachines.
func (*License) Verify ¶
Verify checks if the license's key is genuine by cryptographically verifying the key using your PublicKey. If the license is genuine, the decoded dataset from the key will be returned. An error will be returned if the license is not genuine, or if the key is not signed, e.g. ErrLicenseNotGenuine or ErrLicenseNotSigned.
type LicenseFile ¶
type LicenseFile struct { ID string `json:"-"` Type string `json:"-"` Certificate string `json:"certificate"` Issued time.Time `json:"issued"` Expiry time.Time `json:"expiry"` TTL int `json:"ttl"` LicenseID string `json:"-"` }
LicenseFile represents a Keygen license file.
func (*LicenseFile) Decrypt ¶
func (lic *LicenseFile) Decrypt(key string) (*LicenseFileDataset, error)
Decrypt decrypts the license file's encrypted dataset. It returns the decrypted dataset and any errors that occurred during decryption, e.g. ErrLicenseFileNotEncrypted.
func (*LicenseFile) SetData ¶
func (lic *LicenseFile) SetData(to func(target interface{}) error) error
SetData implements the jsonapi.UnmarshalData interface.
func (*LicenseFile) SetID ¶
func (lic *LicenseFile) SetID(id string) error
SetID implements the jsonapi.UnmarshalResourceIdentifier interface.
func (*LicenseFile) SetRelationships ¶
func (lic *LicenseFile) SetRelationships(relationships map[string]interface{}) error
SetRelationships implements the jsonapi.UnmarshalRelationship interface.
func (*LicenseFile) SetType ¶
func (lic *LicenseFile) SetType(t string) error
SetType implements the jsonapi.UnmarshalResourceIdentifier interface.
func (*LicenseFile) Verify ¶
func (lic *LicenseFile) Verify() error
Decrypt verifies the license file's signature. It returns any errors that occurred during verification, e.g. ErrLicenseFileInvalid.
type LicenseFileDataset ¶
type LicenseFileDataset struct { License License `json:"-"` Entitlements Entitlements `json:"-"` Issued time.Time `json:"issued"` Expiry time.Time `json:"expiry"` TTL int `json:"ttl"` }
LicenseFileDataset represents a decrypted license file object.
func (*LicenseFileDataset) SetData ¶
func (lic *LicenseFileDataset) SetData(to func(target interface{}) error) error
SetData implements the jsonapi.UnmarshalData interface.
func (*LicenseFileDataset) SetIncluded ¶
func (lic *LicenseFileDataset) SetIncluded(relationships []*jsonapi.ResourceObject, unmarshal func(res *jsonapi.ResourceObject, target interface{}) error) error
SetIncluded implements jsonapi.UnmarshalIncluded interface.
func (*LicenseFileDataset) SetMeta ¶
func (lic *LicenseFileDataset) SetMeta(to func(target interface{}) error) error
SetMeta implements jsonapi.UnmarshalMeta interface.
type LicenseFileError ¶
type LicenseFileError struct{ Err error }
LicenseFileError represents an invalid license file error.
func (*LicenseFileError) Error ¶
func (e *LicenseFileError) Error() string
func (*LicenseFileError) Unwrap ¶
func (e *LicenseFileError) Unwrap() error
type LicenseKeyError ¶
type LicenseKeyError struct{ Err *Error }
LicenseKeyError represents an API authentication error due to an invalid license key.
func (*LicenseKeyError) Error ¶
func (e *LicenseKeyError) Error() string
func (*LicenseKeyError) Unwrap ¶
func (e *LicenseKeyError) Unwrap() error
type LicenseTokenError ¶
type LicenseTokenError struct{ Err *Error }
LicenseTokenError represents an API authentication error due to an invalid license token.
func (*LicenseTokenError) Error ¶
func (e *LicenseTokenError) Error() string
func (*LicenseTokenError) Unwrap ¶
func (e *LicenseTokenError) Unwrap() error
type LoggerOptions ¶ added in v3.2.0
LoggerOptions stores config options used for the logger e.g. log streams.
type Machine ¶
type Machine struct { ID string `json:"-"` Type string `json:"-"` Name string `json:"name"` Fingerprint string `json:"fingerprint"` Hostname string `json:"hostname"` Platform string `json:"platform"` IP string `json:"ip"` Cores int `json:"cores"` RequireHeartbeat bool `json:"requireHeartbeat"` HeartbeatStatus HeartbeatStatusCode `json:"heartbeatStatus"` HeartbeatDuration int `json:"heartbeatDuration"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` Metadata map[string]interface{} `json:"metadata"` LicenseID string `json:"-"` // contains filtered or unexported fields }
Machine represents a Keygen machine object.
func (*Machine) Checkout ¶
func (m *Machine) Checkout(ctx context.Context, options ...CheckoutOption) (*MachineFile, error)
Checkout generates an encrypted machine file. Returns a MachineFile.
func (*Machine) Components ¶
func (m *Machine) Components(ctx context.Context) (Components, error)
Components lists up to 100 components for the machine.
func (*Machine) Deactivate ¶
Deactivate performs a machine deactivation for the current Machine. An error will be returned if the machine deactivation fails.
func (Machine) GetData ¶
func (m Machine) GetData() interface{}
GetData implements the jsonapi.MarshalData interface.
func (*Machine) Monitor ¶
Monitor performs, on a loop, a machine hearbeat ping for the current Machine. An error channel will be returned, where any ping errors will be emitted. Pings are sent according to the machine's required heartbeat window, minus 30 seconds to account for any network lag. Panics if a heartbeat ping fails after first ping.
func (*Machine) Spawn ¶
Spawn creates a new process for a machine, identified by the provided pid. If successful, the new Process will be returned. When unsuccessful, as error will be returned, e.g. ErrProcessLimitExceeded. Automatically starts a loop that sends heartbeat pings according to the process's Interval. Panics if a heartbeat ping fails after first ping.
type MachineFile ¶
type MachineFile struct { ID string `json:"-"` Type string `json:"-"` Certificate string `json:"certificate"` Issued time.Time `json:"issued"` Expiry time.Time `json:"expiry"` TTL int `json:"ttl"` MachineID string `json:"-"` LicenseID string `json:"-"` }
MachineFile represents a Keygen license file.
func (*MachineFile) Decrypt ¶
func (lic *MachineFile) Decrypt(key string) (*MachineFileDataset, error)
Decrypt decrypts the machine file's encrypted dataset. It returns the decrypted dataset and any errors that occurred during decryption, e.g. ErrMachineFileNotEncrypted.
func (*MachineFile) SetData ¶
func (lic *MachineFile) SetData(to func(target interface{}) error) error
SetData implements the jsonapi.UnmarshalData interface.
func (*MachineFile) SetID ¶
func (lic *MachineFile) SetID(id string) error
SetID implements the jsonapi.UnmarshalResourceIdentifier interface.
func (*MachineFile) SetRelationships ¶
func (lic *MachineFile) SetRelationships(relationships map[string]interface{}) error
SetRelationships implements the jsonapi.UnmarshalRelationship interface.
func (*MachineFile) SetType ¶
func (lic *MachineFile) SetType(t string) error
SetType implements the jsonapi.UnmarshalResourceIdentifier interface.
func (*MachineFile) Verify ¶
func (lic *MachineFile) Verify() error
Decrypt verifies the machine file's signature. It returns any errors that occurred during verification, e.g. ErrMachineFileInvalid.
type MachineFileDataset ¶
type MachineFileDataset struct { Machine Machine `json:"-"` License License `json:"-"` Entitlements Entitlements `json:"-"` Components Components `json:"-"` Issued time.Time `json:"issued"` Expiry time.Time `json:"expiry"` TTL int `json:"ttl"` }
MachineFileDataset represents a decrypted machine file object.
func (*MachineFileDataset) SetData ¶
func (lic *MachineFileDataset) SetData(to func(target interface{}) error) error
SetData implements the jsonapi.UnmarshalData interface.
func (*MachineFileDataset) SetIncluded ¶
func (lic *MachineFileDataset) SetIncluded(relationships []*jsonapi.ResourceObject, unmarshal func(res *jsonapi.ResourceObject, target interface{}) error) error
SetIncluded implements jsonapi.UnmarshalIncluded interface.
func (*MachineFileDataset) SetMeta ¶
func (lic *MachineFileDataset) SetMeta(to func(target interface{}) error) error
SetMeta implements jsonapi.UnmarshalMeta interface.
type MachineFileError ¶
type MachineFileError struct{ Err error }
MachineFileError represents an invalid machine file error.
func (*MachineFileError) Error ¶
func (e *MachineFileError) Error() string
func (*MachineFileError) Unwrap ¶
func (e *MachineFileError) Unwrap() error
type NotAuthorizedError ¶
type NotAuthorizedError struct{ Err *Error }
NotAuthorizedError represents an API permission error.
func (*NotAuthorizedError) Error ¶
func (e *NotAuthorizedError) Error() string
func (*NotAuthorizedError) Unwrap ¶
func (e *NotAuthorizedError) Unwrap() error
type NotFoundError ¶
type NotFoundError struct{ Err *Error }
NotFoundError represents an API not found error.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
func (*NotFoundError) Unwrap ¶
func (e *NotFoundError) Unwrap() error
type Process ¶
type Process struct { ID string `json:"-"` Type string `json:"-"` Pid string `json:"pid"` Status ProcessStatusCode `json:"status"` Interval int `json:"interval"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` Metadata map[string]interface{} `json:"metadata"` MachineID string `json:"-"` }
Process represents a Keygen process object.
func (Process) GetData ¶
func (p Process) GetData() interface{}
GetData implements the jsonapi.MarshalData interface.
func (*Process) Kill ¶
Kill deletes the current Process. An error will be returned if the process deletion fails.
type ProcessStatusCode ¶
type ProcessStatusCode string
const ( ProcessStatusCodeAlive ProcessStatusCode = "ALIVE" ProcessStatusCodeDead ProcessStatusCode = "DEAD" )
type RateLimitError ¶
type RateLimitError struct { Window string Count int Limit int Remaining int Reset time.Time RetryAfter int Err error }
RateLimitError represents an API rate limiting error.
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
func (*RateLimitError) Unwrap ¶
func (e *RateLimitError) Unwrap() error
type Release ¶
type Release struct { ID string `json:"-"` Type string `json:"-"` Name string `json:"name"` Description string `json:"description"` Version string `json:"version"` Channel string `json:"channel"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` Metadata map[string]interface{} `json:"metadata"` // contains filtered or unexported fields }
Release represents a Keygen release object.
func Upgrade ¶
func Upgrade(ctx context.Context, options UpgradeOptions) (*Release, error)
Upgrade checks if an upgrade is available for the provided version. Returns a Release and any errors that occurred, e.g. ErrUpgradeNotAvailable.
type UpgradeOptions ¶
type UpgradeOptions struct { // CurrentVersion is the current version of the program. This will be used by // Keygen to determine if an upgrade is available. CurrentVersion string // Product is the product ID to scope the upgrade to. This defaults to keygen.Product, // but overriding it may be useful if you're requesting an upgrade for another // accessible product, e.g. a product with an OPEN distribution strategy. Product string // Package is the package ID to scope the upgrade to. This defaults to keygen.Package, // but overriding it may be useful if you're requesting an upgrade for another // accessible package of the product. Package string // Constraint is a version constraint to use when checking for upgrades. For // example, to pin upgrades to v1, you would pass a "1.0" constraint. Constraint string // Channel is the release channel. One of: stable, rc, beta, alpha or dev. Channel string // PublicKey is your personal Ed25519ph public key, generated using Keygen's CLI // or using ssh-keygen. This will be used to verify the release's signature // before install. This MUST NOT be your Keygen account's public key. PublicKey string // Filename is the template string used when retrieving an artifact during // install. This should compile to a valid artifact identifier, e.g. a // filename for the current platform and arch. // // The default template is below: // // {{.program}}_{{.platform}}_{{.arch}}{{if .ext}}.{{.ext}}{{end}} // // Available template variables: // // program // the name of the currently running program (i.e. basename of os.Args[0]) // ext // the extension based on current platform (i.e. exe on Windows) // platform // the current platform (i.e. GOOS) // arch // the current architecture (i.e. GOARCH) // channel // the release channel (e.g. stable) // version // the release version (e.g. 1.0.0-beta.3) // // If more control is needed, provide a string. Filename string }
type ValidationCode ¶
type ValidationCode string
const ( ValidationCodeValid ValidationCode = "VALID" ValidationCodeNotFound ValidationCode = "NOT_FOUND" ValidationCodeSuspended ValidationCode = "SUSPENDED" ValidationCodeExpired ValidationCode = "EXPIRED" ValidationCodeOverdue ValidationCode = "OVERDUE" ValidationCodeNoMachine ValidationCode = "NO_MACHINE" ValidationCodeNoMachines ValidationCode = "NO_MACHINES" ValidationCodeTooManyMachines ValidationCode = "TOO_MANY_MACHINES" ValidationCodeTooManyCores ValidationCode = "TOO_MANY_CORES" ValidationCodeTooManyProcesses ValidationCode = "TOO_MANY_PROCESSES" ValidationCodeFingerprintScopeRequired ValidationCode = "FINGERPRINT_SCOPE_REQUIRED" ValidationCodeFingerprintScopeMismatch ValidationCode = "FINGERPRINT_SCOPE_MISMATCH" ValidationCodeFingerprintScopeEmpty ValidationCode = "FINGERPRINT_SCOPE_EMPTY" ValidationCodeComponentsScopeRequired ValidationCode = "COMPONENTS_SCOPE_REQUIRED" ValidationCodeComponentsScopeMismatch ValidationCode = "COMPONENTS_SCOPE_MISMATCH" ValidationCodeComponentsScopeEmpty ValidationCode = "COMPONENTS_SCOPE_EMPTY" ValidationCodeHeartbeatNotStarted ValidationCode = "HEARTBEAT_NOT_STARTED" ValidationCodeHeartbeatDead ValidationCode = "HEARTBEAT_DEAD" ValidationCodeProductScopeRequired ValidationCode = "PRODUCT_SCOPE_REQUIRED" ValidationCodeProductScopeEmpty ValidationCode = "PRODUCT_SCOPE_MISMATCH" ValidationCodePolicyScopeRequired ValidationCode = "POLICY_SCOPE_REQUIRED" ValidationCodePolicyScopeMismatch ValidationCode = "POLICY_SCOPE_MISMATCH" ValidationCodeMachineScopeRequired ValidationCode = "MACHINE_SCOPE_REQUIRED" ValidationCodeMachineScopeMismatch ValidationCode = "MACHINE_SCOPE_MISMATCH" ValidationCodeEntitlementsMissing ValidationCode = "ENTITLEMENTS_MISSING" ValidationCodeEntitlementsEmpty ValidationCode = "ENTITLEMENTS_SCOPE_EMPTY" )
type ValidationResult ¶
type ValidationResult struct { Detail string `json:"detail"` Valid bool `json:"valid"` Code ValidationCode `json:"code"` Scope *ValidationScope `json:"scope,omitempty"` }
ValidationResult is the result of the validation.
type ValidationScope ¶
type ValidationScope struct {
// contains filtered or unexported fields
}
ValidationResult contains the scopes for a validation.