Revert "Change ACL to Access"
This reverts commit68b3b0aac2. Revert "Object ACL now propagates through ACL config, update minio-go library to bing in SetObjectACL() support" This reverts commit6816542c7a.
This commit is contained in:
+6
-5
@@ -65,7 +65,7 @@ EXAMPLES:
|
||||
type AccessMessage struct {
|
||||
Status string `json:"status"`
|
||||
Bucket string `json:"bucket"`
|
||||
Perms accessPerms `json:"permission"`
|
||||
Perms bucketPerms `json:"permission"`
|
||||
}
|
||||
|
||||
func (s AccessMessage) String() string {
|
||||
@@ -85,8 +85,8 @@ func checkAccessSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
|
||||
}
|
||||
perms := accessPerms(ctx.Args().First())
|
||||
if !perms.isValidAccessPERM() {
|
||||
perms := bucketPerms(ctx.Args().First())
|
||||
if !perms.isValidBucketPERM() {
|
||||
fatalIf(errDummy().Trace(),
|
||||
"Unrecognized permission ‘"+perms.String()+"’. Allowed values are [private, public, readonly].")
|
||||
}
|
||||
@@ -104,7 +104,8 @@ func mainAccess(ctx *cli.Context) {
|
||||
"Access": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
|
||||
perms := accessPerms(ctx.Args().First())
|
||||
perms := bucketPerms(ctx.Args().First())
|
||||
|
||||
config := mustGetMcConfig()
|
||||
for _, arg := range ctx.Args().Tail() {
|
||||
targetURL, err := getCanonicalizedURL(arg, config.Aliases)
|
||||
@@ -120,7 +121,7 @@ func mainAccess(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func doUpdateAccessCmd(targetURL string, targetPERMS accessPerms) *probe.Error {
|
||||
func doUpdateAccessCmd(targetURL string, targetPERMS bucketPerms) *probe.Error {
|
||||
var clnt client.Client
|
||||
clnt, err := target2Client(targetURL)
|
||||
if err != nil {
|
||||
|
||||
+19
-30
@@ -16,10 +16,8 @@
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/minio/minio/pkg/probe"
|
||||
|
||||
// isValidAccessPERM - is provided acl string supported
|
||||
func (b accessPerms) isValidAccessPERM() bool {
|
||||
// isValidBucketPERM - is provided acl string supported
|
||||
func (b bucketPerms) isValidBucketPERM() bool {
|
||||
switch true {
|
||||
case b.isPrivate():
|
||||
fallthrough
|
||||
@@ -34,19 +32,19 @@ func (b accessPerms) isValidAccessPERM() bool {
|
||||
}
|
||||
}
|
||||
|
||||
// accessPerms - access level access control
|
||||
type accessPerms string
|
||||
// bucketPerms - bucket level access control
|
||||
type bucketPerms string
|
||||
|
||||
// different types of ACL's currently supported for accesss
|
||||
// different types of ACL's currently supported for buckets
|
||||
const (
|
||||
accessPrivate = accessPerms("private")
|
||||
accessReadOnly = accessPerms("readonly")
|
||||
accessPublic = accessPerms("public")
|
||||
accessAuthenticated = accessPerms("authenticated")
|
||||
bucketPrivate = bucketPerms("private")
|
||||
bucketReadOnly = bucketPerms("readonly")
|
||||
bucketPublic = bucketPerms("public")
|
||||
bucketAuthenticated = bucketPerms("authenticated")
|
||||
)
|
||||
|
||||
func (b accessPerms) String() string {
|
||||
if !b.isValidAccessPERM() {
|
||||
func (b bucketPerms) String() string {
|
||||
if !b.isValidBucketPERM() {
|
||||
return string(b)
|
||||
}
|
||||
if b.isReadOnly() {
|
||||
@@ -62,30 +60,21 @@ func (b accessPerms) String() string {
|
||||
}
|
||||
|
||||
// IsPrivate - is acl Private
|
||||
func (b accessPerms) isPrivate() bool {
|
||||
return b == accessPrivate
|
||||
func (b bucketPerms) isPrivate() bool {
|
||||
return b == bucketPrivate
|
||||
}
|
||||
|
||||
// IsPublicRead - is acl PublicRead
|
||||
func (b accessPerms) isReadOnly() bool {
|
||||
return b == accessReadOnly
|
||||
func (b bucketPerms) isReadOnly() bool {
|
||||
return b == bucketReadOnly
|
||||
}
|
||||
|
||||
// IsPublicReadWrite - is acl PublicReadWrite
|
||||
func (b accessPerms) isPublic() bool {
|
||||
return b == accessPublic
|
||||
func (b bucketPerms) isPublic() bool {
|
||||
return b == bucketPublic
|
||||
}
|
||||
|
||||
// IsAuthenticated - is acl AuthenticatedRead
|
||||
func (b accessPerms) isAuthenticated() bool {
|
||||
return b == accessAuthenticated
|
||||
}
|
||||
|
||||
// getDefaultAccess - read ACL from config
|
||||
func getDefaultAccess() (acl string, err *probe.Error) {
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
return "", err.Trace()
|
||||
}
|
||||
return config.Access, nil
|
||||
func (b bucketPerms) isAuthenticated() bool {
|
||||
return b == bucketAuthenticated
|
||||
}
|
||||
+12
-13
@@ -108,13 +108,12 @@ func (s *CmdTestSuite) TestNewConfigV2(c *C) {
|
||||
perr = conf.Save(configFile)
|
||||
c.Assert(perr, IsNil)
|
||||
|
||||
confNew := newConfigV3()
|
||||
confNew := newConfigV2()
|
||||
config, perr := quick.New(confNew)
|
||||
c.Assert(perr, IsNil)
|
||||
perr = config.Load(configFile)
|
||||
c.Assert(perr, IsNil)
|
||||
data := config.Data().(*configV3)
|
||||
c.Assert(data.Access, Equals, "private")
|
||||
data := config.Data().(*configV2)
|
||||
|
||||
type aliases struct {
|
||||
name string
|
||||
@@ -184,23 +183,23 @@ func (s *CmdTestSuite) TestArgs2URL(c *C) {
|
||||
}
|
||||
|
||||
func (s *CmdTestSuite) TestValidPERMS(c *C) {
|
||||
perms := accessPerms("private")
|
||||
c.Assert(perms.isValidAccessPERM(), Equals, true)
|
||||
perms := bucketPerms("private")
|
||||
c.Assert(perms.isValidBucketPERM(), Equals, true)
|
||||
c.Assert(perms.String(), Equals, "private")
|
||||
perms = accessPerms("public")
|
||||
c.Assert(perms.isValidAccessPERM(), Equals, true)
|
||||
perms = bucketPerms("public")
|
||||
c.Assert(perms.isValidBucketPERM(), Equals, true)
|
||||
c.Assert(perms.String(), Equals, "public-read-write")
|
||||
perms = accessPerms("readonly")
|
||||
c.Assert(perms.isValidAccessPERM(), Equals, true)
|
||||
perms = bucketPerms("readonly")
|
||||
c.Assert(perms.isValidBucketPERM(), Equals, true)
|
||||
c.Assert(perms.String(), Equals, "public-read")
|
||||
perms = accessPerms("authenticated")
|
||||
c.Assert(perms.isValidAccessPERM(), Equals, true)
|
||||
perms = bucketPerms("authenticated")
|
||||
c.Assert(perms.isValidBucketPERM(), Equals, true)
|
||||
c.Assert(perms.String(), Equals, "authenticated-read")
|
||||
}
|
||||
|
||||
func (s *CmdTestSuite) TestInvalidPERMS(c *C) {
|
||||
perms := accessPerms("invalid")
|
||||
c.Assert(perms.isValidAccessPERM(), Equals, false)
|
||||
perms := bucketPerms("invalid")
|
||||
c.Assert(perms.isValidBucketPERM(), Equals, false)
|
||||
}
|
||||
|
||||
func (s *CmdTestSuite) TestGetMcConfigDir(c *C) {
|
||||
|
||||
@@ -157,11 +157,6 @@ func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error)
|
||||
s3Config.AppVersion = globalMCVersion
|
||||
s3Config.AppComments = []string{os.Args[0], runtime.GOOS, runtime.GOARCH}
|
||||
s3Config.HostURL = urlStr
|
||||
access, err := getDefaultAccess()
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
s3Config.ACL = accessPerms(access).String()
|
||||
s3Config.Debug = globalDebugFlag
|
||||
s3Client, err := s3.New(s3Config)
|
||||
if err != nil {
|
||||
|
||||
+6
-5
@@ -168,7 +168,7 @@ func listAliases() {
|
||||
fatalIf(err.Trace(configPath), "Unable to load config path")
|
||||
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV3)
|
||||
newConf := config.Data().(*configV2)
|
||||
for k, v := range newConf.Aliases {
|
||||
console.Println(AliasMessage{
|
||||
op: "list",
|
||||
@@ -183,7 +183,7 @@ func removeAlias(alias string) {
|
||||
if alias == "" {
|
||||
fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.")
|
||||
}
|
||||
conf := newConfigV3()
|
||||
conf := newConfigV2()
|
||||
config, err := quick.New(conf)
|
||||
fatalIf(err.Trace(conf.Version), "Failed to initialize ‘quick’ configuration data structure.")
|
||||
|
||||
@@ -196,7 +196,8 @@ func removeAlias(alias string) {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: mybucket, Area51, Grand-Nagus", alias))
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV3)
|
||||
newConf := config.Data().(*configV2)
|
||||
|
||||
if _, ok := newConf.Aliases[alias]; !ok {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ does not exist.", alias))
|
||||
}
|
||||
@@ -219,7 +220,7 @@ func addAlias(alias, url string) {
|
||||
if alias == "" || url == "" {
|
||||
fatalIf(errDummy().Trace(), "Alias or URL cannot be empty.")
|
||||
}
|
||||
conf := newConfigV3()
|
||||
conf := newConfigV2()
|
||||
config, err := quick.New(conf)
|
||||
fatalIf(err.Trace(conf.Version), "Failed to initialize ‘quick’ configuration data structure.")
|
||||
|
||||
@@ -237,7 +238,7 @@ func addAlias(alias, url string) {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias name ‘%s’ is invalid, valid examples are: mybucket, Area51, Grand-Nagus", alias))
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV3)
|
||||
newConf := config.Data().(*configV2)
|
||||
if oldURL, ok := newConf.Aliases[alias]; ok {
|
||||
fatalIf(errDummy().Trace(), fmt.Sprintf("Alias ‘%s’ already exists for ‘%s’.", alias, oldURL))
|
||||
}
|
||||
|
||||
@@ -34,13 +34,6 @@ type configV2 struct {
|
||||
Hosts map[string]hostConfig
|
||||
}
|
||||
|
||||
type configV3 struct {
|
||||
Version string
|
||||
Access string
|
||||
Aliases map[string]string
|
||||
Hosts map[string]hostConfig
|
||||
}
|
||||
|
||||
// for backward compatibility
|
||||
type configV101 configV2
|
||||
type configV1 configV2
|
||||
@@ -112,7 +105,7 @@ func mustGetMcConfigPath() string {
|
||||
}
|
||||
|
||||
// getMcConfig - reads configuration file and returns config
|
||||
func getMcConfig() (*configV3, *probe.Error) {
|
||||
func getMcConfig() (*configV2, *probe.Error) {
|
||||
if !isMcConfigExists() {
|
||||
return nil, errInvalidArgument().Trace()
|
||||
}
|
||||
@@ -124,10 +117,10 @@ func getMcConfig() (*configV3, *probe.Error) {
|
||||
|
||||
// Cached in private global variable.
|
||||
if v := cache.Get(); v != nil { // Use previously cached config.
|
||||
return v.(quick.Config).Data().(*configV3), nil
|
||||
return v.(quick.Config).Data().(*configV2), nil
|
||||
}
|
||||
|
||||
conf := newConfigV3()
|
||||
conf := newConfigV2()
|
||||
qconf, err := quick.New(conf)
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
@@ -138,12 +131,12 @@ func getMcConfig() (*configV3, *probe.Error) {
|
||||
return nil, err.Trace()
|
||||
}
|
||||
cache.Put(qconf)
|
||||
return qconf.Data().(*configV3), nil
|
||||
return qconf.Data().(*configV2), nil
|
||||
|
||||
}
|
||||
|
||||
// mustGetMcConfig - reads configuration file and returns configs, exits on error
|
||||
func mustGetMcConfig() *configV3 {
|
||||
func mustGetMcConfig() *configV2 {
|
||||
config, err := getMcConfig()
|
||||
fatalIf(err.Trace(), "Unable to get mcConfig.")
|
||||
|
||||
@@ -186,8 +179,6 @@ func migrateConfig() {
|
||||
migrateConfigV1ToV101()
|
||||
// Migrate config V101 to V2
|
||||
migrateConfigV101ToV2()
|
||||
// Migrate config V2 to V3
|
||||
migrateConfigV2ToV3()
|
||||
}
|
||||
|
||||
func migrateConfigV1ToV101() {
|
||||
@@ -252,31 +243,6 @@ func migrateConfigV101ToV2() {
|
||||
}
|
||||
}
|
||||
|
||||
func migrateConfigV2ToV3() {
|
||||
if !isMcConfigExists() {
|
||||
return
|
||||
}
|
||||
mcConfigV2, err := quick.Load(mustGetMcConfigPath(), newConfigV2())
|
||||
fatalIf(err.Trace(), "Unable to load config.")
|
||||
|
||||
// update to newer version
|
||||
if mcConfigV2.Version() == "2" {
|
||||
confV3 := new(configV3)
|
||||
confV3.Aliases = mcConfigV2.Data().(*configV2).Aliases
|
||||
confV3.Hosts = mcConfigV2.Data().(*configV2).Hosts
|
||||
confV3.Version = globalMCConfigVersion
|
||||
confV3.Access = "private"
|
||||
|
||||
mcNewConfigV3, err := quick.New(confV3)
|
||||
fatalIf(err.Trace(), "Unable to initialize quick config.")
|
||||
|
||||
err = mcNewConfigV3.Save(mustGetMcConfigPath())
|
||||
fatalIf(err.Trace(), "Unable to save config.")
|
||||
|
||||
console.Infof("Successfully migrated %s from version ‘2’ to version: ‘3’.\n", mustGetMcConfigPath())
|
||||
}
|
||||
}
|
||||
|
||||
// newConfigV1() - get new config version 1.0.0
|
||||
func newConfigV1() *configV1 {
|
||||
conf := new(configV1)
|
||||
@@ -296,6 +262,7 @@ func newConfigV101() *configV101 {
|
||||
// exits silently without providing any errors
|
||||
conf.Hosts = make(map[string]hostConfig)
|
||||
conf.Aliases = make(map[string]string)
|
||||
|
||||
return conf
|
||||
}
|
||||
|
||||
@@ -303,18 +270,6 @@ func newConfigV101() *configV101 {
|
||||
func newConfigV2() *configV2 {
|
||||
conf := new(configV2)
|
||||
conf.Version = globalMCConfigVersion
|
||||
// make sure to allocate map's otherwise Golang
|
||||
// exits silently without providing any errors
|
||||
conf.Hosts = make(map[string]hostConfig)
|
||||
conf.Aliases = make(map[string]string)
|
||||
return conf
|
||||
}
|
||||
|
||||
// newConfigV3 - get new config version 3
|
||||
func newConfigV3() *configV3 {
|
||||
conf := new(configV3)
|
||||
conf.Version = globalMCConfigVersion
|
||||
|
||||
// make sure to allocate map's otherwise Golang
|
||||
// exits silently without providing any errors
|
||||
conf.Hosts = make(map[string]hostConfig)
|
||||
@@ -355,14 +310,13 @@ func newConfigV3() *configV3 {
|
||||
aliases["dl"] = "https://dl.minio.io:9000"
|
||||
aliases["localhost"] = "http://localhost:9000"
|
||||
conf.Aliases = aliases
|
||||
conf.Access = "private"
|
||||
|
||||
return conf
|
||||
}
|
||||
|
||||
// newConfig - get new config interface
|
||||
func newConfig() (config quick.Config, err *probe.Error) {
|
||||
conf := newConfigV3()
|
||||
conf := newConfigV2()
|
||||
config, err = quick.New(conf)
|
||||
if err != nil {
|
||||
return nil, err.Trace()
|
||||
|
||||
@@ -38,6 +38,7 @@ package main
|
||||
|
||||
// Version autogenerated
|
||||
const Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}}
|
||||
|
||||
`
|
||||
t := template.Must(template.New("version").Parse(versionTemplate))
|
||||
versionFile, err := os.OpenFile("version.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ var (
|
||||
|
||||
// mc configuration related constants.
|
||||
const (
|
||||
globalMCConfigVersion = "3"
|
||||
globalMCConfigVersion = "2"
|
||||
globalMCVersion = Version
|
||||
|
||||
globalMCConfigDir = ".mc/"
|
||||
|
||||
@@ -38,7 +38,6 @@ type Client interface {
|
||||
Share(expires time.Duration) (string, *probe.Error)
|
||||
GetObject(offset, length int64) (body io.ReadCloser, size int64, err *probe.Error)
|
||||
PutObject(size int64, data io.Reader) *probe.Error
|
||||
SetObjectACL(acl string) *probe.Error
|
||||
|
||||
// URL returns back internal url
|
||||
URL() *URL
|
||||
|
||||
+3
-21
@@ -75,26 +75,8 @@ func (f *fsClient) fsStat() (os.FileInfo, *probe.Error) {
|
||||
return st, nil
|
||||
}
|
||||
|
||||
// SetObjectACL - set new acl
|
||||
func (f *fsClient) SetObjectACL(acl string) *probe.Error {
|
||||
if !isValidACL(acl) {
|
||||
return probe.NewError(client.InvalidACLType{ACL: acl})
|
||||
}
|
||||
_, err := os.Stat(f.path)
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
err = os.Chmod(f.path, aclToPerm(acl))
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// PutObject - create a new file
|
||||
func (f *fsClient) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
// for filesystem we will not support any ACL's in PutObject()
|
||||
objectDir, _ := filepath.Split(f.path)
|
||||
objectPath := f.path
|
||||
if objectDir != "" {
|
||||
@@ -367,8 +349,8 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel
|
||||
}
|
||||
}
|
||||
|
||||
// isValidACL - is acl a valid ACL?
|
||||
func isValidACL(acl string) bool {
|
||||
// isValidBucketACL - is acl a valid ACL?
|
||||
func isValidBucketACL(acl string) bool {
|
||||
switch acl {
|
||||
case "private":
|
||||
fallthrough
|
||||
@@ -412,7 +394,7 @@ func (f *fsClient) MakeBucket() *probe.Error {
|
||||
|
||||
// SetBucketACL - create a new bucket
|
||||
func (f *fsClient) SetBucketACL(acl string) *probe.Error {
|
||||
if !isValidACL(acl) {
|
||||
if !isValidBucketACL(acl) {
|
||||
return probe.NewError(client.InvalidACLType{ACL: acl})
|
||||
}
|
||||
err := os.MkdirAll(f.path, aclToPerm(acl))
|
||||
|
||||
+4
-21
@@ -39,9 +39,6 @@ type Config struct {
|
||||
AppComments []string
|
||||
Debug bool
|
||||
|
||||
// Used for Bucket/Object ACL
|
||||
ACL string
|
||||
|
||||
// Used for SSL transport layer
|
||||
CertPEM string
|
||||
KeyPEM string
|
||||
@@ -55,7 +52,6 @@ type TLSConfig struct {
|
||||
|
||||
type s3Client struct {
|
||||
api minio.API
|
||||
acl string
|
||||
hostURL *client.URL
|
||||
}
|
||||
|
||||
@@ -87,7 +83,7 @@ func New(config *Config) (client.Client, *probe.Error) {
|
||||
if err != nil {
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
return &s3Client{api: api, hostURL: u, acl: config.ACL}, nil
|
||||
return &s3Client{api: api, hostURL: u}, nil
|
||||
}
|
||||
|
||||
// URL get url
|
||||
@@ -121,7 +117,7 @@ func (c *s3Client) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
// for a multipart upload and there is no need to cross verify,
|
||||
// invidual parts are properly verified
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
err := c.api.PutObject(bucket, object, "application/octet-stream", minio.ACL(c.acl), size, data)
|
||||
err := c.api.PutObject(bucket, object, "application/octet-stream", size, data)
|
||||
if err != nil {
|
||||
errResponse := minio.ToErrorResponse(err)
|
||||
if errResponse != nil {
|
||||
@@ -134,26 +130,13 @@ func (c *s3Client) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetObjectACL - set object acl
|
||||
func (c *s3Client) SetObjectACL(acl string) *probe.Error {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if object == "" {
|
||||
return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()})
|
||||
}
|
||||
err := c.api.SetObjectACL(bucket, object, minio.ACL(acl))
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MakeBucket - make a new bucket
|
||||
func (c *s3Client) MakeBucket() *probe.Error {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if object != "" {
|
||||
return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()})
|
||||
}
|
||||
err := c.api.MakeBucket(bucket, minio.ACL("private"))
|
||||
err := c.api.MakeBucket(bucket, minio.BucketACL("private"))
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
@@ -166,7 +149,7 @@ func (c *s3Client) SetBucketACL(acl string) *probe.Error {
|
||||
if object != "" {
|
||||
return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()})
|
||||
}
|
||||
err := c.api.SetBucketACL(bucket, minio.ACL(acl))
|
||||
err := c.api.SetBucketACL(bucket, minio.BucketACL(acl))
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
+2
-2
@@ -41,8 +41,8 @@
|
||||
"canonical": "github.com/minio/minio-go",
|
||||
"comment": "",
|
||||
"local": "vendor/github.com/minio/minio-go",
|
||||
"revision": "1e3ce581b7c50b431bb68db5d03d59927ce4d1fd",
|
||||
"revisionTime": "2015-08-28T19:47:26-07:00"
|
||||
"revision": "7860bcf566f9e641f94a4d85ac60a4f3a0883f46",
|
||||
"revisionTime": "2015-08-28T00:38:53-07:00"
|
||||
},
|
||||
{
|
||||
"canonical": "github.com/minio/minio/pkg/probe",
|
||||
|
||||
+8
-101
@@ -88,10 +88,13 @@ func (a apiV1) putBucketRequest(bucket, acl, location string) (*request, error)
|
||||
r.req.ContentLength = int64(createBucketConfigBuffer.Len())
|
||||
}
|
||||
// by default bucket is private
|
||||
r.Set("x-amz-acl", "private")
|
||||
if acl != "" {
|
||||
switch {
|
||||
case acl != "":
|
||||
r.Set("x-amz-acl", acl)
|
||||
default:
|
||||
r.Set("x-amz-acl", "private")
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
@@ -520,7 +523,7 @@ func (a apiV1) putObjectUnAuthenticated(bucket, object, contentType string, size
|
||||
}
|
||||
|
||||
// putObjectRequest wrapper creates a new PutObject request
|
||||
func (a apiV1) putObjectRequest(bucket, object, contentType, acl string, md5SumBytes []byte, size int64, body io.ReadSeeker) (*request, error) {
|
||||
func (a apiV1) putObjectRequest(bucket, object, contentType string, md5SumBytes []byte, size int64, body io.ReadSeeker) (*request, error) {
|
||||
if strings.TrimSpace(contentType) == "" {
|
||||
contentType = "application/octet-stream"
|
||||
}
|
||||
@@ -537,11 +540,6 @@ func (a apiV1) putObjectRequest(bucket, object, contentType, acl string, md5SumB
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.Set("x-amz-acl", "private")
|
||||
if acl != "" {
|
||||
r.Set("x-amz-acl", acl)
|
||||
}
|
||||
// set Content-MD5 as base64 encoded md5
|
||||
r.Set("Content-MD5", base64.StdEncoding.EncodeToString(md5SumBytes))
|
||||
r.Set("Content-Type", contentType)
|
||||
@@ -551,8 +549,8 @@ func (a apiV1) putObjectRequest(bucket, object, contentType, acl string, md5SumB
|
||||
|
||||
// putObject - add an object to a bucket
|
||||
// NOTE: You must have WRITE permissions on a bucket to add an object to it.
|
||||
func (a apiV1) putObject(bucket, object, contentType, acl string, md5SumBytes []byte, size int64, body io.ReadSeeker) (ObjectStat, error) {
|
||||
req, err := a.putObjectRequest(bucket, object, contentType, acl, md5SumBytes, size, body)
|
||||
func (a apiV1) putObject(bucket, object, contentType string, md5SumBytes []byte, size int64, body io.ReadSeeker) (ObjectStat, error) {
|
||||
req, err := a.putObjectRequest(bucket, object, contentType, md5SumBytes, size, body)
|
||||
if err != nil {
|
||||
return ObjectStat{}, err
|
||||
}
|
||||
@@ -579,97 +577,6 @@ func (a apiV1) putObject(bucket, object, contentType, acl string, md5SumBytes []
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
// putObjectACLRequest wrapper creates a new PutObjectACL request
|
||||
func (a apiV1) putObjectACLRequest(bucket, object, acl string) (*request, error) {
|
||||
encodedObject, err := urlEncodeName(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
op := &operation{
|
||||
HTTPServer: a.config.Endpoint,
|
||||
HTTPMethod: "PUT",
|
||||
HTTPPath: separator + bucket + separator + encodedObject + "?acl",
|
||||
}
|
||||
r, err := newRequest(op, a.config, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.Set("x-amz-acl", acl)
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// putObject - add an object to a bucket
|
||||
// NOTE: You must have WRITE permissions on a bucket to add an object to it.
|
||||
func (a apiV1) putObjectACL(bucket, object, acl string) error {
|
||||
req, err := a.putObjectACLRequest(bucket, object, acl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := req.Do()
|
||||
defer closeResp(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return BodyToErrorResponse(resp.Body, a.config.AcceptType)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// getObjectACLRequest wrapper creates a new getObjectACL request
|
||||
func (a apiV1) getObjectACLRequest(bucket, object string) (*request, error) {
|
||||
encodedObject, err := urlEncodeName(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
op := &operation{
|
||||
HTTPServer: a.config.Endpoint,
|
||||
HTTPMethod: "GET",
|
||||
HTTPPath: separator + bucket + separator + encodedObject + "?acl",
|
||||
}
|
||||
req, err := newRequest(op, a.config, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// getObjectACL get the acl information on an existing bucket
|
||||
func (a apiV1) getObjectACL(bucket, object string) (accessControlPolicy, error) {
|
||||
req, err := a.getObjectACLRequest(bucket, object)
|
||||
if err != nil {
|
||||
return accessControlPolicy{}, err
|
||||
}
|
||||
resp, err := req.Do()
|
||||
defer closeResp(resp)
|
||||
if err != nil {
|
||||
return accessControlPolicy{}, err
|
||||
}
|
||||
if resp != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return accessControlPolicy{}, BodyToErrorResponse(resp.Body, a.config.AcceptType)
|
||||
}
|
||||
}
|
||||
policy := accessControlPolicy{}
|
||||
err = acceptTypeDecoder(resp.Body, a.config.AcceptType, &policy)
|
||||
if err != nil {
|
||||
return accessControlPolicy{}, err
|
||||
}
|
||||
if policy.AccessControlList.Grant == nil {
|
||||
errorResponse := ErrorResponse{
|
||||
Code: "InternalError",
|
||||
Message: "Access control Grant list is empty, please report this at https://github.com/minio/minio-go/issues",
|
||||
Resource: separator + bucket + separator + object,
|
||||
RequestID: resp.Header.Get("x-amz-request-id"),
|
||||
HostID: resp.Header.Get("x-amz-id-2"),
|
||||
}
|
||||
return accessControlPolicy{}, errorResponse
|
||||
}
|
||||
return policy, nil
|
||||
}
|
||||
|
||||
func (a apiV1) presignedGetObjectRequest(bucket, object string, expires, offset, length int64) (*request, error) {
|
||||
encodedObject, err := urlEncodeName(object)
|
||||
if err != nil {
|
||||
|
||||
+18
-93
@@ -44,11 +44,11 @@ type API interface {
|
||||
|
||||
// BucketAPI - bucket specific Read/Write/Stat interface
|
||||
type BucketAPI interface {
|
||||
MakeBucket(bucket string, cannedACL ACL) error
|
||||
MakeBucket(bucket string, cannedACL BucketACL) error
|
||||
BucketExists(bucket string) error
|
||||
RemoveBucket(bucket string) error
|
||||
SetBucketACL(bucket string, acl ACL) error
|
||||
GetBucketACL(bucket string) (ACL, error)
|
||||
SetBucketACL(bucket string, cannedACL BucketACL) error
|
||||
GetBucketACL(bucket string) (BucketACL, error)
|
||||
|
||||
ListBuckets() <-chan BucketStatCh
|
||||
ListObjects(bucket, prefix string, recursive bool) <-chan ObjectStatCh
|
||||
@@ -61,9 +61,7 @@ type BucketAPI interface {
|
||||
type ObjectAPI interface {
|
||||
GetObject(bucket, object string) (io.ReadCloser, ObjectStat, error)
|
||||
GetPartialObject(bucket, object string, offset, length int64) (io.ReadCloser, ObjectStat, error)
|
||||
PutObject(bucket, object, contentType string, acl ACL, size int64, data io.Reader) error
|
||||
SetObjectACL(bucket, object string, acl ACL) error
|
||||
GetObjectACL(bucket, object string) (ACL, error)
|
||||
PutObject(bucket, object, contentType string, size int64, data io.Reader) error
|
||||
StatObject(bucket, object string) (ObjectStat, error)
|
||||
RemoveObject(bucket, object string) error
|
||||
|
||||
@@ -501,16 +499,13 @@ func (a apiV2) listMultipartUploadsRecursiveInRoutine(bucket, object string, ch
|
||||
// You must have WRITE permissions on a bucket to create an object
|
||||
//
|
||||
// This version of PutObject automatically does multipart for more than 5MB worth of data
|
||||
func (a apiV2) PutObject(bucket, object, contentType string, acl ACL, size int64, data io.Reader) error {
|
||||
func (a apiV2) PutObject(bucket, object, contentType string, size int64, data io.Reader) error {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := invalidArgumentError(object); err != nil {
|
||||
return err
|
||||
}
|
||||
if !acl.isValidACL() {
|
||||
return invalidArgumentError("")
|
||||
}
|
||||
// for un-authenticated requests do not initiated multipart operation
|
||||
//
|
||||
// NOTE: this behavior is only kept valid for S3, since S3 doesn't
|
||||
@@ -539,7 +534,7 @@ func (a apiV2) PutObject(bucket, object, contentType string, acl ACL, size int64
|
||||
Resource: separator + bucket + separator + object,
|
||||
}
|
||||
}
|
||||
_, err := a.putObject(bucket, object, contentType, string(acl), part.MD5Sum, part.Len, part.ReadSeeker)
|
||||
_, err := a.putObject(bucket, object, contentType, part.MD5Sum, part.Len, part.ReadSeeker)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -559,83 +554,13 @@ func (a apiV2) PutObject(bucket, object, contentType string, acl ACL, size int64
|
||||
}
|
||||
}
|
||||
if !inProgress {
|
||||
if err := a.newObjectUpload(bucket, object, contentType, size, data); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.putObjectACL(bucket, object, string(acl))
|
||||
return a.newObjectUpload(bucket, object, contentType, size, data)
|
||||
}
|
||||
if err := a.continueObjectUpload(bucket, object, inProgressUploadID, size, data); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.putObjectACL(bucket, object, string(acl))
|
||||
return a.continueObjectUpload(bucket, object, inProgressUploadID, size, data)
|
||||
}
|
||||
return errors.New("Unexpected control flow, please report this error at https://github.com/minio/minio-go/issues")
|
||||
}
|
||||
|
||||
// GetObjectACL get the permissions on an existing object
|
||||
//
|
||||
// Returned values are:
|
||||
//
|
||||
// private - owner gets full access
|
||||
// public-read - owner gets full access, others get read access
|
||||
// public-read-write - owner gets full access, others get full access too
|
||||
// authenticated-read - owner gets full access, authenticated users get read access
|
||||
//
|
||||
func (a apiV2) GetObjectACL(bucket, object string) (ACL, error) {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := invalidArgumentError(object); err != nil {
|
||||
return "", err
|
||||
}
|
||||
policy, err := a.getObjectACL(bucket, object)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
grants := policy.AccessControlList.Grant
|
||||
switch {
|
||||
case len(grants) == 1:
|
||||
if grants[0].Grantee.URI == "" && grants[0].Permission == "FULL_CONTROL" {
|
||||
return ACL("private"), nil
|
||||
}
|
||||
case len(grants) == 2:
|
||||
for _, g := range grants {
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" && g.Permission == "READ" {
|
||||
return ACL("authenticated-read"), nil
|
||||
}
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" && g.Permission == "READ" {
|
||||
return ACL("public-read"), nil
|
||||
}
|
||||
}
|
||||
case len(grants) == 3:
|
||||
for _, g := range grants {
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" && g.Permission == "WRITE" {
|
||||
return ACL("public-read-write"), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", ErrorResponse{
|
||||
Code: "NoSuchObjectPolicy",
|
||||
Message: "The specified object does not have a access policy.",
|
||||
Resource: separator + bucket + separator + object,
|
||||
RequestID: "minio",
|
||||
}
|
||||
}
|
||||
|
||||
// SetObjectACL set object acl's
|
||||
func (a apiV2) SetObjectACL(bucket, object string, acl ACL) error {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := invalidArgumentError(object); err != nil {
|
||||
return err
|
||||
}
|
||||
if !acl.isValidACL() {
|
||||
return invalidArgumentError("")
|
||||
}
|
||||
return a.putObjectACL(bucket, object, string(acl))
|
||||
}
|
||||
|
||||
// StatObject verify if object exists and you have permission to access it
|
||||
func (a apiV2) StatObject(bucket, object string) (ObjectStat, error) {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
@@ -677,11 +602,11 @@ func (a apiV2) RemoveObject(bucket, object string) error {
|
||||
//
|
||||
// [ us-west-1 | us-west-2 | eu-west-1 | eu-central-1 | ap-southeast-1 | ap-northeast-1 | ap-southeast-2 | sa-east-1 ]
|
||||
// Default - US standard
|
||||
func (a apiV2) MakeBucket(bucket string, acl ACL) error {
|
||||
func (a apiV2) MakeBucket(bucket string, acl BucketACL) error {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return err
|
||||
}
|
||||
if !acl.isValidACL() {
|
||||
if !acl.isValidBucketACL() {
|
||||
return invalidArgumentError("")
|
||||
}
|
||||
location := a.config.Region
|
||||
@@ -703,11 +628,11 @@ func (a apiV2) MakeBucket(bucket string, acl ACL) error {
|
||||
// public-read-write - owner gets full access, all others get full access too
|
||||
// authenticated-read - owner gets full access, authenticated users get read access
|
||||
//
|
||||
func (a apiV2) SetBucketACL(bucket string, acl ACL) error {
|
||||
func (a apiV2) SetBucketACL(bucket string, acl BucketACL) error {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return err
|
||||
}
|
||||
if !acl.isValidACL() {
|
||||
if !acl.isValidBucketACL() {
|
||||
return invalidArgumentError("")
|
||||
}
|
||||
return a.putBucketACL(bucket, string(acl))
|
||||
@@ -722,7 +647,7 @@ func (a apiV2) SetBucketACL(bucket string, acl ACL) error {
|
||||
// public-read-write - owner gets full access, others get full access too
|
||||
// authenticated-read - owner gets full access, authenticated users get read access
|
||||
//
|
||||
func (a apiV2) GetBucketACL(bucket string) (ACL, error) {
|
||||
func (a apiV2) GetBucketACL(bucket string) (BucketACL, error) {
|
||||
if err := invalidBucketError(bucket); err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -734,28 +659,28 @@ func (a apiV2) GetBucketACL(bucket string) (ACL, error) {
|
||||
switch {
|
||||
case len(grants) == 1:
|
||||
if grants[0].Grantee.URI == "" && grants[0].Permission == "FULL_CONTROL" {
|
||||
return ACL("private"), nil
|
||||
return BucketACL("private"), nil
|
||||
}
|
||||
case len(grants) == 2:
|
||||
for _, g := range grants {
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" && g.Permission == "READ" {
|
||||
return ACL("authenticated-read"), nil
|
||||
return BucketACL("authenticated-read"), nil
|
||||
}
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" && g.Permission == "READ" {
|
||||
return ACL("public-read"), nil
|
||||
return BucketACL("public-read"), nil
|
||||
}
|
||||
}
|
||||
case len(grants) == 3:
|
||||
for _, g := range grants {
|
||||
if g.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers" && g.Permission == "WRITE" {
|
||||
return ACL("public-read-write"), nil
|
||||
return BucketACL("public-read-write"), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", ErrorResponse{
|
||||
Code: "NoSuchBucketPolicy",
|
||||
Message: "The specified bucket does not have a bucket policy.",
|
||||
Resource: separator + bucket,
|
||||
Resource: "/" + bucket,
|
||||
RequestID: "minio",
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ func TestACLTypes(t *testing.T) {
|
||||
"invalid": false,
|
||||
}
|
||||
for acl, ok := range want {
|
||||
if ACL(acl).isValidACL() != ok {
|
||||
if BucketACL(acl).isValidBucketACL() != ok {
|
||||
t.Fatal("Error")
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -64,7 +64,7 @@ func TestBucketOperations(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error")
|
||||
}
|
||||
if acl != minio.ACL("private") {
|
||||
if acl != minio.BucketACL("private") {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ func TestObjectOperations(t *testing.T) {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
data := []byte("Hello, World")
|
||||
err = a.PutObject("bucket", "object", "", minio.ACL("private"), int64(len(data)), bytes.NewReader(data))
|
||||
err = a.PutObject("bucket", "object", "", int64(len(data)), bytes.NewReader(data))
|
||||
if err != nil {
|
||||
t.Fatalf("Error")
|
||||
}
|
||||
|
||||
Generated
Vendored
+18
-18
@@ -16,27 +16,27 @@
|
||||
|
||||
package minio
|
||||
|
||||
// ACL - level access control
|
||||
type ACL string
|
||||
// BucketACL - bucket level access control
|
||||
type BucketACL string
|
||||
|
||||
// different types of ACL's currently supported
|
||||
// different types of ACL's currently supported for buckets
|
||||
const (
|
||||
Private = ACL("private")
|
||||
ReadOnly = ACL("public-read")
|
||||
Public = ACL("public-read-write")
|
||||
Authenticated = ACL("authenticated-read")
|
||||
bucketPrivate = BucketACL("private")
|
||||
bucketReadOnly = BucketACL("public-read")
|
||||
bucketPublic = BucketACL("public-read-write")
|
||||
bucketAuthenticated = BucketACL("authenticated-read")
|
||||
)
|
||||
|
||||
// String printer helper
|
||||
func (b ACL) String() string {
|
||||
func (b BucketACL) String() string {
|
||||
if string(b) == "" {
|
||||
return "private"
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// isValidACL - is provided acl string supported
|
||||
func (b ACL) isValidACL() bool {
|
||||
// isValidBucketACL - is provided acl string supported
|
||||
func (b BucketACL) isValidBucketACL() bool {
|
||||
switch true {
|
||||
case b.isPrivate():
|
||||
fallthrough
|
||||
@@ -55,21 +55,21 @@ func (b ACL) isValidACL() bool {
|
||||
}
|
||||
|
||||
// IsPrivate - is acl Private
|
||||
func (b ACL) isPrivate() bool {
|
||||
return b == Private
|
||||
func (b BucketACL) isPrivate() bool {
|
||||
return b == bucketPrivate
|
||||
}
|
||||
|
||||
// IsPublicRead - is acl PublicRead
|
||||
func (b ACL) isReadOnly() bool {
|
||||
return b == ReadOnly
|
||||
func (b BucketACL) isReadOnly() bool {
|
||||
return b == bucketReadOnly
|
||||
}
|
||||
|
||||
// IsPublicReadWrite - is acl PublicReadWrite
|
||||
func (b ACL) isPublic() bool {
|
||||
return b == Public
|
||||
func (b BucketACL) isPublic() bool {
|
||||
return b == bucketPublic
|
||||
}
|
||||
|
||||
// IsAuthenticated - is acl AuthenticatedRead
|
||||
func (b ACL) isAuthenticated() bool {
|
||||
return b == Authenticated
|
||||
func (b BucketACL) isAuthenticated() bool {
|
||||
return b == bucketAuthenticated
|
||||
}
|
||||
@@ -5,3 +5,4 @@ package main
|
||||
|
||||
// Version autogenerated
|
||||
const Version = "2015-08-28T19:20:08.123385413Z"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user