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

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

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

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

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

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