Documentation ¶
Overview ¶
Package client provides a general purpose Omaha update client implementation.
Example ¶
// Launch a dummy server for our client to talk to. s, err := omaha.NewTrivialServer("127.0.0.1:0") if err != nil { fmt.Println(err) return } defer s.Destroy() go s.Serve() // Configure our client. userID should be random but preserved // across restarts. version is the current version of our app. var ( serverURL = "http://" + s.Addr().String() userID = "8b10fc6d-30ca-49b2-b1a2-8185f03d522b" appID = "5ca607f8-61b5-4692-90ce-30380ba05a98" version = "1.0.0" ) c, err := NewAppClient(serverURL, userID, appID, version) if err != nil { fmt.Println(err) return } // Client version is the name and version of this updater. c.SetClientVersion("example-0.0.1") // Use SIGUSR1 to trigger immediate update checks. sigc := make(chan os.Signal, 1) //signal.Notify(sigc, syscall.SIGUSR1) sigc <- syscall.SIGUSR1 // Fake it //for { var source string select { case <-sigc: source = "ondemandupdate" case <-c.NextPing(): source = "scheduler" } // TODO: pass source to UpdateCheck _ = source // If updates are disabled call c.Ping() instead. update, err := c.UpdateCheck() if err != nil { fmt.Println(err) //continue return } // Download new application version. c.Event(&omaha.EventRequest{ Type: omaha.EventTypeUpdateDownloadFinished, Result: omaha.EventResultSuccess, }) // Install new application version here. c.Event(&omaha.EventRequest{ Type: omaha.EventTypeUpdateComplete, Result: omaha.EventResultSuccess, }) // Restart, new application is now running. c.SetVersion(update.Manifest.Version) c.Event(&omaha.EventRequest{ Type: omaha.EventTypeUpdateComplete, Result: omaha.EventResultSuccessReboot, }) //}
Output: omaha: update status noupdate
Index ¶
- Variables
- func EventString(e *omaha.EventRequest) string
- func FuzzyAfter(d, fuzz time.Duration) <-chan time.Time
- func FuzzyDuration(d, fuzz time.Duration) time.Duration
- func FuzzySleep(d, fuzz time.Duration)
- func NewErrorEvent(e ExitCode) *omaha.EventRequest
- type AppClient
- func (ac *AppClient) Event(event *omaha.EventRequest) <-chan error
- func (ac *AppClient) NewAppRequest() *omaha.Request
- func (ac *AppClient) Ping() error
- func (ac *AppClient) SendAppRequest(req *omaha.Request) (*omaha.AppResponse, error)
- func (ac *AppClient) SetAppID(appID string) error
- func (ac *AppClient) SetOEM(oem string)
- func (ac *AppClient) SetTrack(track string) error
- func (ac *AppClient) SetVersion(version string) error
- func (ac *AppClient) UpdateCheck() (*omaha.UpdateResponse, error)
- type Client
- type ErrorEvent
- type ExitCode
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // These events are what update_engine sends to CoreUpdate to // mark different steps in the update process. EventDownloading = &omaha.EventRequest{ Type: omaha.EventTypeUpdateDownloadStarted, Result: omaha.EventResultSuccess, } EventDownloaded = &omaha.EventRequest{ Type: omaha.EventTypeUpdateDownloadFinished, Result: omaha.EventResultSuccess, } EventInstalled = &omaha.EventRequest{ Type: omaha.EventTypeUpdateComplete, Result: omaha.EventResultSuccess, } EventComplete = &omaha.EventRequest{ Type: omaha.EventTypeUpdateComplete, Result: omaha.EventResultSuccessReboot, } )
Functions ¶
func EventString ¶
func EventString(e *omaha.EventRequest) string
EventString allows for easily logging events in a readable format.
func FuzzyAfter ¶
FuzzyAfter waits for the fuzzy duration to elapse and then sends the current time on the returned channel. See FuzzyDuration.
func FuzzyDuration ¶
FuzzyDuration randomizes the duration d within the range specified by fuzz. Specifically the value range is: [d-(fuzz/2), d+(fuzz/2)] The result will never be negative.
func FuzzySleep ¶
FuzzySleep pauses the current goroutine for the fuzzy duration d. See FuzzyDuration.
func NewErrorEvent ¶
func NewErrorEvent(e ExitCode) *omaha.EventRequest
NewErrorEvent creates an EventRequest for reporting errors.
Types ¶
type AppClient ¶
type AppClient struct { *Client // contains filtered or unexported fields }
AppClient supports managing a single application.
func NewAppClient ¶
NewAppClient creates a single application client. Shorthand for New(serverURL, userID).NewAppClient(appID, appVersion).
func (*AppClient) Event ¶
func (ac *AppClient) Event(event *omaha.EventRequest) <-chan error
Event asynchronously sends the given omaha event. Reading the error channel is optional.
func (*AppClient) NewAppRequest ¶
NewAppRequest creates a Request object containing one application.
func (*AppClient) SendAppRequest ¶
SendAppRequest sends a Request object and validates the response. On failure an error event is automatically sent to the server.
func (*AppClient) SetOEM ¶
SetOEM sets the application OEM name. This is a update_engine/Core Update protocol extension.
func (*AppClient) SetTrack ¶
SetTrack sets the application update track or group. This is a update_engine/Core Update protocol extension.
func (*AppClient) SetVersion ¶
SetVersion changes the application version.
func (*AppClient) UpdateCheck ¶
func (ac *AppClient) UpdateCheck() (*omaha.UpdateResponse, error)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client supports managing multiple apps using a single server.
func New ¶
New creates an omaha client for updating one or more applications. userID must be a persistent unique identifier of this update client.
func NewMachineClient ¶
NewMachineClient creates a machine-wide client, updating applications that may be used by multiple users. On Linux the system's machine id is used as the user id, and boot id is used as the omaha session id.
func (*Client) NewAppClient ¶
NewAppClient creates a new application client.
func (*Client) NextPing ¶
NextPing returns a timer channel that will fire when the next update check or ping should be sent.
func (*Client) SetClientVersion ¶
SetClientVersion sets the identifier of this updater application. e.g. "update_engine-0.1.0". Default is "go-omaha".
func (*Client) SetServerURL ¶
SetServerURL changes the Omaha server this client talks to. If the URL does not include a path component /v1/update/ is assumed.
type ErrorEvent ¶
type ErrorEvent interface { error ErrorEvent() *omaha.EventRequest }
ErrorEvent is an error type that can generate EventRequests for reporting.
type ExitCode ¶
type ExitCode int
ExitCode is used for omaha event error codes derived from update_engine
const ( ExitCodeSuccess ExitCode = 0 ExitCodeError ExitCode = 1 ExitCodeOmahaRequestError ExitCode = 2 ExitCodeOmahaResponseHandlerError ExitCode = 3 ExitCodeFilesystemCopierError ExitCode = 4 ExitCodePostinstallRunnerError ExitCode = 5 ExitCodeSetBootableFlagError ExitCode = 6 ExitCodeInstallDeviceOpenError ExitCode = 7 ExitCodeKernelDeviceOpenError ExitCode = 8 ExitCodeDownloadTransferError ExitCode = 9 ExitCodePayloadHashMismatchError ExitCode = 10 ExitCodePayloadSizeMismatchError ExitCode = 11 ExitCodeDownloadPayloadVerificationError ExitCode = 12 ExitCodeDownloadNewPartitionInfoError ExitCode = 13 ExitCodeDownloadWriteError ExitCode = 14 ExitCodeNewRootfsVerificationError ExitCode = 15 ExitCodeNewKernelVerificationError ExitCode = 16 ExitCodeSignedDeltaPayloadExpectedError ExitCode = 17 ExitCodeDownloadPayloadPubKeyVerificationError ExitCode = 18 ExitCodePostinstallBootedFromFirmwareB ExitCode = 19 ExitCodeDownloadStateInitializationError ExitCode = 20 ExitCodeDownloadInvalidMetadataMagicString ExitCode = 21 ExitCodeDownloadSignatureMissingInManifest ExitCode = 22 ExitCodeDownloadManifestParseError ExitCode = 23 ExitCodeDownloadMetadataSignatureError ExitCode = 24 ExitCodeDownloadMetadataSignatureVerificationError ExitCode = 25 ExitCodeDownloadMetadataSignatureMismatch ExitCode = 26 ExitCodeDownloadOperationHashVerificationError ExitCode = 27 ExitCodeDownloadOperationExecutionError ExitCode = 28 ExitCodeDownloadOperationHashMismatch ExitCode = 29 ExitCodeOmahaRequestEmptyResponseError ExitCode = 30 ExitCodeOmahaRequestXMLParseError ExitCode = 31 ExitCodeDownloadInvalidMetadataSize ExitCode = 32 ExitCodeDownloadInvalidMetadataSignature ExitCode = 33 ExitCodeOmahaResponseInvalid ExitCode = 34 ExitCodeOmahaUpdateIgnoredPerPolicy ExitCode = 35 ExitCodeOmahaUpdateDeferredPerPolicy ExitCode = 36 ExitCodeOmahaErrorInHTTPResponse ExitCode = 37 ExitCodeDownloadOperationHashMissingError ExitCode = 38 ExitCodeDownloadMetadataSignatureMissingError ExitCode = 39 ExitCodeOmahaUpdateDeferredForBackoff ExitCode = 40 ExitCodePostinstallPowerwashError ExitCode = 41 ExitCodeNewPCRPolicyVerificationError ExitCode = 42 ExitCodeNewPCRPolicyHTTPError ExitCode = 43 // Use the 2xxx range to encode HTTP errors from the Omaha server. // Sometimes aggregated into ExitCodeOmahaErrorInHTTPResponse ExitCodeOmahaRequestHTTPResponseBase ExitCode = 2000 // + HTTP response code )
These error codes are from CoreOS Container Linux update_engine 0.4.x https://github.com/coreos/update_engine/blob/master/src/update_engine/action_processor.h The whole list is included for the sake of completeness but lots of these are not generally applicable and not even used by update_engine any more. Also there are clearly duplicate errors for the same condition.