storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/madmin/update-commands.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2019 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   */
    17  
    18  package madmin
    19  
    20  import (
    21  	"context"
    22  	"encoding/json"
    23  	"net/http"
    24  	"net/url"
    25  )
    26  
    27  // ServerUpdateStatus - contains the response of service update API
    28  type ServerUpdateStatus struct {
    29  	CurrentVersion string `json:"currentVersion"`
    30  	UpdatedVersion string `json:"updatedVersion"`
    31  }
    32  
    33  // ServerUpdate - updates and restarts the MinIO cluster to latest version.
    34  // optionally takes an input URL to specify a custom update binary link
    35  func (adm *AdminClient) ServerUpdate(ctx context.Context, updateURL string) (us ServerUpdateStatus, err error) {
    36  	queryValues := url.Values{}
    37  	queryValues.Set("updateURL", updateURL)
    38  
    39  	// Request API to Restart server
    40  	resp, err := adm.executeMethod(ctx,
    41  		http.MethodPost, requestData{
    42  			relPath:     adminAPIPrefix + "/update",
    43  			queryValues: queryValues,
    44  		},
    45  	)
    46  	defer closeResponse(resp)
    47  	if err != nil {
    48  		return us, err
    49  	}
    50  
    51  	if resp.StatusCode != http.StatusOK {
    52  		return us, httpRespToErrorResponse(resp)
    53  	}
    54  
    55  	if err = json.NewDecoder(resp.Body).Decode(&us); err != nil {
    56  		return us, err
    57  	}
    58  
    59  	return us, nil
    60  }