go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/appengine/coordinator/endpoints/registration/service.go (about) 1 // Copyright 2016 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package registration 16 17 import ( 18 "context" 19 20 "github.com/golang/protobuf/proto" 21 "google.golang.org/grpc/codes" 22 "google.golang.org/grpc/status" 23 24 "go.chromium.org/luci/grpc/grpcutil" 25 logdog "go.chromium.org/luci/logdog/api/endpoints/coordinator/registration/v1" 26 "go.chromium.org/luci/logdog/appengine/coordinator" 27 "go.chromium.org/luci/logdog/appengine/coordinator/endpoints" 28 ) 29 30 // server is a service supporting log stream registration. 31 type server struct{} 32 33 // New creates a new authenticating ServicesServer instance. 34 func New() logdog.RegistrationServer { 35 return &logdog.DecoratedRegistration{ 36 Service: &server{}, 37 Prelude: func(ctx context.Context, methodName string, req proto.Message) (context.Context, error) { 38 // Enter a datastore namespace based on the message type. All RPC messages 39 // in RegistrationServer must implement ProjectBoundMessage. We panic if 40 // they don't. 41 project := req.(endpoints.ProjectBoundMessage).GetMessageProject() 42 if project == "" { 43 return nil, status.Error(codes.InvalidArgument, "project is required") 44 } 45 if err := coordinator.WithProjectNamespace(&ctx, project); err != nil { 46 return nil, grpcutil.GRPCifyAndLogErr(ctx, err) 47 } 48 return ctx, nil 49 }, 50 } 51 }