/
endpoint.go
90 lines (65 loc) · 2.02 KB
/
endpoint.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package gaia
import (
"fmt"
"github.com/mitchellh/copystructure"
"go.aporeto.io/elemental"
)
// Endpoint represents the model of a endpoint
type Endpoint struct {
// URI of the exposed API.
URI string `json:"URI" msgpack:"URI" bson:"uri" mapstructure:"URI,omitempty"`
// The scopes authorized to access the API.
AllowedScopes [][]string `json:"allowedScopes" msgpack:"allowedScopes" bson:"allowedscopes" mapstructure:"allowedScopes,omitempty"`
// Methods exposed to access the API.
Methods []string `json:"methods" msgpack:"methods" bson:"methods" mapstructure:"methods,omitempty"`
// If `true`, the API is public.
Public bool `json:"public" msgpack:"public" bson:"public" mapstructure:"public,omitempty"`
// Use `allowedScopes`.
Scopes []string `json:"scopes" msgpack:"scopes" bson:"-" mapstructure:"scopes,omitempty"`
ModelVersion int `json:"-" msgpack:"-" bson:"_modelversion"`
}
// NewEndpoint returns a new *Endpoint
func NewEndpoint() *Endpoint {
return &Endpoint{
ModelVersion: 1,
AllowedScopes: [][]string{},
Methods: []string{},
Scopes: []string{},
}
}
// BleveType implements the bleve.Classifier Interface.
func (o *Endpoint) BleveType() string {
return "endpoint"
}
// DeepCopy returns a deep copy if the Endpoint.
func (o *Endpoint) DeepCopy() *Endpoint {
if o == nil {
return nil
}
out := &Endpoint{}
o.DeepCopyInto(out)
return out
}
// DeepCopyInto copies the receiver into the given *Endpoint.
func (o *Endpoint) DeepCopyInto(out *Endpoint) {
target, err := copystructure.Copy(o)
if err != nil {
panic(fmt.Sprintf("Unable to deepcopy Endpoint: %s", err))
}
*out = *target.(*Endpoint)
}
// Validate valides the current information stored into the structure.
func (o *Endpoint) Validate() error {
errors := elemental.Errors{}
requiredErrors := elemental.Errors{}
if err := ValidateHTTPMethods("methods", o.Methods); err != nil {
errors = errors.Append(err)
}
if len(requiredErrors) > 0 {
return requiredErrors
}
if len(errors) > 0 {
return errors
}
return nil
}