mirror of
https://github.com/minio/minio.git
synced 2024-12-23 21:55:53 -05:00
Fix peers and web UIVersion validation. (#3048)
This commit is contained in:
parent
8839c5105a
commit
5782ec3ada
2
.github/ISSUE_TEMPLATE.md
vendored
2
.github/ISSUE_TEMPLATE.md
vendored
@ -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
|
||||
<!--- If you're describing a bug, tell us what should happen -->
|
||||
|
@ -45,17 +45,13 @@ func initGlobalS3Peers(eps []storageEndPoint) {
|
||||
rpcClients: make(map[string]*AuthRPCClient),
|
||||
mutex: &sync.RWMutex{},
|
||||
}
|
||||
|
||||
// Initialize each peer connection.
|
||||
for _, peer := range peers {
|
||||
globalS3Peers.InitS3PeerClient(peer)
|
||||
}
|
||||
|
||||
// Additionally setup a local peer if one does not exist.
|
||||
if globalS3Peers.GetPeerClient(globalMinioAddr) == nil {
|
||||
globalS3Peers.InitS3PeerClient(globalMinioAddr)
|
||||
peers = append(peers, globalMinioAddr)
|
||||
}
|
||||
|
||||
// Save new peers
|
||||
globalS3Peers.peers = peers
|
||||
}
|
||||
|
||||
@ -108,14 +104,19 @@ func (s3p *s3Peers) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// returns the network addresses of all Minio servers in the cluster
|
||||
// in `host:port` format.
|
||||
func getAllPeers(eps []storageEndPoint) []string {
|
||||
res := []string{}
|
||||
for _, ep := range eps {
|
||||
res = append(res, fmt.Sprintf("%s:%d", ep.host, ep.port))
|
||||
// Returns the network addresses of all Minio servers in the cluster in `host:port` format.
|
||||
func getAllPeers(eps []storageEndPoint) (peers []string) {
|
||||
if eps == nil {
|
||||
return nil
|
||||
}
|
||||
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
|
||||
|
46
cmd/s3-peer-client_test.go
Normal file
46
cmd/s3-peer-client_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
@ -125,12 +125,12 @@ func (web *webAPIHandlers) StorageInfo(r *http.Request, args *GenericArgs, reply
|
||||
if !isJWTReqAuthenticated(r) {
|
||||
return &json2.Error{Message: "Unauthorized request"}
|
||||
}
|
||||
reply.UIVersion = miniobrowser.UIVersion
|
||||
objectAPI := web.ObjectAPI()
|
||||
if objectAPI == nil {
|
||||
return &json2.Error{Message: "Server not initialized"}
|
||||
}
|
||||
reply.StorageInfo = objectAPI.StorageInfo()
|
||||
reply.UIVersion = miniobrowser.UIVersion
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -144,7 +144,6 @@ func (web *webAPIHandlers) MakeBucket(r *http.Request, args *MakeBucketArgs, rep
|
||||
if !isJWTReqAuthenticated(r) {
|
||||
return &json2.Error{Message: "Unauthorized request"}
|
||||
}
|
||||
reply.UIVersion = miniobrowser.UIVersion
|
||||
objectAPI := web.ObjectAPI()
|
||||
if objectAPI == nil {
|
||||
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 {
|
||||
return &json2.Error{Message: err.Error()}
|
||||
}
|
||||
reply.UIVersion = miniobrowser.UIVersion
|
||||
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 {
|
||||
return &json2.Error{Message: err.Error()}
|
||||
}
|
||||
reply.UIVersion = miniobrowser.UIVersion
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -653,7 +654,6 @@ func (web *webAPIHandlers) ListAllBucketPolicies(r *http.Request, args *ListAllB
|
||||
}
|
||||
|
||||
reply.UIVersion = miniobrowser.UIVersion
|
||||
reply.Policies = []bucketAccessPolicy{}
|
||||
for prefix, policy := range policy.GetPolicies(policyInfo.Statements, args.BucketName) {
|
||||
reply.Policies = append(reply.Policies, bucketAccessPolicy{
|
||||
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 {
|
||||
return &json2.Error{Message: err.Error()}
|
||||
}
|
||||
reply.UIVersion = miniobrowser.UIVersion
|
||||
return nil
|
||||
}
|
||||
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 {
|
||||
return &json2.Error{Message: err.Error()}
|
||||
}
|
||||
|
||||
reply.UIVersion = miniobrowser.UIVersion
|
||||
return nil
|
||||
}
|
||||
@ -738,6 +738,7 @@ type PresignedGetArgs struct {
|
||||
|
||||
// PresignedGetRep - presigned-get URL reply.
|
||||
type PresignedGetRep struct {
|
||||
UIVersion string `json:"uiVersion"`
|
||||
// Presigned URL of the object.
|
||||
URL string `json:"url"`
|
||||
}
|
||||
@ -750,6 +751,7 @@ func (web *webAPIHandlers) PresignedGet(r *http.Request, args *PresignedGetArgs,
|
||||
if args.BucketName == "" || args.ObjectName == "" {
|
||||
return &json2.Error{Message: "Required arguments: Host, Bucket, Object"}
|
||||
}
|
||||
reply.UIVersion = miniobrowser.UIVersion
|
||||
reply.URL = presignedGet(args.HostName, args.BucketName, args.ObjectName)
|
||||
return nil
|
||||
}
|
||||
|
@ -801,6 +801,31 @@ func testWebPresignedGetHandler(obj ObjectLayer, instanceType string, t TestErrH
|
||||
if !bytes.Equal(data, savedData) {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user