Documentation ¶
Overview ¶
Package keygen allows programs to license and remotely update themselves using the keygen.sh service.
Index ¶
- Constants
- Variables
- func Genuine(licenseKey string, signingScheme SchemeCode) ([]byte, error)
- type Artifact
- type Client
- func (c *Client) Delete(path string, params interface{}, model interface{}) (*Response, error)
- func (c *Client) Get(path string, params interface{}, model interface{}) (*Response, error)
- func (c *Client) Patch(path string, params interface{}, model interface{}) (*Response, error)
- func (c *Client) Post(path string, params interface{}, model interface{}) (*Response, error)
- func (c *Client) Put(path string, params interface{}, model interface{}) (*Response, error)
- type Entitlement
- type EntitlementCode
- type Entitlements
- type ErrorCode
- type HeartbeatStatusCode
- type LeveledLogger
- type License
- func (l *License) Activate(fingerprint string) (*Machine, error)
- func (l *License) Deactivate(id string) error
- func (l *License) Entitlements() (Entitlements, error)
- func (l *License) Genuine() ([]byte, error)
- func (l *License) Machine(id string) (*Machine, error)
- func (l *License) Machines() (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(fingerprints ...string) error
- type LogLevel
- type LoggerInterface
- type Machine
- func (m *Machine) Deactivate() error
- func (m Machine) GetData() interface{}
- func (m Machine) GetID() string
- func (m Machine) GetType() string
- func (m *Machine) Monitor() chan 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
- type Machines
- type Release
- type Response
- type SchemeCode
- type ValidationCode
Constants ¶
const (
// The current version of the SDK.
SDKVersion = "1.13.0"
)
Variables ¶
var ( ErrLicenseTokenInvalid = errors.New("token authentication is invalid") ErrLicenseKeyInvalid = errors.New("license key authentication is invalid") ErrMachineAlreadyActivated = errors.New("machine is already activated") ErrMachineLimitExceeded = errors.New("machine limit has been exceeded") ErrMachineHeartbeatRequired = errors.New("machine heartbeat is required") ErrMachineHeartbeatDead = errors.New("machine heartbeat is dead") ErrNotAuthorized = errors.New("token is not authorized to perform the request") ErrNotFound = errors.New("resource does not exist") )
var ( // APIURL is the URL of the API service backend. APIURL = "https://api.keygen.sh" // APIVersion is the currently supported API version. APIVersion = "v1" // Account is the Keygen account ID used globally in the binding. Account string // Product is the Keygen product ID used globally in the binding. Product string // LicenseKey is the end-user's license key used in the binding. LicenseKey string // Token is the end-user's API token used in the binding. Token string // PublicKey is the Keygen public key used for verifying license keys // and API response signatures. PublicKey string // UpgradeKey is a developer's public key used for verifying that an // upgrade was signed by the developer. You can generate an upgrade // key using Keygen's CLI. UpgradeKey string // Channel is the release channel used when checking for upgrades. Channel = "stable" // Platform is the release platform used when checking for upgrades // and when activating machines. Platform = runtime.GOOS + "/" + runtime.GOARCH // 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 LoggerInterface = &LeveledLogger{Level: LogLevelError} )
var ( ErrLicenseNotActivated = errors.New("license is not activated") 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") ErrLicenseNotSigned = errors.New("license is not signed") ErrLicenseInvalid = errors.New("license is invalid") ErrFingerprintMissing = errors.New("fingerprint scope is missing") ErrProductMissing = errors.New("product scope is missing") )
var ( ErrHeartbeatPingFailed = errors.New("machine heartbeat ping failed") ErrMachineNotFound = errors.New("machine no longer exists") )
var ( ErrLicenseSchemeNotSupported = errors.New("license scheme is not supported") ErrLicenseSchemeMissing = errors.New("license scheme is missing") ErrLicenseKeyMissing = errors.New("license key is missing") ErrLicenseNotGenuine = errors.New("license key is not genuine") 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") ErrResponseDateInvalid = errors.New("response date is invalid") ErrResponseDateTooOld = errors.New("response date is too old") ErrPublicKeyMissing = errors.New("public key is missing") ErrPublicKeyInvalid = errors.New("public key is invalid") )
var (
ErrReleaseLocationMissing = errors.New("release has no download URL")
)
var (
ErrUpgradeNotAvailable = errors.New("no upgrades available (already up-to-date)")
)
var (
// Filetype is the release filetype used when checking for upgrades.
Filetype = "bin"
)
Functions ¶
func Genuine ¶
func Genuine(licenseKey string, signingScheme SchemeCode) ([]byte, error)
Genuine checks if a license key is genuine by cryptographically verifying the key using your PublicKey. If the key is genuine, the decoded dataset from the key will be returned. An error will be returned if the key is not genuine or otherwise invalid, e.g. ErrLicenseNotGenuine.
Types ¶
type Artifact ¶
type Artifact struct { ID string `json:"-"` Type string `json:"-"` Key string `json:"key"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` ReleaseId string `json:"-"` }
Artifact represents a Keygen artifact object.
func (*Artifact) SetRelationships ¶
type Client ¶
type Client struct { Account string LicenseKey string Token string PublicKey string UserAgent string }
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
func (*Entitlement) SetID ¶
func (e *Entitlement) SetID(id string) error
Implement jsonapi.UnmarshalData interface
func (*Entitlement) SetType ¶
func (e *Entitlement) SetType(t string) error
type EntitlementCode ¶ added in v1.2.0
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
Implement jsonapi.UnmarshalData interface
type ErrorCode ¶
type ErrorCode string
const ( ErrorCodeTokenInvalid ErrorCode = "TOKEN_INVALID" ErrorCodeLicenseInvalid ErrorCode = "LICENSE_INVALID" ErrorCodeFingerprintTaken ErrorCode = "FINGERPRINT_TAKEN" ErrorCodeMachineLimitExceeded ErrorCode = "MACHINE_LIMIT_EXCEEDED" ErrorCodeMachineHeartbeatDead ErrorCode = "MACHINE_HEARTBEAT_DEAD" ErrorCodeNotFound ErrorCode = "NOT_FOUND" )
type HeartbeatStatusCode ¶ added in v1.0.1
type HeartbeatStatusCode string
const ( HeartbeatStatusCodeNotStarted HeartbeatStatusCode = "NOT_STARTED" HeartbeatStatusCodeAlive HeartbeatStatusCode = "ALIVE" HeartbeatStatusCodeDead HeartbeatStatusCode = "DEAD" HeartbeatStatusCodeResurrected HeartbeatStatusCode = "RESURRECTED" )
type LeveledLogger ¶ added in v1.7.0
type LeveledLogger struct {
Level LogLevel
}
func (*LeveledLogger) Debugf ¶ added in v1.7.0
func (l *LeveledLogger) Debugf(format string, v ...interface{})
func (*LeveledLogger) Errorf ¶ added in v1.7.0
func (l *LeveledLogger) Errorf(format string, v ...interface{})
func (*LeveledLogger) Infof ¶ added in v1.7.0
func (l *LeveledLogger) Infof(format string, v ...interface{})
func (*LeveledLogger) Warnf ¶ added in v1.7.0
func (l *LeveledLogger) Warnf(format string, v ...interface{})
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"` LastValidated *time.Time `json:"lastValidated"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` Metadata map[string]interface{} `json:"metadata"` PolicyId string `json:"-"` }
License represents a Keygen license object.
func Validate ¶
Validate performs a license validation using the current Token, scoped to any provided fingerprints. It returns a License, and an error if the license is invalid, e.g. ErrLicenseNotActivated or ErrLicenseExpired.
func (*License) Activate ¶
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) 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() (Entitlements, error)
Machines lists up to 100 entitlements for the license.
func (*License) Genuine ¶
Genuine 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.
func (*License) Machine ¶ added in v1.5.0
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 ¶
type LoggerInterface ¶ added in v1.7.0
type LoggerInterface interface { // Debugf logs a debug message using Printf conventions. Debugf(format string, v ...interface{}) // Errorf logs a warning message using Printf conventions. Errorf(format string, v ...interface{}) // Infof logs an informational message using Printf conventions. Infof(format string, v ...interface{}) // Warnf logs a warning message using Printf conventions. Warnf(format string, v ...interface{}) }
LoggerInterface provides a basic leveled logging interface for printing debug, informational, warning, and error messages.
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"` Cores int `json:"cores"` 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:"-"` }
Machine represents a Keygen machine object.
func (*Machine) Deactivate ¶
Deactivate performs a machine deactivation for the current Machine. An error will be returned if the machine deactivation fails.
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.
type Release ¶
type Release struct { ID string `json:"-"` Type string `json:"-"` Name string `json:"name"` Description string `json:"description"` Version string `json:"version"` Filename string `json:"filename"` Filetype string `json:"filetype"` Filesize int64 `json:"filesize"` Platform string `json:"platform"` Channel string `json:"channel"` Signature string `json:"signature"` Checksum string `json:"checksum"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` Metadata map[string]interface{} `json:"metadata"` Location string `json:"-"` }
Release represents a Keygen release object.
type SchemeCode ¶ added in v1.1.0
type SchemeCode string
const (
SchemeCodeEd25519 SchemeCode = "ED25519_SIGN"
)
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" ValidationCodeFingerprintScopeRequired ValidationCode = "FINGERPRINT_SCOPE_REQUIRED" ValidationCodeFingerprintScopeMismatch ValidationCode = "FINGERPRINT_SCOPE_MISMATCH" ValidationCodeFingerprintScopeEmpty ValidationCode = "FINGERPRINT_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" )