go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/rpc/get_project_cfg.go (about) 1 // Copyright 2021 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 rpc 16 17 import ( 18 "context" 19 20 "go.chromium.org/luci/auth/identity" 21 "go.chromium.org/luci/grpc/appstatus" 22 "go.chromium.org/luci/milo/internal/projectconfig" 23 projectconfigpb "go.chromium.org/luci/milo/proto/projectconfig" 24 milopb "go.chromium.org/luci/milo/proto/v1" 25 "go.chromium.org/luci/server/auth" 26 "google.golang.org/grpc/codes" 27 "google.golang.org/protobuf/proto" 28 ) 29 30 // GetProjectCfg implements milopb.MiloInternal service 31 func (s *MiloInternalService) GetProjectCfg(ctx context.Context, req *milopb.GetProjectCfgRequest) (_ *projectconfigpb.Project, err error) { 32 projectName := req.GetProject() 33 if projectName == "" { 34 return nil, appstatus.Error(codes.InvalidArgument, "project must be specified") 35 } 36 37 allowed, err := projectconfig.IsAllowed(ctx, projectName) 38 if err != nil { 39 return nil, err 40 } 41 if !allowed { 42 if auth.CurrentIdentity(ctx) == identity.AnonymousIdentity { 43 return nil, appstatus.Error(codes.Unauthenticated, "not logged in ") 44 } 45 return nil, appstatus.Error(codes.PermissionDenied, "no access to the project") 46 } 47 48 project, err := projectconfig.GetProject(ctx, projectName) 49 if err != nil { 50 return nil, err 51 } 52 metadataConfig := &projectconfigpb.MetadataConfig{} 53 if err := proto.Unmarshal(project.MetadataConfig, metadataConfig); err != nil { 54 return nil, err 55 } 56 return &projectconfigpb.Project{ 57 LogoUrl: project.LogoURL, 58 BugUrlTemplate: project.BugURLTemplate, 59 MetadataConfig: metadataConfig, 60 }, nil 61 }