| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. | 1 // Copyright 2016 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 package apiservers | 15 package apiservers |
| 16 | 16 |
| 17 import ( | 17 import ( |
| 18 "github.com/luci/luci-go/scheduler/api/scheduler/v1" | 18 "github.com/luci/luci-go/scheduler/api/scheduler/v1" |
| 19 "github.com/luci/luci-go/scheduler/appengine/acl" |
| 19 "github.com/luci/luci-go/scheduler/appengine/catalog" | 20 "github.com/luci/luci-go/scheduler/appengine/catalog" |
| 20 "github.com/luci/luci-go/scheduler/appengine/engine" | 21 "github.com/luci/luci-go/scheduler/appengine/engine" |
| 21 "github.com/luci/luci-go/scheduler/appengine/presentation" | 22 "github.com/luci/luci-go/scheduler/appengine/presentation" |
| 22 "github.com/luci/luci-go/server/auth" | 23 "github.com/luci/luci-go/server/auth" |
| 23 "golang.org/x/net/context" | 24 "golang.org/x/net/context" |
| 24 "google.golang.org/grpc" | 25 "google.golang.org/grpc" |
| 25 "google.golang.org/grpc/codes" | 26 "google.golang.org/grpc/codes" |
| 26 | 27 |
| 27 "github.com/golang/protobuf/ptypes/empty" | 28 "github.com/golang/protobuf/ptypes/empty" |
| 28 ) | 29 ) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 func (s SchedulerServer) AbortInvocation(ctx context.Context, in *scheduler.Invo
cationRef) ( | 140 func (s SchedulerServer) AbortInvocation(ctx context.Context, in *scheduler.Invo
cationRef) ( |
| 140 *empty.Empty, error) { | 141 *empty.Empty, error) { |
| 141 return runAction(ctx, in.GetJobRef(), func() error { | 142 return runAction(ctx, in.GetJobRef(), func() error { |
| 142 return s.Engine.AbortInvocation(ctx, getJobId(in.GetJobRef()), i
n.GetInvocationId(), auth.CurrentIdentity(ctx)) | 143 return s.Engine.AbortInvocation(ctx, getJobId(in.GetJobRef()), i
n.GetInvocationId(), auth.CurrentIdentity(ctx)) |
| 143 }) | 144 }) |
| 144 } | 145 } |
| 145 | 146 |
| 146 //// Private helpers. | 147 //// Private helpers. |
| 147 | 148 |
| 148 func runAction(ctx context.Context, jobRef *scheduler.JobRef, action func() erro
r) (*empty.Empty, error) { | 149 func runAction(ctx context.Context, jobRef *scheduler.JobRef, action func() erro
r) (*empty.Empty, error) { |
| 149 » if !presentation.IsJobOwner(ctx, jobRef.GetProject(), jobRef.GetJob()) { | 150 » if !acl.IsJobOwner(ctx, jobRef.GetProject(), jobRef.GetJob()) { |
| 150 return nil, grpc.Errorf(codes.PermissionDenied, "No permission t
o execute action") | 151 return nil, grpc.Errorf(codes.PermissionDenied, "No permission t
o execute action") |
| 151 } | 152 } |
| 152 switch err := action(); { | 153 switch err := action(); { |
| 153 case err == nil: | 154 case err == nil: |
| 154 return &empty.Empty{}, nil | 155 return &empty.Empty{}, nil |
| 155 case err == engine.ErrNoSuchJob: | 156 case err == engine.ErrNoSuchJob: |
| 156 return nil, grpc.Errorf(codes.NotFound, "no such job") | 157 return nil, grpc.Errorf(codes.NotFound, "no such job") |
| 157 case err == engine.ErrNoSuchInvocation: | 158 case err == engine.ErrNoSuchInvocation: |
| 158 return nil, grpc.Errorf(codes.NotFound, "no such invocation") | 159 return nil, grpc.Errorf(codes.NotFound, "no such invocation") |
| 159 default: | 160 default: |
| 160 return nil, grpc.Errorf(codes.Internal, "internal error: %s", er
r) | 161 return nil, grpc.Errorf(codes.Internal, "internal error: %s", er
r) |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 | 164 |
| 164 func getJobId(jobRef *scheduler.JobRef) string { | 165 func getJobId(jobRef *scheduler.JobRef) string { |
| 165 return jobRef.GetProject() + "/" + jobRef.GetJob() | 166 return jobRef.GetProject() + "/" + jobRef.GetJob() |
| 166 } | 167 } |
| OLD | NEW |