From 5e54ada1e9f293855c670218451e960d2f2e1bc7 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sun, 11 Oct 2015 13:38:48 -0700 Subject: [PATCH] omaha: add structure for representing a single app update The protocol structures are intended for representing a collection of apps and their updates but for a server's internal API and data store we need to represent a self-contained app update manifest. --- omaha/update.go | 50 ++++++++++++++++++++++++++++++++++++++++++++ omaha/update_test.go | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 omaha/update.go create mode 100644 omaha/update_test.go diff --git a/omaha/update.go b/omaha/update.go new file mode 100644 index 0000000..a430acb --- /dev/null +++ b/omaha/update.go @@ -0,0 +1,50 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package omaha + +import ( + "encoding/xml" +) + +// Update is a manifest for a single omaha update response. It extends +// the standard Manifest protocol element with the application id and +// previous version which are used to match against the update request. +// A blank previous version indicates this update can be applied to any +// existing install. The application id may not be blank. +type Update struct { + XMLName xml.Name `xml:"update" json:"-"` + Id string `xml:"appid,attr"` + PreviousVersion string `xml:"previousversion,attr,omitempty"` + URL URL `xml:"urls>url"` + Manifest + + // The delta_okay request attribute is an update_engine extension. + RespectDeltaOK bool `xml:"respect_delta_okay,attr,omitempty"` +} + +// The URL attribute in Update is currently assumed to be a relative +// path which may be found on multiple mirrors. A server using this is +// expected to know the mirror prefix(s) it can give the client. +func (u *Update) URLs(prefixes []string) []*URL { + urls := make([]*URL, len(prefixes)) + for i, prefix := range prefixes { + urls[i] = &URL{CodeBase: prefix + u.URL.CodeBase} + } + return urls +} + +type Updater interface { + Update(os *OS, app *AppRequest) (*Update, error) +} diff --git a/omaha/update_test.go b/omaha/update_test.go new file mode 100644 index 0000000..d6e0bdf --- /dev/null +++ b/omaha/update_test.go @@ -0,0 +1,42 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package omaha + +import ( + "encoding/xml" + "testing" +) + +const SampleUpdate = ` + + + + + + + + + +` + +func TestUpdateURLs(t *testing.T) { + u := Update{} + xml.Unmarshal([]byte(SampleUpdate), &u) + + urls := u.URLs([]string{"http://localhost/updates/"}) + if urls[0].CodeBase != "http://localhost/updates/packages/9999.0.0" { + t.Error("Unexpected URL", urls[0].CodeBase) + } +}