This repository was archived by the owner on Apr 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1802,3 +1802,24 @@ func (c *Client) RemoveIndexILMPolicy(index string) error {
18021802
18031803 return nil
18041804}
1805+
1806+ // LicenseCluster takes in the Elasticsearch license encoded as a string
1807+ func (c * Client ) LicenseCluster (license string ) error {
1808+ // If the license is empty, return an error
1809+ if license == "" {
1810+ return errors .New ("license is required" )
1811+ }
1812+
1813+ // Build the request to apply the license to the cluster
1814+ agent := c .buildPutRequest ("_license" ).
1815+ Set ("Content-Type" , "application/json" ).
1816+ Send (license )
1817+
1818+ // Execute the request
1819+ _ , err := handleErrWithBytes (agent )
1820+ if err != nil {
1821+ return err
1822+ }
1823+
1824+ return nil
1825+ }
Original file line number Diff line number Diff line change @@ -2363,3 +2363,22 @@ func TestRemoveIndexILMPolicy(t *testing.T) {
23632363 t .Fatalf ("Unexpected error. expected nil, got %s" , err )
23642364 }
23652365}
2366+ func TestLicenseCluster (t * testing.T ) {
2367+ body := `{"license":{"start_date_in_millis":2728303200000,"uid":"asdfasdf-e"}}`
2368+
2369+ testSetup := & ServerSetup {
2370+ Method : "PUT" ,
2371+ Path : "/_license" ,
2372+ Body : body ,
2373+ }
2374+
2375+ host , port , ts := setupTestServers (t , []* ServerSetup {testSetup })
2376+ defer ts .Close ()
2377+ client := NewClient (host , port )
2378+
2379+ err := client .LicenseCluster (body )
2380+
2381+ if err != nil {
2382+ t .Errorf ("Unexpected error expected nil, got %s" , err )
2383+ }
2384+ }
You can’t perform that action at this time.
0 commit comments