OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 registration |
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" | 9 "github.com/luci/luci-go/appengine/logdog/coordinator" |
10 "github.com/luci/luci-go/appengine/logdog/coordinator/endpoints" | 10 "github.com/luci/luci-go/appengine/logdog/coordinator/endpoints" |
11 » "github.com/luci/luci-go/common/api/logdog_coordinator/logs/v1" | 11 » "github.com/luci/luci-go/common/api/logdog_coordinator/registration/v1" |
12 "github.com/luci/luci-go/common/config" | 12 "github.com/luci/luci-go/common/config" |
13 "github.com/luci/luci-go/common/grpcutil" | 13 "github.com/luci/luci-go/common/grpcutil" |
14 log "github.com/luci/luci-go/common/logging" | 14 log "github.com/luci/luci-go/common/logging" |
15 "golang.org/x/net/context" | 15 "golang.org/x/net/context" |
16 ) | 16 ) |
17 | 17 |
18 // Server is the user-facing log access and query endpoint service. | 18 // server is a Cloud Endpoint service supporting log stream registration. |
nodir
2016/05/19 16:43:17
It is not Cloud Endpoints
dnj (Google)
2016/05/19 22:52:04
Done.
| |
19 type server struct { | 19 type server struct{} |
20 » // resultLimit is the maximum number of query results to return in a | |
21 » // single query. If zero, the default will be used. | |
22 » // | |
23 » // This is provided for testing purposes. | |
24 » resultLimit int | |
25 } | |
26 | 20 |
27 // New creates a new authenticating LogsServer instance. | 21 // New creates a new authenticating ServicesServer instance. |
28 func New() logdog.LogsServer { | 22 func New() logdog.RegistrationServer { |
29 » return newService(&server{}) | 23 » return &logdog.DecoratedRegistration{ |
30 } | 24 » » Service: &server{}, |
31 | |
32 func newService(svr *server) logdog.LogsServer { | |
33 » return &logdog.DecoratedLogs{ | |
34 » » Service: svr, | |
35 Prelude: func(c context.Context, methodName string, req proto.Me ssage) (context.Context, error) { | 25 Prelude: func(c context.Context, methodName string, req proto.Me ssage) (context.Context, error) { |
36 // Enter a datastore namespace based on the message type . | 26 // Enter a datastore namespace based on the message type . |
37 // | 27 // |
38 // We use a type switch here because this is a shared de corator. All user | 28 // We use a type switch here because this is a shared de corator. All user |
39 // mesages must implement ProjectBoundMessage. | 29 // mesages must implement ProjectBoundMessage. |
40 pbm, ok := req.(endpoints.ProjectBoundMessage) | 30 pbm, ok := req.(endpoints.ProjectBoundMessage) |
41 if ok { | 31 if ok { |
42 // Enter the requested project namespace. This v alidates that the | 32 // Enter the requested project namespace. This v alidates that the |
43 // current user has READ access. | 33 // current user has READ access. |
44 project := config.ProjectName(pbm.GetMessageProj ect()) | 34 project := config.ProjectName(pbm.GetMessageProj ect()) |
45 log.Fields{ | 35 log.Fields{ |
46 "project": project, | 36 "project": project, |
47 }.Debugf(c, "User is accessing project.") | 37 }.Debugf(c, "User is accessing project.") |
48 » » » » if err := coordinator.WithProjectNamespace(&c, p roject); err != nil { | 38 » » » » if err := coordinator.WithProjectNamespace(&c, p roject, coordinator.NamespaceAccessWRITE); err != nil { |
49 return nil, getGRPCError(c, err) | 39 return nil, getGRPCError(c, err) |
50 } | 40 } |
51 } | 41 } |
52 | 42 |
53 return c, nil | 43 return c, nil |
54 }, | 44 }, |
55 } | 45 } |
56 } | 46 } |
57 | 47 |
58 func getGRPCError(c context.Context, err error) error { | 48 func getGRPCError(c context.Context, err error) error { |
59 switch { | 49 switch { |
60 case err == nil: | 50 case err == nil: |
61 return nil | 51 return nil |
62 | 52 |
63 case err == config.ErrNoConfig: | 53 case err == config.ErrNoConfig: |
64 log.WithError(err).Errorf(c, "No project configuration defined." ) | 54 log.WithError(err).Errorf(c, "No project configuration defined." ) |
65 return grpcutil.PermissionDenied | 55 return grpcutil.PermissionDenied |
66 | 56 |
67 case coordinator.IsMembershipError(err): | 57 case coordinator.IsMembershipError(err): |
68 » » log.WithError(err).Errorf(c, "User does not have READ access to project.") | 58 » » log.WithError(err).Errorf(c, "User does not have WRITE access to project.") |
nodir
2016/05/19 16:43:17
I don't see why this is necessarily WRITE access.
dnj (Google)
2016/05/19 22:52:04
I think it could be useful for debugging, so I'm g
nodir
2016/05/25 17:34:05
Acknowledged.
| |
69 return grpcutil.PermissionDenied | 59 return grpcutil.PermissionDenied |
70 | 60 |
71 default: | 61 default: |
72 return grpcutil.Internal | 62 return grpcutil.Internal |
73 } | 63 } |
74 } | 64 } |
75 | |
76 func (s *server) limit(v int, d int) int { | |
77 if s.resultLimit > 0 { | |
78 d = s.resultLimit | |
79 } | |
80 if v <= 0 || v > d { | |
81 return d | |
82 } | |
83 return v | |
84 } | |
OLD | NEW |