| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 services | 5 package services |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "github.com/golang/protobuf/proto" | 8 "github.com/golang/protobuf/proto" |
| 9 "github.com/luci/luci-go/common/config" | |
| 10 log "github.com/luci/luci-go/common/logging" | 9 log "github.com/luci/luci-go/common/logging" |
| 11 "github.com/luci/luci-go/grpc/grpcutil" | 10 "github.com/luci/luci-go/grpc/grpcutil" |
| 12 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/services/v1" | 11 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/services/v1" |
| 13 "github.com/luci/luci-go/logdog/appengine/coordinator" | 12 "github.com/luci/luci-go/logdog/appengine/coordinator" |
| 14 "github.com/luci/luci-go/logdog/appengine/coordinator/endpoints" | 13 "github.com/luci/luci-go/logdog/appengine/coordinator/endpoints" |
| 14 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 15 | 15 |
| 16 "golang.org/x/net/context" | 16 "golang.org/x/net/context" |
| 17 ) | 17 ) |
| 18 | 18 |
| 19 // server is a service supporting privileged support services. | 19 // server is a service supporting privileged support services. |
| 20 // | 20 // |
| 21 // This endpoint is restricted to LogDog support service accounts. | 21 // This endpoint is restricted to LogDog support service accounts. |
| 22 type server struct{} | 22 type server struct{} |
| 23 | 23 |
| 24 // New creates a new authenticating ServicesServer instance. | 24 // New creates a new authenticating ServicesServer instance. |
| 25 func New() logdog.ServicesServer { | 25 func New() logdog.ServicesServer { |
| 26 return &logdog.DecoratedServices{ | 26 return &logdog.DecoratedServices{ |
| 27 Service: &server{}, | 27 Service: &server{}, |
| 28 Prelude: func(c context.Context, methodName string, req proto.Me
ssage) (context.Context, error) { | 28 Prelude: func(c context.Context, methodName string, req proto.Me
ssage) (context.Context, error) { |
| 29 // Only service users may access this endpoint. | 29 // Only service users may access this endpoint. |
| 30 if err := coordinator.IsServiceUser(c); err != nil { | 30 if err := coordinator.IsServiceUser(c); err != nil { |
| 31 log.WithError(err).Errorf(c, "Failed to authenti
cate user as a service.") | 31 log.WithError(err).Errorf(c, "Failed to authenti
cate user as a service.") |
| 32 | 32 |
| 33 if !coordinator.IsMembershipError(err) { | 33 if !coordinator.IsMembershipError(err) { |
| 34 // Not a membership error. Something wen
t wrong on the server's end. | 34 // Not a membership error. Something wen
t wrong on the server's end. |
| 35 return nil, grpcutil.Internal | 35 return nil, grpcutil.Internal |
| 36 } | 36 } |
| 37 return nil, grpcutil.PermissionDenied | 37 return nil, grpcutil.PermissionDenied |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Enter a datastore namespace based on the message type
. | 40 // Enter a datastore namespace based on the message type
. |
| 41 // | 41 // |
| 42 // We use a type switch here because this is a shared de
corator. | 42 // We use a type switch here because this is a shared de
corator. |
| 43 if pbm, ok := req.(endpoints.ProjectBoundMessage); ok { | 43 if pbm, ok := req.(endpoints.ProjectBoundMessage); ok { |
| 44 » » » » project := config.ProjectName(pbm.GetMessageProj
ect()) | 44 » » » » project := cfgtypes.ProjectName(pbm.GetMessagePr
oject()) |
| 45 log.Fields{ | 45 log.Fields{ |
| 46 "project": project, | 46 "project": project, |
| 47 }.Debugf(c, "Request is entering project namespa
ce.") | 47 }.Debugf(c, "Request is entering project namespa
ce.") |
| 48 if err := coordinator.WithProjectNamespace(&c, p
roject, coordinator.NamespaceAccessNoAuth); err != nil { | 48 if err := coordinator.WithProjectNamespace(&c, p
roject, coordinator.NamespaceAccessNoAuth); err != nil { |
| 49 return nil, err | 49 return nil, err |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 return c, nil | 53 return c, nil |
| 54 }, | 54 }, |
| 55 } | 55 } |
| 56 } | 56 } |
| OLD | NEW |