1package api
2
3import (
4	"fmt"
5	"io/ioutil"
6	"time"
7)
8
9type License struct {
10	// The unique identifier of the license
11	LicenseID string `json:"license_id"`
12
13	// The customer ID associated with the license
14	CustomerID string `json:"customer_id"`
15
16	// If set, an identifier that should be used to lock the license to a
17	// particular site, cluster, etc.
18	InstallationID string `json:"installation_id"`
19
20	// The time at which the license was issued
21	IssueTime time.Time `json:"issue_time"`
22
23	// The time at which the license starts being valid
24	StartTime time.Time `json:"start_time"`
25
26	// The time after which the license expires
27	ExpirationTime time.Time `json:"expiration_time"`
28
29	// The time at which the license ceases to function and can
30	// no longer be used in any capacity
31	TerminationTime time.Time `json:"termination_time"`
32
33	// The product the license is valid for
34	Product string `json:"product"`
35
36	// License Specific Flags
37	Flags map[string]interface{} `json:"flags"`
38
39	// Modules is a list of the licensed enterprise modules
40	Modules []string `json:"modules"`
41
42	// List of features enabled by the license
43	Features []string `json:"features"`
44}
45
46type LicenseReply struct {
47	Valid    bool
48	License  *License
49	Warnings []string
50}
51
52func (op *Operator) LicenseGet(q *QueryOptions) (*LicenseReply, error) {
53	var reply LicenseReply
54	if _, err := op.c.query("/v1/operator/license", &reply, q); err != nil {
55		return nil, err
56	} else {
57		return &reply, nil
58	}
59}
60
61func (op *Operator) LicenseGetSigned(q *QueryOptions) (string, error) {
62	r := op.c.newRequest("GET", "/v1/operator/license")
63	r.params.Set("signed", "1")
64	r.setQueryOptions(q)
65	_, resp, err := requireOK(op.c.doRequest(r))
66	if err != nil {
67		return "", err
68	}
69	defer closeResponseBody(resp)
70
71	data, err := ioutil.ReadAll(resp.Body)
72	if err != nil {
73		return "", err
74	}
75
76	return string(data), nil
77}
78
79// LicenseReset will reset the license to the builtin one if it is still valid.
80// If the builtin license is invalid, the current license stays active.
81//
82// DEPRECATED: Consul 1.10 removes the corresponding HTTP endpoint as licenses
83// are now set via agent configuration instead of through the API
84func (*Operator) LicenseReset(_ *WriteOptions) (*LicenseReply, error) {
85	return nil, fmt.Errorf("Consul 1.10 no longer supports API driven license management.")
86}
87
88// LicensePut will configure the Consul Enterprise license for the target datacenter
89//
90// DEPRECATED: Consul 1.10 removes the corresponding HTTP endpoint as licenses
91// are now set via agent configuration instead of through the API
92func (*Operator) LicensePut(_ string, _ *WriteOptions) (*LicenseReply, error) {
93	return nil, fmt.Errorf("Consul 1.10 no longer supports API driven license management.")
94}
95