go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/rpc/v0/get_run.go (about) 1 // Copyright 2022 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 "google.golang.org/grpc/codes" 21 22 "go.chromium.org/luci/common/logging" 23 "go.chromium.org/luci/grpc/appstatus" 24 25 apiv0pb "go.chromium.org/luci/cv/api/v0" 26 "go.chromium.org/luci/cv/internal/acls" 27 "go.chromium.org/luci/cv/internal/common" 28 "go.chromium.org/luci/cv/internal/run" 29 ) 30 31 // GetRun fetches information about one Run given a public Run ID. 32 func (s *RunsServer) GetRun(ctx context.Context, req *apiv0pb.GetRunRequest) (resp *apiv0pb.Run, err error) { 33 defer func() { err = appstatus.GRPCifyAndLog(ctx, err) }() 34 if err = checkCanUseAPI(ctx, "Runs.GetRun"); err != nil { 35 return 36 } 37 38 id, err := toInternalRunID(req.GetId()) 39 if err != nil { 40 return nil, err 41 } 42 43 r, err := run.LoadRun(ctx, id, acls.NewRunReadChecker()) 44 if err != nil { 45 return nil, err 46 } 47 48 ctx = logging.SetField(ctx, "run", r.ID) 49 return populateRunResponse(ctx, r) 50 } 51 52 func toInternalRunID(id string) (common.RunID, error) { 53 if id == "" { 54 return "", appstatus.Errorf(codes.InvalidArgument, "Run ID is required") 55 } 56 internalID, err := common.FromPublicRunID(id) 57 if err != nil { 58 return "", appstatus.Errorf(codes.InvalidArgument, "%s", err) 59 } 60 return internalID, nil 61 }