Fix peers and web UIVersion validation. (#3048)

This commit is contained in:
Harshavardhana 2016-10-23 12:32:35 -07:00 committed by GitHub
parent 8839c5105a
commit 5782ec3ada
5 changed files with 92 additions and 18 deletions

View File

@ -1,4 +1,4 @@
!--- Provide a general summary of the issue in the Title above --> <!--- Provide a general summary of the issue in the Title above -->
## Expected Behavior ## Expected Behavior
<!--- If you're describing a bug, tell us what should happen --> <!--- If you're describing a bug, tell us what should happen -->

View File

@ -45,17 +45,13 @@ func initGlobalS3Peers(eps []storageEndPoint) {
rpcClients: make(map[string]*AuthRPCClient), rpcClients: make(map[string]*AuthRPCClient),
mutex: &sync.RWMutex{}, mutex: &sync.RWMutex{},
} }
// Initialize each peer connection. // Initialize each peer connection.
for _, peer := range peers { for _, peer := range peers {
globalS3Peers.InitS3PeerClient(peer) globalS3Peers.InitS3PeerClient(peer)
} }
// Additionally setup a local peer if one does not exist. // Save new peers
if globalS3Peers.GetPeerClient(globalMinioAddr) == nil {
globalS3Peers.InitS3PeerClient(globalMinioAddr)
peers = append(peers, globalMinioAddr)
}
globalS3Peers.peers = peers globalS3Peers.peers = peers
} }
@ -108,14 +104,19 @@ func (s3p *s3Peers) Close() error {
return nil return nil
} }
// returns the network addresses of all Minio servers in the cluster // Returns the network addresses of all Minio servers in the cluster in `host:port` format.
// in `host:port` format. func getAllPeers(eps []storageEndPoint) (peers []string) {
func getAllPeers(eps []storageEndPoint) []string { if eps == nil {
res := []string{} return nil
for _, ep := range eps {
res = append(res, fmt.Sprintf("%s:%d", ep.host, ep.port))
} }
return res peers = []string{globalMinioAddr} // Starts with a default peer.
for _, ep := range eps {
// Rest of the peers configured.
if ep.host != "" {
peers = append(peers, fmt.Sprintf("%s:%d", ep.host, ep.port))
}
}
return peers
} }
// Make RPC calls with the given method and arguments to all the given // Make RPC calls with the given method and arguments to all the given

View File

@ -0,0 +1,46 @@
/*
* Minio Cloud Storage, (C) 2016 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 cmd
import (
"reflect"
"testing"
)
// Validates getAllPeers, fetches all peers based on list of storage endpoints.
func TestGetAllPeers(t *testing.T) {
testCases := []struct {
eps []storageEndPoint
peers []string
}{
{nil, nil},
{[]storageEndPoint{{path: "/mnt/disk1"}}, []string{globalMinioAddr}},
{[]storageEndPoint{{
host: "localhost",
port: 9001,
}}, []string{
globalMinioAddr, "localhost:9001",
}},
}
for i, testCase := range testCases {
peers := getAllPeers(testCase.eps)
if !reflect.DeepEqual(testCase.peers, peers) {
t.Errorf("Test %d: Expected %s, got %s", i+1, testCase.peers, peers)
}
}
}

View File

@ -125,12 +125,12 @@ func (web *webAPIHandlers) StorageInfo(r *http.Request, args *GenericArgs, reply
if !isJWTReqAuthenticated(r) { if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"} return &json2.Error{Message: "Unauthorized request"}
} }
reply.UIVersion = miniobrowser.UIVersion
objectAPI := web.ObjectAPI() objectAPI := web.ObjectAPI()
if objectAPI == nil { if objectAPI == nil {
return &json2.Error{Message: "Server not initialized"} return &json2.Error{Message: "Server not initialized"}
} }
reply.StorageInfo = objectAPI.StorageInfo() reply.StorageInfo = objectAPI.StorageInfo()
reply.UIVersion = miniobrowser.UIVersion
return nil return nil
} }
@ -144,7 +144,6 @@ func (web *webAPIHandlers) MakeBucket(r *http.Request, args *MakeBucketArgs, rep
if !isJWTReqAuthenticated(r) { if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"} return &json2.Error{Message: "Unauthorized request"}
} }
reply.UIVersion = miniobrowser.UIVersion
objectAPI := web.ObjectAPI() objectAPI := web.ObjectAPI()
if objectAPI == nil { if objectAPI == nil {
return &json2.Error{Message: "Server not initialized"} return &json2.Error{Message: "Server not initialized"}
@ -152,6 +151,7 @@ func (web *webAPIHandlers) MakeBucket(r *http.Request, args *MakeBucketArgs, rep
if err := objectAPI.MakeBucket(args.BucketName); err != nil { if err := objectAPI.MakeBucket(args.BucketName); err != nil {
return &json2.Error{Message: err.Error()} return &json2.Error{Message: err.Error()}
} }
reply.UIVersion = miniobrowser.UIVersion
return nil return nil
} }
@ -275,6 +275,7 @@ func (web *webAPIHandlers) RemoveObject(r *http.Request, args *RemoveObjectArgs,
if err := objectAPI.DeleteObject(args.BucketName, args.ObjectName); err != nil { if err := objectAPI.DeleteObject(args.BucketName, args.ObjectName); err != nil {
return &json2.Error{Message: err.Error()} return &json2.Error{Message: err.Error()}
} }
reply.UIVersion = miniobrowser.UIVersion
return nil return nil
} }
@ -653,7 +654,6 @@ func (web *webAPIHandlers) ListAllBucketPolicies(r *http.Request, args *ListAllB
} }
reply.UIVersion = miniobrowser.UIVersion reply.UIVersion = miniobrowser.UIVersion
reply.Policies = []bucketAccessPolicy{}
for prefix, policy := range policy.GetPolicies(policyInfo.Statements, args.BucketName) { for prefix, policy := range policy.GetPolicies(policyInfo.Statements, args.BucketName) {
reply.Policies = append(reply.Policies, bucketAccessPolicy{ reply.Policies = append(reply.Policies, bucketAccessPolicy{
Prefix: prefix, Prefix: prefix,
@ -694,6 +694,7 @@ func (web *webAPIHandlers) SetBucketPolicy(r *http.Request, args *SetBucketPolic
if err = persistAndNotifyBucketPolicyChange(args.BucketName, policyChange{true, nil}, objectAPI); err != nil { if err = persistAndNotifyBucketPolicyChange(args.BucketName, policyChange{true, nil}, objectAPI); err != nil {
return &json2.Error{Message: err.Error()} return &json2.Error{Message: err.Error()}
} }
reply.UIVersion = miniobrowser.UIVersion
return nil return nil
} }
data, err := json.Marshal(policyInfo) data, err := json.Marshal(policyInfo)
@ -719,7 +720,6 @@ func (web *webAPIHandlers) SetBucketPolicy(r *http.Request, args *SetBucketPolic
if err := persistAndNotifyBucketPolicyChange(args.BucketName, policyChange{false, policy}, objectAPI); err != nil { if err := persistAndNotifyBucketPolicyChange(args.BucketName, policyChange{false, policy}, objectAPI); err != nil {
return &json2.Error{Message: err.Error()} return &json2.Error{Message: err.Error()}
} }
reply.UIVersion = miniobrowser.UIVersion reply.UIVersion = miniobrowser.UIVersion
return nil return nil
} }
@ -738,6 +738,7 @@ type PresignedGetArgs struct {
// PresignedGetRep - presigned-get URL reply. // PresignedGetRep - presigned-get URL reply.
type PresignedGetRep struct { type PresignedGetRep struct {
UIVersion string `json:"uiVersion"`
// Presigned URL of the object. // Presigned URL of the object.
URL string `json:"url"` URL string `json:"url"`
} }
@ -750,6 +751,7 @@ func (web *webAPIHandlers) PresignedGet(r *http.Request, args *PresignedGetArgs,
if args.BucketName == "" || args.ObjectName == "" { if args.BucketName == "" || args.ObjectName == "" {
return &json2.Error{Message: "Required arguments: Host, Bucket, Object"} return &json2.Error{Message: "Required arguments: Host, Bucket, Object"}
} }
reply.UIVersion = miniobrowser.UIVersion
reply.URL = presignedGet(args.HostName, args.BucketName, args.ObjectName) reply.URL = presignedGet(args.HostName, args.BucketName, args.ObjectName)
return nil return nil
} }

View File

@ -801,6 +801,31 @@ func testWebPresignedGetHandler(obj ObjectLayer, instanceType string, t TestErrH
if !bytes.Equal(data, savedData) { if !bytes.Equal(data, savedData) {
t.Fatal("Read data is not equal was what was expected") t.Fatal("Read data is not equal was what was expected")
} }
// Register the API end points with XL/FS object layer.
apiRouter = initTestWebRPCEndPoint(obj)
presignGetReq = PresignedGetArgs{
HostName: "",
BucketName: "",
ObjectName: "",
}
presignGetRep = &PresignedGetRep{}
req, err = newTestWebRPCRequest("Web.PresignedGet", authorization, presignGetReq)
if err != nil {
t.Fatalf("Failed to create HTTP request: <ERROR> %v", err)
}
apiRouter.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("Expected the response status to be 200, but instead found `%d`", rec.Code)
}
err = getTestWebRPCResponse(rec, &presignGetRep)
if err == nil {
t.Fatalf("Failed, %v", err)
}
if err.Error() != "Required arguments: Host, Bucket, Object" {
t.Fatalf("Unexpected, expected `Required arguments: Host, Bucket, Object`, got %s", err)
}
} }
// Wrapper for calling GetBucketPolicy Handler // Wrapper for calling GetBucketPolicy Handler