Check key length before adding a new user. (#6790)

User's key should satisfy the requirement of `mc config host add`.
Check access key and secret key length before adding a new user,
avoid creating a useless user which cannot be added into config
host or log into the browser.
This commit is contained in:
Chester Li
2018-11-10 07:48:24 +08:00
committed by kannappanr
parent df2d75a2a3
commit aa2d8583ad
3 changed files with 16 additions and 5 deletions

View File

@@ -21,6 +21,8 @@ import (
"encoding/json"
"net/http"
"net/url"
"github.com/minio/minio/pkg/auth"
)
// AccountStatus - account status.
@@ -97,6 +99,15 @@ func (adm *AdminClient) ListUsers() (map[string]UserInfo, error) {
// SetUser - sets a user info.
func (adm *AdminClient) SetUser(accessKey, secretKey string, status AccountStatus) error {
if !auth.IsAccessKeyValid(accessKey) {
return auth.ErrInvalidAccessKeyLength
}
if !auth.IsSecretKeyValid(secretKey) {
return auth.ErrInvalidSecretKeyLength
}
data, err := json.Marshal(UserInfo{
SecretKey: secretKey,
Status: status,