2017-02-25 14:06:08 -05:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
package madmin
|
|
|
|
|
|
|
|
import (
|
2018-01-22 17:54:55 -05:00
|
|
|
"encoding/json"
|
2017-02-25 14:06:08 -05:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// SetCredsReq - xml to send to the server to set new credentials
|
|
|
|
type SetCredsReq struct {
|
|
|
|
AccessKey string `json:"accessKey"`
|
|
|
|
SecretKey string `json:"secretKey"`
|
2017-02-25 14:06:08 -05:00
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
// SetAdminCredentials - Call Set Credentials API to set new access and
|
2018-01-22 17:54:55 -05:00
|
|
|
// secret keys in the specified Minio server
|
2018-10-09 17:00:01 -04:00
|
|
|
func (adm *AdminClient) SetAdminCredentials(access, secret string) error {
|
2017-02-25 14:06:08 -05:00
|
|
|
// Setup request's body
|
2018-01-22 17:54:55 -05:00
|
|
|
body, err := json.Marshal(SetCredsReq{access, secret})
|
2017-02-25 14:06:08 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-22 17:54:55 -05:00
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
ebody, err := EncryptData(adm.secretAccessKey, body)
|
2018-08-17 21:51:34 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup new request
|
|
|
|
reqData := requestData{
|
2018-05-30 17:49:03 -04:00
|
|
|
relPath: "/v1/config/credential",
|
2018-08-17 21:51:34 -04:00
|
|
|
content: ebody,
|
2018-01-22 17:54:55 -05:00
|
|
|
}
|
2017-02-25 14:06:08 -05:00
|
|
|
|
|
|
|
// Execute GET on bucket to list objects.
|
2018-01-22 17:54:55 -05:00
|
|
|
resp, err := adm.executeMethod("PUT", reqData)
|
2017-02-25 14:06:08 -05:00
|
|
|
|
|
|
|
defer closeResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// Return error to the caller if http response code is
|
|
|
|
// different from 200
|
2017-02-25 14:06:08 -05:00
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
return httpRespToErrorResponse(resp)
|
|
|
|
}
|
2018-08-17 21:51:34 -04:00
|
|
|
|
2017-02-25 14:06:08 -05:00
|
|
|
return nil
|
|
|
|
}
|