Revert early out errors in license API (#10952)

Licensing recently changed in Consul v1.10 and along with those changes
the client API was updated such that PutLicense and ResetLicense both
immediately return an error to avoid an unecessary round trip that will
inevitably fail.

For reference, see: 08eb600ee5

Unfortunately, this change broke forward compatibility such that a v1.10
client can no longer make these requests to a v1.9 server which is a
valid use case.

This commit reintroduces these requests to fix this compatibility
breakage but leaves the deprecation notices in tact.
This commit is contained in:
Paul Ewing 2021-08-31 09:36:35 -07:00 committed by GitHub
parent d341e113db
commit a121970f53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 5 deletions

4
.changelog/10952.txt Normal file
View File

@ -0,0 +1,4 @@
```release-note:bug
api: Revert early out errors from license APIs to allow v1.10+ clients to
manage licenses on older servers
```

View File

@ -1,8 +1,8 @@
package api package api
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"strings"
"time" "time"
) )
@ -81,14 +81,39 @@ func (op *Operator) LicenseGetSigned(q *QueryOptions) (string, error) {
// //
// DEPRECATED: Consul 1.10 removes the corresponding HTTP endpoint as licenses // DEPRECATED: Consul 1.10 removes the corresponding HTTP endpoint as licenses
// are now set via agent configuration instead of through the API // are now set via agent configuration instead of through the API
func (*Operator) LicenseReset(_ *WriteOptions) (*LicenseReply, error) { func (op *Operator) LicenseReset(opts *WriteOptions) (*LicenseReply, error) {
return nil, fmt.Errorf("Consul 1.10 no longer supports API driven license management.") var reply LicenseReply
r := op.c.newRequest("DELETE", "/v1/operator/license")
r.setWriteOptions(opts)
_, resp, err := requireOK(op.c.doRequest(r))
if err != nil {
return nil, err
}
defer resp.Body.Close()
if err := decodeBody(resp, &reply); err != nil {
return nil, err
}
return &reply, nil
} }
// LicensePut will configure the Consul Enterprise license for the target datacenter // LicensePut will configure the Consul Enterprise license for the target datacenter
// //
// DEPRECATED: Consul 1.10 removes the corresponding HTTP endpoint as licenses // DEPRECATED: Consul 1.10 removes the corresponding HTTP endpoint as licenses
// are now set via agent configuration instead of through the API // are now set via agent configuration instead of through the API
func (*Operator) LicensePut(_ string, _ *WriteOptions) (*LicenseReply, error) { func (op *Operator) LicensePut(license string, opts *WriteOptions) (*LicenseReply, error) {
return nil, fmt.Errorf("Consul 1.10 no longer supports API driven license management.") var reply LicenseReply
r := op.c.newRequest("PUT", "/v1/operator/license")
r.setWriteOptions(opts)
r.body = strings.NewReader(license)
_, resp, err := requireOK(op.c.doRequest(r))
if err != nil {
return nil, err
}
defer resp.Body.Close()
if err := decodeBody(resp, &reply); err != nil {
return nil, err
}
return &reply, nil
} }