| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package logs | 5 package logs |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "github.com/golang/protobuf/proto" | 8 "github.com/golang/protobuf/proto" |
| 9 "github.com/luci/luci-go/appengine/logdog/coordinator" |
| 10 "github.com/luci/luci-go/appengine/logdog/coordinator/endpoints" |
| 9 "github.com/luci/luci-go/common/api/logdog_coordinator/logs/v1" | 11 "github.com/luci/luci-go/common/api/logdog_coordinator/logs/v1" |
| 12 "github.com/luci/luci-go/common/config" |
| 13 "github.com/luci/luci-go/common/grpcutil" |
| 14 log "github.com/luci/luci-go/common/logging" |
| 10 "golang.org/x/net/context" | 15 "golang.org/x/net/context" |
| 11 ) | 16 ) |
| 12 | 17 |
| 13 // Server is the user-facing log access and query endpoint service. | 18 // Server is the user-facing log access and query endpoint service. |
| 14 type server struct { | 19 type server struct { |
| 15 // resultLimit is the maximum number of query results to return in a | 20 // resultLimit is the maximum number of query results to return in a |
| 16 // single query. If zero, the default will be used. | 21 // single query. If zero, the default will be used. |
| 17 // | 22 // |
| 18 // This is provided for testing purposes. | 23 // This is provided for testing purposes. |
| 19 resultLimit int | 24 resultLimit int |
| 20 } | 25 } |
| 21 | 26 |
| 22 // New creates a new authenticating LogsServer instance. | 27 // New creates a new authenticating LogsServer instance. |
| 23 func New() logdog.LogsServer { | 28 func New() logdog.LogsServer { |
| 24 return newService(&server{}) | 29 return newService(&server{}) |
| 25 } | 30 } |
| 26 | 31 |
| 27 func newService(svr *server) logdog.LogsServer { | 32 func newService(svr *server) logdog.LogsServer { |
| 28 return &logdog.DecoratedLogs{ | 33 return &logdog.DecoratedLogs{ |
| 29 Service: svr, | 34 Service: svr, |
| 30 Prelude: func(c context.Context, methodName string, req proto.Me
ssage) (context.Context, error) { | 35 Prelude: func(c context.Context, methodName string, req proto.Me
ssage) (context.Context, error) { |
| 36 // Enter a datastore namespace based on the message type
. |
| 37 // |
| 38 // We use a type switch here because this is a shared de
corator. All user |
| 39 // mesages must implement ProjectBoundMessage. |
| 40 pbm, ok := req.(endpoints.ProjectBoundMessage) |
| 41 if !ok { |
| 42 log.Fields{ |
| 43 "methodName": methodName, |
| 44 }.Errorf(c, "Request (%T) does not expose a proj
ect namespace.", req) |
| 45 return nil, grpcutil.Internal |
| 46 } |
| 47 |
| 48 if err := coordinator.WithProjectNamespace(&c, config.Pr
ojectName(pbm.GetMessageProject())); err != nil { |
| 49 return nil, grpcutil.Internal |
| 50 } |
| 51 |
| 31 return c, nil | 52 return c, nil |
| 32 }, | 53 }, |
| 33 } | 54 } |
| 34 } | 55 } |
| 35 | 56 |
| 36 func (s *server) limit(v int, d int) int { | 57 func (s *server) limit(v int, d int) int { |
| 37 if s.resultLimit > 0 { | 58 if s.resultLimit > 0 { |
| 38 d = s.resultLimit | 59 d = s.resultLimit |
| 39 } | 60 } |
| 40 if v <= 0 || v > d { | 61 if v <= 0 || v > d { |
| 41 return d | 62 return d |
| 42 } | 63 } |
| 43 return v | 64 return v |
| 44 } | 65 } |
| OLD | NEW |