Skip to content

Commit

Permalink
Merge pull request #116 from github/dtaivpp/license-cluster
Browse files Browse the repository at this point in the history
Adding a license cluster command
  • Loading branch information
dtaivpp authored Nov 20, 2024
2 parents 3dce9a2 + 4c40fa7 commit 9c7fa78
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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)
}
}

0 comments on commit 9c7fa78

Please sign in to comment.