1// Copyright 2017 Istio 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
15package adapter
16
17import (
18	"fmt"
19	"time"
20
21	rpc "istio.io/gogo-genproto/googleapis/google/rpc"
22
23	mixerpb "istio.io/api/mixer/v1"
24	"istio.io/istio/mixer/pkg/status"
25)
26
27// CheckResult provides return value from check request call on the handler.
28type CheckResult struct {
29	// The outcome status of the operation.
30	Status rpc.Status
31	// ValidDuration represents amount of time for which this result can be considered valid.
32	ValidDuration time.Duration
33	// ValidUseCount represents the number of uses for which this result can be considered valid.
34	ValidUseCount int32
35	// RouteDirective represents the route directive return result
36	RouteDirective *mixerpb.RouteDirective
37}
38
39// IsDefault returns true if the CheckResult is in its zero state
40func (r *CheckResult) IsDefault() bool {
41	return status.IsOK(r.Status) && r.ValidDuration == 0 && r.ValidUseCount == 0 && r.RouteDirective == nil
42}
43
44func (r *CheckResult) String() string {
45	return fmt.Sprintf("CheckResult: status:%s, duration:%d, usecount:%d", status.String(r.Status), r.ValidDuration, r.ValidUseCount)
46}
47