| 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 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/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/common/api/logdog_coordinator/services/v1" | 11 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" |
| 12 "github.com/luci/luci-go/common/config" |
| 11 "github.com/luci/luci-go/common/grpcutil" | 13 "github.com/luci/luci-go/common/grpcutil" |
| 12 log "github.com/luci/luci-go/common/logging" | 14 log "github.com/luci/luci-go/common/logging" |
| 13 "golang.org/x/net/context" | 15 "golang.org/x/net/context" |
| 14 ) | 16 ) |
| 15 | 17 |
| 16 // server is a Cloud Endpoint service supporting privileged support services. | 18 // server is a Cloud Endpoint service supporting privileged support services. |
| 17 // | 19 // |
| 18 // This endpoint is restricted to LogDog support service accounts. | 20 // This endpoint is restricted to LogDog support service accounts. |
| 19 type server struct{} | 21 type server struct{} |
| 20 | 22 |
| 21 // New creates a new authenticating ServicesServer instance. | 23 // New creates a new authenticating ServicesServer instance. |
| 22 func New() logdog.ServicesServer { | 24 func New() logdog.ServicesServer { |
| 23 return &logdog.DecoratedServices{ | 25 return &logdog.DecoratedServices{ |
| 24 Service: &server{}, | 26 Service: &server{}, |
| 25 Prelude: func(c context.Context, methodName string, req proto.Me
ssage) (context.Context, error) { | 27 Prelude: func(c context.Context, methodName string, req proto.Me
ssage) (context.Context, error) { |
| 26 // Only service users may access this endpoint. | 28 // Only service users may access this endpoint. |
| 27 if err := coordinator.IsServiceUser(c); err != nil { | 29 if err := coordinator.IsServiceUser(c); err != nil { |
| 28 log.Fields{ | 30 log.Fields{ |
| 29 log.ErrorKey: err, | 31 log.ErrorKey: err, |
| 30 }.Errorf(c, "Failed to authenticate user as a se
rvice.") | 32 }.Errorf(c, "Failed to authenticate user as a se
rvice.") |
| 31 if !coordinator.IsMembershipError(err) { | 33 if !coordinator.IsMembershipError(err) { |
| 32 // 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. |
| 33 return nil, grpcutil.Internal | 35 return nil, grpcutil.Internal |
| 34 } | 36 } |
| 35 return nil, grpcutil.PermissionDenied | 37 return nil, grpcutil.PermissionDenied |
| 36 } | 38 } |
| 39 |
| 40 // Enter a datastore namespace based on the message type
. |
| 41 // |
| 42 // We use a type switch here because this is a shared de
corator. |
| 43 if pbm, ok := req.(endpoints.ProjectBoundMessage); ok { |
| 44 if err := coordinator.WithProjectNamespace(&c, c
onfig.ProjectName(pbm.GetMessageProject())); err != nil { |
| 45 return nil, grpcutil.Internal |
| 46 } |
| 47 } |
| 48 |
| 37 return c, nil | 49 return c, nil |
| 38 }, | 50 }, |
| 39 } | 51 } |
| 40 } | 52 } |
| OLD | NEW |