admin: Move SetCredentials from Service to Generic (#3805)

Setting credentials doesn't belong to service management API
anymore.
master
Anis Elleuch 8 years ago committed by Harshavardhana
parent 69777b654e
commit 461b2bbd37
  1. 42
      pkg/madmin/API.md
  2. 2
      pkg/madmin/examples/set-credentials.go
  3. 72
      pkg/madmin/generic-commands.go
  4. 49
      pkg/madmin/service-commands.go

@ -36,13 +36,13 @@ func main() {
```
| Service operations|LockInfo operations|Healing operations|Config operations|
|:---|:---|:---|:---|
|[`ServiceStatus`](#ServiceStatus)| [`ListLocks`](#ListLocks)| [`ListObjectsHeal`](#ListObjectsHeal)|[`GetConfig`](#GetConfig)|
|[`ServiceRestart`](#ServiceRestart)| [`ClearLocks`](#ClearLocks)| [`ListBucketsHeal`](#ListBucketsHeal)||
| | |[`HealBucket`](#HealBucket) ||
| | |[`HealObject`](#HealObject)||
| | |[`HealFormat`](#HealFormat)||
| Service operations|LockInfo operations|Healing operations|Config operations| Misc |
|:---|:---|:---|:---|:---|
|[`ServiceStatus`](#ServiceStatus)| [`ListLocks`](#ListLocks)| [`ListObjectsHeal`](#ListObjectsHeal)|[`GetConfig`](#GetConfig)| [`SetCredentials`](#SetCredentials)|
|[`ServiceRestart`](#ServiceRestart)| [`ClearLocks`](#ClearLocks)| [`ListBucketsHeal`](#ListBucketsHeal)|||
| | |[`HealBucket`](#HealBucket) |||
| | |[`HealObject`](#HealObject)|||
| | |[`HealFormat`](#HealFormat)|||
## 1. Constructor
<a name="Minio"></a>
@ -119,6 +119,9 @@ If successful restarts the running minio service, for distributed setup restarts
log.Printf("Success")
```
## 3. Lock operations
<a name="ListLocks"></a>
### ListLocks(bucket, prefix string, duration time.Duration) ([]VolumeLockInfo, error)
If successful returns information on the list of locks held on ``bucket`` matching ``prefix`` for longer than ``duration`` seconds.
@ -149,6 +152,8 @@ __Example__
```
## 4. Heal operations
<a name="ListObjectsHeal"></a>
### ListObjectsHeal(bucket, prefix string, recursive bool, doneCh <-chan struct{}) (<-chan ObjectInfo, error)
If successful returns information on the list of objects that need healing in ``bucket`` matching ``prefix``.
@ -272,6 +277,9 @@ __Example__
log.Println("successfully healed storage format on available disks.")
```
## 5. Config operations
<a name="GetConfig"></a>
### GetConfig() ([]byte, error)
Get config.json of a minio setup.
@ -293,3 +301,23 @@ __Example__
log.Println("config received successfully: ", string(buf.Bytes()))
```
## 6. Misc operations
<a name="SetCredentials"></a>
### SetCredentials() error
Set new credentials of a Minio setup.
__Example__
``` go
err = madmClnt.SetCredentials("YOUR-NEW-ACCESSKEY", "YOUR-NEW-SECRETKEY")
if err != nil {
log.Fatalln(err)
}
log.Println("New credentials successfully set.")
```

@ -36,7 +36,7 @@ func main() {
log.Fatalln(err)
}
err = madmClnt.ServiceSetCredentials("YOUR-NEW-ACCESSKEY", "YOUR-NEW-SECRETKEY")
err = madmClnt.SetCredentials("YOUR-NEW-ACCESSKEY", "YOUR-NEW-SECRETKEY")
if err != nil {
log.Fatalln(err)
}

@ -0,0 +1,72 @@
/*
* 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 (
"bytes"
"encoding/xml"
"errors"
"net/http"
"net/url"
)
// setCredsReq - xml to send to the server to set new credentials
type setCredsReq struct {
Username string `xml:"username"`
Password string `xml:"password"`
}
// SetCredentials - Call Set Credentials API to set new access and secret keys in the specified Minio server
func (adm *AdminClient) SetCredentials(access, secret string) error {
// Disallow sending with the server if the connection is not secure
if !adm.secure {
return errors.New("setting new credentials requires HTTPS connection to the server")
}
// Setup new request
reqData := requestData{}
reqData.queryValues = make(url.Values)
reqData.queryValues.Set("service", "")
reqData.customHeaders = make(http.Header)
reqData.customHeaders.Set(minioAdminOpHeader, "set-credentials")
// Setup request's body
body, err := xml.Marshal(setCredsReq{Username: access, Password: secret})
if err != nil {
return err
}
reqData.contentBody = bytes.NewReader(body)
reqData.contentLength = int64(len(body))
reqData.contentMD5Bytes = sumMD5(body)
reqData.contentSHA256Bytes = sum256(body)
// Execute GET on bucket to list objects.
resp, err := adm.executeMethod("POST", reqData)
defer closeResponse(resp)
if err != nil {
return err
}
// Return error to the caller if http response code is different from 200
if resp.StatusCode != http.StatusOK {
return httpRespToErrorResponse(resp)
}
return nil
}

@ -18,10 +18,7 @@
package madmin
import (
"bytes"
"encoding/json"
"encoding/xml"
"errors"
"io/ioutil"
"net/http"
"net/url"
@ -94,49 +91,3 @@ func (adm *AdminClient) ServiceRestart() error {
}
return nil
}
// setCredsReq - xml to send to the server to set new credentials
type setCredsReq struct {
Username string `xml:"username"`
Password string `xml:"password"`
}
// ServiceSetCredentials - Call Service Set Credentials API to set new access and secret keys in the specified Minio server
func (adm *AdminClient) ServiceSetCredentials(access, secret string) error {
// Disallow sending with the server if the connection is not secure
if !adm.secure {
return errors.New("setting new credentials requires HTTPS connection to the server")
}
// Setup new request
reqData := requestData{}
reqData.queryValues = make(url.Values)
reqData.queryValues.Set("service", "")
reqData.customHeaders = make(http.Header)
reqData.customHeaders.Set(minioAdminOpHeader, "set-credentials")
// Setup request's body
body, err := xml.Marshal(setCredsReq{Username: access, Password: secret})
if err != nil {
return err
}
reqData.contentBody = bytes.NewReader(body)
reqData.contentLength = int64(len(body))
reqData.contentMD5Bytes = sumMD5(body)
reqData.contentSHA256Bytes = sum256(body)
// Execute GET on bucket to list objects.
resp, err := adm.executeMethod("POST", reqData)
defer closeResponse(resp)
if err != nil {
return err
}
// Return error to the caller if http response code is different from 200
if resp.StatusCode != http.StatusOK {
return httpRespToErrorResponse(resp)
}
return nil
}

Loading…
Cancel
Save