-
Notifications
You must be signed in to change notification settings - Fork 70
/
license.go
141 lines (118 loc) · 4.02 KB
/
license.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package license
import (
"context"
"strconv"
)
type Status int
const (
// StatusMissing define state when the license could not be loaded from the start or was not provided
// NotLicensed
StatusMissing Status = iota
// StatusInvalid define state when the license and any of the fields are not valid
// NotLicensed
StatusInvalid
// StatusInvalidSignature define state when license signature could not be validated
// NotLicensed
StatusInvalidSignature
// StatusNotYetValid define state when the license contains nbf and current time (UTC) is before a specified time
// NotLicensed
StatusNotYetValid
// StatusNotAnymoreValid define state when the license contains exp and current time (UTC) is after a specified time
// NotLicensed
StatusNotAnymoreValid
// StatusFeatureNotEnabled define state when features requirements does not match one requested by the feature in Operator
// NotLicensed
StatusFeatureNotEnabled
// StatusFeatureExpired define state when token is valid, but feature itself is expired
// NotLicensed
StatusFeatureExpired
// StatusValid define state when Operator should continue execution
// Licensed
StatusValid
)
func (s Status) Valid() bool {
return s == StatusValid
}
func (s Status) Validate(feature Feature, subFeatures ...Feature) Status {
return s
}
func (s Status) String() string {
switch s {
case StatusMissing:
return "Missing"
case StatusInvalid:
return "Invalid"
case StatusInvalidSignature:
return "InvalidSignature"
case StatusNotYetValid:
return "NotYetValid"
case StatusNotAnymoreValid:
return "NotAnymoreValid"
case StatusFeatureNotEnabled:
return "FeatureNotEnabled"
case StatusFeatureExpired:
return "FeatureExpired"
case StatusValid:
return "Valid"
default:
return strconv.Itoa(int(s))
}
}
type Feature string
const (
// FeatureAll define feature name for all features
FeatureAll Feature = "*"
// FeatureArangoDB define feature name for ArangoDB
FeatureArangoDB Feature = "ArangoDB"
// FeatureArangoSearch define feature name for ArangoSearch
FeatureArangoSearch Feature = "ArangoSearch"
// FeatureDataSciencePackage define feature name for DataSciencePackage
FeatureDataSciencePackage Feature = "DataSciencePackage"
// SubFeatureGraphML define feature name for GraphML - SubFeature of DataSciencePackage
SubFeatureGraphML Feature = "GraphML"
// SubFeatureAnalytics define feature name for Analytics - SubFeature of DataSciencePackage
SubFeatureAnalytics Feature = "Analytics"
)
func (f Feature) In(features []Feature) bool {
for _, v := range features {
if v == f {
return true
}
}
return false
}
type License interface {
// Validate validates the license scope. In case of:
// - if feature is '*' - checks if:
// -- license is valid and not expired
// - if feature is not '*' and subFeatures list is empty - checks if:
// -- license is valid and not expired
// -- feature is enabled and not expired
// - if feature is not '*' and subFeatures list is not empty - checks if:
// -- license is valid and not expired
// -- feature is enabled and not expired
// -- for each subFeature defined in subFeatures:
// --- checks if subFeature or '*' is in the list of License Feature enabled SubFeatures
Validate(feature Feature, subFeatures ...Feature) Status
// Refresh refreshes the license from the source (Secret) and verifies the signature
Refresh(ctx context.Context) error
}