From 6198ba9443ffd402c1e4bb7aaef94ae4511b3cc3 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Wed, 3 May 2017 12:38:39 -0700 Subject: [PATCH] protocol: style fix, use "ID" and "SHA" in identifiers. --- omaha/codes.go | 4 ++-- omaha/handler.go | 6 +++--- omaha/handler_test.go | 6 +++--- omaha/package.go | 14 +++++++------- omaha/package_test.go | 34 +++++++++++++++++----------------- omaha/protocol.go | 18 +++++++++--------- omaha/protocol_test.go | 14 +++++++------- omaha/trivial_server.go | 2 +- omaha/trivial_server_test.go | 2 +- omaha/update.go | 2 +- 10 files changed, 51 insertions(+), 51 deletions(-) diff --git a/omaha/codes.go b/omaha/codes.go index 783491a..822f4b1 100644 --- a/omaha/codes.go +++ b/omaha/codes.go @@ -150,8 +150,8 @@ const ( // Standard values AppOK AppStatus = "ok" AppRestricted AppStatus = "restricted" - AppUnknownId AppStatus = "error-unknownApplication" - AppInvalidId AppStatus = "error-invalidAppId" + AppUnknownID AppStatus = "error-unknownApplication" + AppInvalidID AppStatus = "error-invalidAppId" // Extra error values AppInvalidVersion AppStatus = "error-invalidVersion" diff --git a/omaha/handler.go b/omaha/handler.go index 754ffc3..42898f9 100644 --- a/omaha/handler.go +++ b/omaha/handler.go @@ -87,13 +87,13 @@ func (o *OmahaHandler) ServeHTTP(w http.ResponseWriter, httpReq *http.Request) { func (o *OmahaHandler) serveApp(omahaResp *Response, httpReq *http.Request, omahaReq *Request, appReq *AppRequest) *AppResponse { if err := o.CheckApp(omahaReq, appReq); err != nil { if appStatus, ok := err.(AppStatus); ok { - return omahaResp.AddApp(appReq.Id, appStatus) + return omahaResp.AddApp(appReq.ID, appStatus) } log.Printf("omaha: CheckApp failed: %v", err) - return omahaResp.AddApp(appReq.Id, AppInternalError) + return omahaResp.AddApp(appReq.ID, AppInternalError) } - appResp := omahaResp.AddApp(appReq.Id, AppOK) + appResp := omahaResp.AddApp(appReq.ID, AppOK) if appReq.UpdateCheck != nil { o.checkUpdate(appResp, httpReq, omahaReq, appReq) } diff --git a/omaha/handler_test.go b/omaha/handler_test.go index 013dea5..bf28107 100644 --- a/omaha/handler_test.go +++ b/omaha/handler_test.go @@ -23,7 +23,7 @@ import ( ) const ( - testAppId = "{27BD862E-8AE8-4886-A055-F7F1A6460627}" + testAppID = "{27BD862E-8AE8-4886-A055-F7F1A6460627}" testAppVer = "1.0.0" ) @@ -34,9 +34,9 @@ var ( func init() { nilRequest = NewRequest() - nilRequest.AddApp(testAppId, testAppVer) + nilRequest.AddApp(testAppID, testAppVer) nilResponse = NewResponse() - nilResponse.AddApp(testAppId, AppOK) + nilResponse.AddApp(testAppID, AppOK) } func compareXML(a, b interface{}) error { diff --git a/omaha/package.go b/omaha/package.go index d2dcdc6..d5f1586 100644 --- a/omaha/package.go +++ b/omaha/package.go @@ -32,8 +32,8 @@ var ( // Package represents a single downloadable file. type Package struct { Name string `xml:"name,attr"` - Sha1 string `xml:"hash,attr"` - Sha256 string `xml:"hash_sha256,attr,omitempty"` + SHA1 string `xml:"hash,attr"` + SHA256 string `xml:"hash_sha256,attr,omitempty"` Size uint64 `xml:"size,attr"` Required bool `xml:"required,attr"` } @@ -60,8 +60,8 @@ func (p *Package) FromReader(r io.Reader) error { return err } - p.Sha1 = sha1b64 - p.Sha256 = sha256b64 + p.SHA1 = sha1b64 + p.SHA256 = sha256b64 p.Size = uint64(n) return nil } @@ -86,12 +86,12 @@ func (p *Package) VerifyReader(r io.Reader) error { return PackageSizeMismatchError } - if p.Sha1 != sha1b64 { + if p.SHA1 != sha1b64 { return PackageHashMismatchError } - // Allow Sha256 to be empty since it is a protocol extension. - if p.Sha256 != "" && p.Sha256 != sha256b64 { + // Allow SHA256 to be empty since it is a later protocol addition. + if p.SHA256 != "" && p.SHA256 != sha256b64 { return PackageHashMismatchError } diff --git a/omaha/package_test.go b/omaha/package_test.go index c617218..03c6014 100644 --- a/omaha/package_test.go +++ b/omaha/package_test.go @@ -24,8 +24,8 @@ import ( func TestPackageFromPath(t *testing.T) { expect := Package{ Name: "null", - Sha1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", - Sha256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", + SHA1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", + SHA256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", Size: 0, Required: false, } @@ -44,8 +44,8 @@ func TestProtocolFromReader(t *testing.T) { data := strings.NewReader("testing\n") expect := Package{ Name: "", - Sha1: "mAFznarkTsUpPU4fU9P00tQm2Rw=", - Sha256: "EqYfThc/s6EcBdZHH3Ryj3YjG0pfzZZnzvOvh6OuTcI=", + SHA1: "mAFznarkTsUpPU4fU9P00tQm2Rw=", + SHA256: "EqYfThc/s6EcBdZHH3Ryj3YjG0pfzZZnzvOvh6OuTcI=", Size: 8, Required: false, } @@ -63,8 +63,8 @@ func TestProtocolFromReader(t *testing.T) { func TestPackageVerify(t *testing.T) { p := Package{ Name: "null", - Sha1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", - Sha256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", + SHA1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", + SHA256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", Size: 0, Required: false, } @@ -74,11 +74,11 @@ func TestPackageVerify(t *testing.T) { } } -func TestPackageVerifyNoSha256(t *testing.T) { +func TestPackageVerifyNoSHA256(t *testing.T) { p := Package{ Name: "null", - Sha1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", - Sha256: "", + SHA1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", + SHA256: "", Size: 0, Required: false, } @@ -91,8 +91,8 @@ func TestPackageVerifyNoSha256(t *testing.T) { func TestPackageVerifyBadSize(t *testing.T) { p := Package{ Name: "null", - Sha1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", - Sha256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", + SHA1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", + SHA256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", Size: 1, Required: false, } @@ -107,11 +107,11 @@ func TestPackageVerifyBadSize(t *testing.T) { } -func TestPackageVerifyBadSha1(t *testing.T) { +func TestPackageVerifyBadSHA1(t *testing.T) { p := Package{ Name: "null", - Sha1: "xxxxxxxxxxxxxxxxxxxxxxxxxxx=", - Sha256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", + SHA1: "xxxxxxxxxxxxxxxxxxxxxxxxxxx=", + SHA256: "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", Size: 0, Required: false, } @@ -125,11 +125,11 @@ func TestPackageVerifyBadSha1(t *testing.T) { } } -func TestPackageVerifyBadSha256(t *testing.T) { +func TestPackageVerifyBadSHA256(t *testing.T) { p := Package{ Name: "null", - Sha1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", - Sha256: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=", + SHA1: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=", + SHA256: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=", Size: 0, Required: false, } diff --git a/omaha/protocol.go b/omaha/protocol.go index e9f2248..4cc7922 100644 --- a/omaha/protocol.go +++ b/omaha/protocol.go @@ -34,10 +34,10 @@ type Request struct { Protocol string `xml:"protocol,attr"` InstallSource string `xml:"installsource,attr,omitempty"` IsMachine string `xml:"ismachine,attr,omitempty"` - RequestId string `xml:"requestid,attr,omitempty"` - SessionId string `xml:"sessionid,attr,omitempty"` + RequestID string `xml:"requestid,attr,omitempty"` + SessionID string `xml:"sessionid,attr,omitempty"` TestSource string `xml:"testsource,attr,omitempty"` - UserId string `xml:"userid,attr,omitempty"` + UserID string `xml:"userid,attr,omitempty"` Version string `xml:"version,attr,omitempty"` // update engine extension, duplicates the version attribute. @@ -57,7 +57,7 @@ func NewRequest() *Request { } func (r *Request) AddApp(id, version string) *AppRequest { - a := &AppRequest{Id: id, Version: version} + a := &AppRequest{ID: id, Version: version} r.Apps = append(r.Apps, a) return a } @@ -66,7 +66,7 @@ type AppRequest struct { Ping *PingRequest `xml:"ping"` UpdateCheck *UpdateRequest `xml:"updatecheck"` Events []*EventRequest `xml:"event" json:",omitempty"` - Id string `xml:"appid,attr,omitempty"` + ID string `xml:"appid,attr,omitempty"` Client string `xml:"client,attr,omitempty"` InstallAge string `xml:"installage,attr,omitempty"` Lang string `xml:"lang,attr,omitempty"` @@ -81,7 +81,7 @@ type AppRequest struct { // coreos update engine extensions AlephVersion string `xml:"alephversion,attr,omitempty"` - BootId string `xml:"bootid,attr,omitempty"` + BootID string `xml:"bootid,attr,omitempty"` MachineID string `xml:"machineid,attr,omitempty"` OEM string `xml:"oem,attr,omitempty"` OEMVersion string `xml:"oemversion,attr,omitempty"` @@ -143,7 +143,7 @@ type DayStart struct { } func (r *Response) AddApp(id string, status AppStatus) *AppResponse { - a := &AppResponse{Id: id, Status: status} + a := &AppResponse{ID: id, Status: status} r.Apps = append(r.Apps, a) return a } @@ -152,7 +152,7 @@ type AppResponse struct { Ping *PingResponse `xml:"ping"` UpdateCheck *UpdateResponse `xml:"updatecheck"` Events []*EventResponse `xml:"event" json:",omitempty"` - Id string `xml:"appid,attr,omitempty"` + ID string `xml:"appid,attr,omitempty"` Status AppStatus `xml:"status,attr,omitempty"` } @@ -248,7 +248,7 @@ type Action struct { // update engine extensions for event="postinstall" DisplayVersion string `xml:"DisplayVersion,attr,omitempty"` - Sha256 string `xml:"sha256,attr,omitempty"` + SHA256 string `xml:"sha256,attr,omitempty"` NeedsAdmin bool `xml:"needsadmin,attr,omitempty"` IsDeltaPayload bool `xml:"IsDeltaPayload,attr,omitempty"` DisablePayloadBackoff bool `xml:"DisablePayloadBackoff,attr,omitempty"` diff --git a/omaha/protocol_test.go b/omaha/protocol_test.go index 1980cf4..2dd3dbc 100644 --- a/omaha/protocol_test.go +++ b/omaha/protocol_test.go @@ -39,16 +39,16 @@ func TestOmahaRequestUpdateCheck(t *testing.T) { t.Error("Unexpected version", v.OS.Version) } - if v.Apps[0].Id != "{87efface-864d-49a5-9bb3-4b050a7c227a}" { - t.Error("Expected an App Id") + if v.Apps[0].ID != "{87efface-864d-49a5-9bb3-4b050a7c227a}" { + t.Error("Expected an App ID") } - if v.Apps[0].BootId != "{7D52A1CC-7066-40F0-91C7-7CB6A871BFDE}" { - t.Error("Expected a Boot Id") + if v.Apps[0].BootID != "{7D52A1CC-7066-40F0-91C7-7CB6A871BFDE}" { + t.Error("Expected a Boot ID") } if v.Apps[0].MachineID != "{8BDE4C4D-9083-4D61-B41C-3253212C0C37}" { - t.Error("Expected a MachineId") + t.Error("Expected a Machine ID") } if v.Apps[0].OEM != "ec3000" { @@ -88,13 +88,13 @@ func ExampleNewResponse() { u.AddURL("http://localhost/updates") m := u.AddManifest("9999.0.0") k := m.AddPackage() - k.Sha1 = "+LXvjiaPkeYDLHoNKlf9qbJwvnk=" + k.SHA1 = "+LXvjiaPkeYDLHoNKlf9qbJwvnk=" k.Name = "update.gz" k.Size = 67546213 k.Required = true a := m.AddAction("postinstall") a.DisplayVersion = "9999.0.0" - a.Sha256 = "0VAlQW3RE99SGtSB5R4m08antAHO8XDoBMKDyxQT/Mg=" + a.SHA256 = "0VAlQW3RE99SGtSB5R4m08antAHO8XDoBMKDyxQT/Mg=" a.NeedsAdmin = false a.IsDeltaPayload = true a.DisablePayloadBackoff = true diff --git a/omaha/trivial_server.go b/omaha/trivial_server.go index 2d38792..f95f5e6 100644 --- a/omaha/trivial_server.go +++ b/omaha/trivial_server.go @@ -92,7 +92,7 @@ func (ts *TrivialServer) AddPackage(file, name string) error { if len(ts.tu.Manifest.Actions) == 0 { act := ts.tu.Manifest.AddAction("postinstall") act.DisablePayloadBackoff = true - act.Sha256 = pkg.Sha256 + act.SHA256 = pkg.SHA256 } ts.Mux.Handle(pkg_prefix+name, &trivialHandler{file}) diff --git a/omaha/trivial_server_test.go b/omaha/trivial_server_test.go index df80d02..ce56104 100644 --- a/omaha/trivial_server_test.go +++ b/omaha/trivial_server_test.go @@ -26,7 +26,7 @@ import ( func mkUpdateReq() (*bytes.Buffer, error) { req := NewRequest() - app := req.AddApp(testAppId, testAppVer) + app := req.AddApp(testAppID, testAppVer) app.AddUpdateCheck() buf := &bytes.Buffer{} diff --git a/omaha/update.go b/omaha/update.go index ce2188e..321b5a4 100644 --- a/omaha/update.go +++ b/omaha/update.go @@ -25,7 +25,7 @@ import ( // existing install. The application id may not be blank. type Update struct { XMLName xml.Name `xml:"update" json:"-"` - Id string `xml:"appid,attr"` + ID string `xml:"appid,attr"` PreviousVersion string `xml:"previousversion,attr,omitempty"` URL URL `xml:"urls>url"` Manifest