diff --git a/es.go b/es.go index fc1da22..48e0292 100644 --- a/es.go +++ b/es.go @@ -1802,3 +1802,24 @@ func (c *Client) RemoveIndexILMPolicy(index string) error { return nil } + +// LicenseCluster takes in the Elasticsearch license encoded as a string +func (c *Client) LicenseCluster(license string) error { + // If the license is empty, return an error + if license == "" { + return errors.New("license is required") + } + + // Build the request to apply the license to the cluster + agent := c.buildPutRequest("_license"). + Set("Content-Type", "application/json"). + Send(license) + + // Execute the request + _, err := handleErrWithBytes(agent) + if err != nil { + return err + } + + return nil +} diff --git a/es_test.go b/es_test.go index 7135453..e71b6be 100644 --- a/es_test.go +++ b/es_test.go @@ -2363,3 +2363,22 @@ func TestRemoveIndexILMPolicy(t *testing.T) { t.Fatalf("Unexpected error. expected nil, got %s", err) } } +func TestLicenseCluster(t *testing.T) { + body := `{"license":{"start_date_in_millis":2728303200000,"uid":"asdfasdf-e"}}` + + testSetup := &ServerSetup{ + Method: "PUT", + Path: "/_license", + Body: body, + } + + host, port, ts := setupTestServers(t, []*ServerSetup{testSetup}) + defer ts.Close() + client := NewClient(host, port) + + err := client.LicenseCluster(body) + + if err != nil { + t.Errorf("Unexpected error expected nil, got %s", err) + } +}