Skip to content

Commit 04685c6

Browse files
committed
devapp/owners: add platform owners to owners endpoint
The owners HTTP endpoint will now include the platform owners information. This enables the querying of platform owners when a broken LUCI bot is detected. For golang/go#68790 Change-Id: I7a69f1cbb8db55db7369cf97bec41c8eedfbea3c Reviewed-on: https://go-review.googlesource.com/c/build/+/646837 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent c59a72b commit 04685c6

File tree

2 files changed

+67
-13
lines changed

2 files changed

+67
-13
lines changed

devapp/owners/owners.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,18 @@ type Request struct {
6060
//
6161
// If All is true, Paths must be empty.
6262
All bool `json:"all"`
63+
64+
// Platform indicates that the response should contain all platform
65+
// owners entries.
66+
Platform bool `json:"platform"`
6367
} `json:"payload"`
6468
Version int `json:"v"` // API version
6569
}
6670

6771
type Response struct {
6872
Payload struct {
69-
Entries map[string]*Entry `json:"entries"` // paths in request -> Entry
73+
Entries map[string]*Entry `json:"entries"` // paths in request -> Entry
74+
Platforms map[string]*Entry `json:"platforms"` // platforms (GOOS or GOARCH) -> Entry
7075
} `json:"payload"`
7176
Error string `json:"error,omitempty"`
7277
}
@@ -133,14 +138,18 @@ func Handler(w http.ResponseWriter, r *http.Request) {
133138
var resp Response
134139
if req.Payload.All {
135140
resp.Payload.Entries = entries
141+
resp.Payload.Platforms = archOses
136142
} else {
137143
resp.Payload.Entries = make(map[string]*Entry)
138144
for _, p := range req.Payload.Paths {
139145
resp.Payload.Entries[p] = match(p)
140146
}
147+
if req.Payload.Platform {
148+
resp.Payload.Platforms = archOses
149+
}
141150
}
142-
// resp.Payload.Entries must not be mutated because it contains
143-
// references to the global "entries" value.
151+
// resp.Payload.Entries and resp.Payload.Platforms must not be mutated because they
152+
// contain references to the global "entries" and "archOses" values.
144153

145154
var buf bytes.Buffer
146155
if err := json.NewEncoder(&buf).Encode(resp); err != nil {

devapp/owners/owners_test.go

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,44 @@ func TestMatch(t *testing.T) {
6464
}
6565

6666
func TestHandler(t *testing.T) {
67+
copyEntries := func(m map[string]*Entry) map[string]*Entry {
68+
out := make(map[string]*Entry)
69+
for k, v := range m {
70+
e := &Entry{
71+
Primary: v.Primary,
72+
}
73+
if len(v.Secondary) != 0 {
74+
e.Secondary = v.Secondary
75+
}
76+
out[k] = e
77+
}
78+
return out
79+
}
80+
6781
testCases := []struct {
68-
method string
69-
code int
70-
paths []string
71-
entries map[string]*Entry
82+
method string
83+
code int
84+
all bool
85+
paths []string
86+
entries map[string]*Entry
87+
platforms map[string]*Entry
7288
}{
73-
{"PUT", http.StatusMethodNotAllowed, nil, nil},
74-
{"OPTIONS", http.StatusOK, nil, nil},
89+
{"PUT", http.StatusMethodNotAllowed, false, nil, nil, nil},
90+
{"OPTIONS", http.StatusOK, false, nil, nil, nil},
7591
{
76-
"POST", http.StatusOK,
92+
"POST", http.StatusOK, false,
7793
[]string{"nonexistent/path"},
7894
map[string]*Entry{"nonexistent/path": nil},
95+
nil,
7996
},
8097
{
81-
"POST", http.StatusOK,
98+
"POST", http.StatusOK, false,
8299
[]string{"go/src/archive/zip/a.go"},
83100
map[string]*Entry{"go/src/archive/zip/a.go": {Primary: []Owner{joetsai}, Secondary: []Owner{bradfitz}}},
101+
nil,
84102
},
85103
{
86-
"POST", http.StatusOK,
104+
"POST", http.StatusOK, false,
87105
[]string{
88106
"go/src/archive/zip/a.go",
89107
"go/src/archive/zip/b.go",
@@ -92,9 +110,22 @@ func TestHandler(t *testing.T) {
92110
"go/src/archive/zip/a.go": {Primary: []Owner{joetsai}, Secondary: []Owner{bradfitz}},
93111
"go/src/archive/zip/b.go": {Primary: []Owner{joetsai}, Secondary: []Owner{bradfitz}},
94112
},
113+
nil,
114+
},
115+
{
116+
"POST", http.StatusOK, false,
117+
[]string{
118+
"go/src/archive/zip/a.go",
119+
"crypto/chacha20poly1305/chacha20poly1305.go",
120+
},
121+
map[string]*Entry{
122+
"go/src/archive/zip/a.go": {Primary: []Owner{joetsai}, Secondary: []Owner{bradfitz}},
123+
"crypto/chacha20poly1305/chacha20poly1305.go": {Primary: []Owner{filippo, roland, securityTeam}},
124+
},
125+
nil,
95126
},
96127
{
97-
"POST", http.StatusOK,
128+
"POST", http.StatusOK, false,
98129
[]string{
99130
"go/src/archive/zip/a.go",
100131
"crypto/chacha20poly1305/chacha20poly1305.go",
@@ -103,14 +134,25 @@ func TestHandler(t *testing.T) {
103134
"go/src/archive/zip/a.go": {Primary: []Owner{joetsai}, Secondary: []Owner{bradfitz}},
104135
"crypto/chacha20poly1305/chacha20poly1305.go": {Primary: []Owner{filippo, roland, securityTeam}},
105136
},
137+
archOses,
138+
},
139+
{
140+
"POST", http.StatusOK, true,
141+
[]string{},
142+
copyEntries(entries),
143+
archOses,
106144
},
107145
}
108146

109147
for _, tc := range testCases {
110148
var buf bytes.Buffer
111149
if tc.paths != nil {
112150
var oReq Request
151+
oReq.Payload.All = tc.all
113152
oReq.Payload.Paths = tc.paths
153+
if len(tc.platforms) > 0 {
154+
oReq.Payload.Platform = true
155+
}
114156
if err := json.NewEncoder(&buf).Encode(oReq); err != nil {
115157
t.Errorf("could not encode request: %v", err)
116158
continue
@@ -146,6 +188,9 @@ func TestHandler(t *testing.T) {
146188
if diff := cmp.Diff(oResp.Payload.Entries, tc.entries); diff != "" {
147189
t.Errorf("%s: (-got +want)\n%s", tc.method, diff)
148190
}
191+
if diff := cmp.Diff(oResp.Payload.Platforms, tc.platforms); diff != "" {
192+
t.Errorf("%s: (-got +want)\n%s", tc.method, diff)
193+
}
149194
}
150195
}
151196

0 commit comments

Comments
 (0)