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 noop // import "istio.io/istio/mixer/adapter/noop"
16
17// NOTE: This adapter will eventually be auto-generated so that it automatically supports all templates
18//       known to Mixer. For now, it's manually curated.
19
20import (
21	"context"
22	"time"
23
24	rpc "istio.io/gogo-genproto/googleapis/google/rpc"
25
26	"istio.io/istio/mixer/adapter/metadata"
27	"istio.io/istio/mixer/pkg/adapter"
28	"istio.io/istio/mixer/template/authorization"
29	"istio.io/istio/mixer/template/checknothing"
30	"istio.io/istio/mixer/template/listentry"
31	"istio.io/istio/mixer/template/logentry"
32	"istio.io/istio/mixer/template/metric"
33	"istio.io/istio/mixer/template/quota"
34	"istio.io/istio/mixer/template/reportnothing"
35	"istio.io/istio/mixer/template/tracespan"
36)
37
38type handler struct{}
39
40var checkResult = adapter.CheckResult{
41	Status:        rpc.Status{Code: int32(rpc.OK)},
42	ValidDuration: 1000000000 * time.Second,
43	ValidUseCount: 1000000000,
44}
45
46func (*handler) HandleAuthorization(context.Context, *authorization.Instance) (adapter.CheckResult, error) {
47	return checkResult, nil
48}
49
50func (*handler) HandleCheckNothing(context.Context, *checknothing.Instance) (adapter.CheckResult, error) {
51	return checkResult, nil
52}
53
54func (*handler) HandleListEntry(context.Context, *listentry.Instance) (adapter.CheckResult, error) {
55	return checkResult, nil
56}
57
58func (*handler) HandleLogEntry(context.Context, []*logentry.Instance) error {
59	return nil
60}
61
62func (*handler) HandleMetric(context.Context, []*metric.Instance) error {
63	return nil
64}
65
66func (*handler) HandleQuota(ctx context.Context, _ *quota.Instance, args adapter.QuotaArgs) (adapter.QuotaResult, error) {
67	return adapter.QuotaResult{
68			ValidDuration: 1000000000 * time.Second,
69			Amount:        args.QuotaAmount,
70		},
71		nil
72}
73
74func (*handler) HandleReportNothing(context.Context, []*reportnothing.Instance) error {
75	return nil
76}
77
78func (*handler) HandleTraceSpan(context.Context, []*tracespan.Instance) error {
79	return nil
80}
81
82func (*handler) Close() error { return nil }
83
84////////////////// Config //////////////////////////
85
86// GetInfo returns the Info associated with this adapter implementation.
87func GetInfo() adapter.Info {
88	info := metadata.GetInfo("noop")
89	info.NewBuilder = func() adapter.HandlerBuilder { return &builder{} }
90	return info
91}
92
93type builder struct{}
94
95func (*builder) SetCheckNothingTypes(map[string]*checknothing.Type)   {}
96func (*builder) SetAuthorizationTypes(map[string]*authorization.Type) {}
97func (*builder) SetReportNothingTypes(map[string]*reportnothing.Type) {}
98func (*builder) SetListEntryTypes(map[string]*listentry.Type)         {}
99func (*builder) SetLogEntryTypes(map[string]*logentry.Type)           {}
100func (*builder) SetMetricTypes(map[string]*metric.Type)               {}
101func (*builder) SetQuotaTypes(map[string]*quota.Type)                 {}
102func (*builder) SetTraceSpanTypes(map[string]*tracespan.Type)         {}
103func (*builder) SetAdapterConfig(adapter.Config)                      {}
104func (*builder) Validate() (ce *adapter.ConfigErrors)                 { return }
105
106func (b *builder) Build(context context.Context, env adapter.Env) (adapter.Handler, error) {
107	return &handler{}, nil
108}
109