Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: milo/buildsource/buildbot/pubsub.go

Issue 2974263002: [milo] better ACL system for masters. (Closed)
Patch Set: fix tests Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « milo/buildsource/buildbot/master.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package buildbot 5 package buildbot
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "compress/gzip" 9 "compress/gzip"
10 "compress/zlib" 10 "compress/zlib"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 Master *buildbotMaster `json:"master"` 54 Master *buildbotMaster `json:"master"`
55 Builds []*buildbotBuild `json:"builds"` 55 Builds []*buildbotBuild `json:"builds"`
56 } 56 }
57 57
58 // buildbotMasterEntry is a container for a marshaled and packed buildbot 58 // buildbotMasterEntry is a container for a marshaled and packed buildbot
59 // master json. 59 // master json.
60 type buildbotMasterEntry struct { 60 type buildbotMasterEntry struct {
61 // Name of the buildbot master. 61 // Name of the buildbot master.
62 Name string `gae:"$id"` 62 Name string `gae:"$id"`
63 // Internal 63 // Internal
64 Internal bool 64 Internal bool
Vadim Sh. 2017/07/11 21:04:59 will this be removed?
iannucci 2017/07/11 21:10:28 later CL
65 // Data is the json serialzed and gzipped blob of the master data. 65 // Data is the json serialzed and gzipped blob of the master data.
66 Data []byte `gae:",noindex"` 66 Data []byte `gae:",noindex"`
67 // Modified is when this entry was last modified. 67 // Modified is when this entry was last modified.
68 Modified time.Time 68 Modified time.Time
69 } 69 }
70 70
71 // buildbotMasterPublic is a struct that exists for public builtbot masters, and
72 // not for internal masters. It's used for ACL checks.
73 type buildbotMasterPublic struct {
74 Name string `gae:"$id"`
75 }
76
71 func putDSMasterJSON( 77 func putDSMasterJSON(
72 c context.Context, master *buildbotMaster, internal bool) error { 78 c context.Context, master *buildbotMaster, internal bool) error {
73 for _, builder := range master.Builders { 79 for _, builder := range master.Builders {
74 // Trim out extra info in the "Changes" portion of the pending b uild state, 80 // Trim out extra info in the "Changes" portion of the pending b uild state,
75 // we don't actually need comments, files, and properties 81 // we don't actually need comments, files, and properties
76 for _, pbs := range builder.PendingBuildStates { 82 for _, pbs := range builder.PendingBuildStates {
77 for i := range pbs.Source.Changes { 83 for i := range pbs.Source.Changes {
78 pbs.Source.Changes[i].Comments = "" 84 pbs.Source.Changes[i].Comments = ""
79 pbs.Source.Changes[i].Files = nil 85 pbs.Source.Changes[i].Files = nil
80 pbs.Source.Changes[i].Properties = nil 86 pbs.Source.Changes[i].Properties = nil
81 } 87 }
82 } 88 }
83 } 89 }
84 entry := buildbotMasterEntry{ 90 entry := buildbotMasterEntry{
85 Name: master.Name, 91 Name: master.Name,
86 Internal: internal, 92 Internal: internal,
87 Modified: clock.Now(c).UTC(), 93 Modified: clock.Now(c).UTC(),
88 } 94 }
95 toPut := []interface{}{&entry}
96 publicTag := &buildbotMasterPublic{master.Name}
97 if internal {
98 // do the deletion immediately so that the 'public' bit is remov ed from
99 // datastore before any internal details are actually written to datastore.
100 if err := ds.Delete(c, publicTag); err != nil && err != ds.ErrNo SuchEntity {
101 return err
102 }
103 } else {
104 toPut = append(toPut, publicTag)
105 }
89 gzbs := bytes.Buffer{} 106 gzbs := bytes.Buffer{}
90 gsw := gzip.NewWriter(&gzbs) 107 gsw := gzip.NewWriter(&gzbs)
91 cw := iotools.CountingWriter{Writer: gsw} 108 cw := iotools.CountingWriter{Writer: gsw}
92 e := json.NewEncoder(&cw) 109 e := json.NewEncoder(&cw)
93 if err := e.Encode(master); err != nil { 110 if err := e.Encode(master); err != nil {
94 return err 111 return err
95 } 112 }
96 gsw.Close() 113 gsw.Close()
97 entry.Data = gzbs.Bytes() 114 entry.Data = gzbs.Bytes()
98 logging.Debugf(c, "Length of json data: %d", cw.Count) 115 logging.Debugf(c, "Length of json data: %d", cw.Count)
99 logging.Debugf(c, "Length of gzipped data: %d", len(entry.Data)) 116 logging.Debugf(c, "Length of gzipped data: %d", len(entry.Data))
100 » return ds.Put(c, &entry) 117 » return ds.Put(c, toPut)
101 } 118 }
102 119
103 // unmarshal a gzipped byte stream into a list of buildbot builds and masters. 120 // unmarshal a gzipped byte stream into a list of buildbot builds and masters.
104 func unmarshal( 121 func unmarshal(
105 c context.Context, msg []byte) ([]*buildbotBuild, *buildbotMaster, error ) { 122 c context.Context, msg []byte) ([]*buildbotBuild, *buildbotMaster, error ) {
106 bm := buildMasterMsg{} 123 bm := buildMasterMsg{}
107 if len(msg) == 0 { 124 if len(msg) == 0 {
108 return bm.Builds, bm.Master, nil 125 return bm.Builds, bm.Master, nil
109 } 126 }
110 reader, err := zlib.NewReader(bytes.NewReader(msg)) 127 reader, err := zlib.NewReader(bytes.NewReader(msg))
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 398
382 } 399 }
383 if master != nil { 400 if master != nil {
384 code := doMaster(c, master, internal) 401 code := doMaster(c, master, internal)
385 if code != 0 { 402 if code != 0 {
386 return code 403 return code
387 } 404 }
388 } 405 }
389 return http.StatusOK 406 return http.StatusOK
390 } 407 }
OLDNEW
« no previous file with comments | « milo/buildsource/buildbot/master.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698