From 2f62b1b7ba21e3eba3db1467dcfa43f33213d1b1 Mon Sep 17 00:00:00 2001 From: David Tippett Date: Thu, 7 Nov 2024 17:56:02 +0000 Subject: [PATCH 1/2] Adding a license cluster command --- es.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/es.go b/es.go index fc1da22..f796da6 100644 --- a/es.go +++ b/es.go @@ -1802,3 +1802,24 @@ func (c *Client) RemoveIndexILMPolicy(index string) error { return nil } + +// Function called LicenseCluster. This function takes a json document as a string which is the license to apply to the Elasticsearch cluster. +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 +} From 4c40fa7b413a1d85de0c0d12c0545d8b3145dc5c Mon Sep 17 00:00:00 2001 From: David Tippett Date: Wed, 20 Nov 2024 14:48:09 +0000 Subject: [PATCH 2/2] Adding unit tests and updating docstrings for functions. --- es.go | 2 +- es_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/es.go b/es.go index f796da6..48e0292 100644 --- a/es.go +++ b/es.go @@ -1803,7 +1803,7 @@ func (c *Client) RemoveIndexILMPolicy(index string) error { return nil } -// Function called LicenseCluster. This function takes a json document as a string which is the license to apply to the Elasticsearch cluster. +// 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 == "" { 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) + } +}