Make BucketPolicy strictly typed

master
Harshavardhana 10 years ago
parent 7b57797455
commit 01e98eb326
  1. 3
      pkg/api/minioapi/policy_handlers.go
  2. 23
      pkg/storage/fs/fs.go
  3. 7
      pkg/storage/inmemory/inmemory.go
  4. 4
      pkg/storage/storage.go
  5. 2
      pkg/storage/storage_bucket_date.go
  6. 2
      pkg/storage/storage_bucket_policy.go

@ -23,7 +23,6 @@ import (
"github.com/gorilla/mux"
mstorage "github.com/minio-io/minio/pkg/storage"
"github.com/minio-io/minio/pkg/utils/policy"
)
// PUT Bucket policy
@ -35,7 +34,7 @@ func (server *minioAPI) putBucketPolicyHandler(w http.ResponseWriter, req *http.
bucket := vars["bucket"]
acceptsContentType := getContentType(req)
policy, ok := policy.Parsepolicy(req.Body)
policy, ok := mstorage.Parsepolicy(req.Body)
if ok == false {
error := errorCodeError(InvalidPolicyDocument)
errorResponse := getErrorResponse(error, bucket)

@ -33,7 +33,6 @@ import (
"sync"
mstorage "github.com/minio-io/minio/pkg/storage"
"github.com/minio-io/minio/pkg/utils/policy"
)
// Storage - fs local variables
@ -130,44 +129,44 @@ func (storage *Storage) StoreBucket(bucket string) error {
}
// GetBucketPolicy - GET bucket policy
func (storage *Storage) GetBucketPolicy(bucket string) (interface{}, error) {
func (storage *Storage) GetBucketPolicy(bucket string) (mstorage.BucketPolicy, error) {
storage.lock.Lock()
defer storage.lock.Unlock()
var p policy.BucketPolicy
var p mstorage.BucketPolicy
// verify bucket path legal
if mstorage.IsValidBucket(bucket) == false {
return policy.BucketPolicy{}, mstorage.BucketNameInvalid{Bucket: bucket}
return mstorage.BucketPolicy{}, mstorage.BucketNameInvalid{Bucket: bucket}
}
// get bucket path
bucketDir := path.Join(storage.root, bucket)
// check if bucket exists
if _, err := os.Stat(bucketDir); err != nil {
return policy.BucketPolicy{}, mstorage.BucketNotFound{Bucket: bucket}
return mstorage.BucketPolicy{}, mstorage.BucketNotFound{Bucket: bucket}
}
// get policy path
bucketPolicy := path.Join(storage.root, bucket+"_policy.json")
bucketPolicy := path.Join(storage.root, bucket+"_mstoragejson")
filestat, err := os.Stat(bucketPolicy)
if os.IsNotExist(err) {
return policy.BucketPolicy{}, mstorage.BucketPolicyNotFound{Bucket: bucket}
return mstorage.BucketPolicy{}, mstorage.BucketPolicyNotFound{Bucket: bucket}
}
if filestat.IsDir() {
return policy.BucketPolicy{}, mstorage.BackendCorrupted{Path: bucketPolicy}
return mstorage.BucketPolicy{}, mstorage.BackendCorrupted{Path: bucketPolicy}
}
file, err := os.OpenFile(bucketPolicy, os.O_RDONLY, 0666)
defer file.Close()
if err != nil {
return policy.BucketPolicy{}, mstorage.EmbedError(bucket, "", err)
return mstorage.BucketPolicy{}, mstorage.EmbedError(bucket, "", err)
}
encoder := json.NewDecoder(file)
err = encoder.Decode(&p)
if err != nil {
return policy.BucketPolicy{}, mstorage.EmbedError(bucket, "", err)
return mstorage.BucketPolicy{}, mstorage.EmbedError(bucket, "", err)
}
return p, nil
@ -175,7 +174,7 @@ func (storage *Storage) GetBucketPolicy(bucket string) (interface{}, error) {
}
// StoreBucketPolicy - PUT bucket policy
func (storage *Storage) StoreBucketPolicy(bucket string, policy interface{}) error {
func (storage *Storage) StoreBucketPolicy(bucket string, p mstorage.BucketPolicy) error {
storage.lock.Lock()
defer storage.lock.Unlock()
@ -208,7 +207,7 @@ func (storage *Storage) StoreBucketPolicy(bucket string, policy interface{}) err
return mstorage.EmbedError(bucket, "", err)
}
encoder := json.NewEncoder(file)
err = encoder.Encode(policy)
err = encoder.Encode(p)
if err != nil {
return mstorage.EmbedError(bucket, "", err)
}

@ -28,7 +28,6 @@ import (
"time"
mstorage "github.com/minio-io/minio/pkg/storage"
"github.com/minio-io/minio/pkg/utils/policy"
)
// Storage - local variables
@ -78,13 +77,13 @@ func (storage *Storage) CopyObjectToWriter(w io.Writer, bucket string, object st
}
// StoreBucketPolicy - Not implemented
func (storage *Storage) StoreBucketPolicy(bucket string, policy interface{}) error {
func (storage *Storage) StoreBucketPolicy(bucket string, policy mstorage.BucketPolicy) error {
return mstorage.APINotImplemented{API: "PutBucketPolicy"}
}
// GetBucketPolicy - Not implemented
func (storage *Storage) GetBucketPolicy(bucket string) (interface{}, error) {
return policy.BucketPolicy{}, mstorage.APINotImplemented{API: "GetBucketPolicy"}
func (storage *Storage) GetBucketPolicy(bucket string) (mstorage.BucketPolicy, error) {
return mstorage.BucketPolicy{}, mstorage.APINotImplemented{API: "GetBucketPolicy"}
}
// StoreObject - PUT object to memory buffer

@ -28,8 +28,8 @@ type Storage interface {
// Bucket Operations
ListBuckets() ([]BucketMetadata, error)
StoreBucket(bucket string) error
StoreBucketPolicy(bucket string, policy interface{}) error
GetBucketPolicy(bucket string) (interface{}, error)
StoreBucketPolicy(bucket string, p BucketPolicy) error
GetBucketPolicy(bucket string) (BucketPolicy, error)
// Object Operations
CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error)

@ -1,4 +1,4 @@
package policy
package storage
import (
"fmt"

@ -1,4 +1,4 @@
package policy
package storage
import (
"encoding/json"
Loading…
Cancel
Save