This repository has been archived by the owner on May 23, 2023. It is now read-only.
/
products.go
65 lines (58 loc) · 1.8 KB
/
products.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package product
import (
"fmt"
"net/http"
"net/url"
"time"
"istio.io/istio/mixer/pkg/adapter"
)
// ServicesAttr is the name of the Product attribute that lists the Istio services it binds to (comma delim)
const ServicesAttr = "istio-services"
// NewManager creates a new product.Manager. Call Close() when done.
func NewManager(env adapter.Env, options Options) (*Manager, error) {
if err := options.validate(); err != nil {
return nil, err
}
pm := createManager(options, env.Logger())
pm.start(env)
return pm, nil
}
// Options allows us to specify options for how this product manager will run.
type Options struct {
// Client is a configured HTTPClient
Client *http.Client
// BaseURL of the Apigee customer proxy
BaseURL *url.URL
// RefreshRate determines how often the products are refreshed
RefreshRate time.Duration
// Key is provisioning key
Key string
// Secret is provisioning secret
Secret string
}
func (o *Options) validate() error {
if o.Client == nil ||
o.BaseURL == nil ||
o.RefreshRate <= 0 ||
o.Key == "" ||
o.Secret == "" {
return fmt.Errorf("all products options are required")
}
if o.RefreshRate < time.Minute {
return fmt.Errorf("products refresh_rate must be >= 1 minute")
}
return nil
}