Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions es.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
19 changes: 19 additions & 0 deletions es_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}