From 902aa0502197a19686565b12ed55e0a0166b3bb4 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 21 Mar 2016 01:06:07 -0700 Subject: [PATCH] main: Remove all the dead/unused code. This patch removes some dead and unused code. --- api-response.go | 22 ---------------------- auth-handler.go | 8 -------- bucket-policy.go | 14 +++++++------- server_fs_test.go | 9 +++++++++ typed-errors.go | 47 ----------------------------------------------- 5 files changed, 16 insertions(+), 84 deletions(-) diff --git a/api-response.go b/api-response.go index 2e2e6748a..9467c8c9d 100644 --- a/api-response.go +++ b/api-response.go @@ -37,28 +37,6 @@ type LocationResponse struct { Location string `xml:",chardata"` } -// AccessControlPolicyResponse - format for get bucket acl response. -type AccessControlPolicyResponse struct { - XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ AccessControlPolicy" json:"-"` - - AccessControlList struct { - Grants []Grant `xml:"Grant"` - } - Owner Owner -} - -// Grant container for grantee and permission. -type Grant struct { - Grantee struct { - ID string - DisplayName string - EmailAddress string - Type string - URI string - } - Permission string -} - // ListObjectsResponse - format for list objects response. type ListObjectsResponse struct { XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult" json:"-"` diff --git a/auth-handler.go b/auth-handler.go index d4e2e0f2c..81e04758d 100644 --- a/auth-handler.go +++ b/auth-handler.go @@ -68,14 +68,6 @@ func isRequestPostPolicySignatureV4(r *http.Request) bool { return false } -// Verify if incoming request is anonymous. -func isRequestAnonymous(r *http.Request) bool { - if isRequestJWT(r) || isRequestSignatureV4(r) || isRequestPresignedSignatureV4(r) || isRequestPostPolicySignatureV4(r) { - return false - } - return true -} - // Authorization type. type authType int diff --git a/bucket-policy.go b/bucket-policy.go index 14f8c0ae0..3e5b8183e 100644 --- a/bucket-policy.go +++ b/bucket-policy.go @@ -46,7 +46,7 @@ func createBucketsConfigPath() *probe.Error { return nil } -// getBucketConfigPath - get bucket path. +// getBucketConfigPath - get bucket config path. func getBucketConfigPath(bucket string) (string, *probe.Error) { bucketsConfigPath, err := getBucketsConfigPath() if err != nil { @@ -55,7 +55,7 @@ func getBucketConfigPath(bucket string) (string, *probe.Error) { return filepath.Join(bucketsConfigPath, bucket), nil } -// createBucketConfigPath - create bucket directory. +// createBucketConfigPath - create bucket config directory. func createBucketConfigPath(bucket string) *probe.Error { bucketConfigPath, err := getBucketConfigPath(bucket) if err != nil { @@ -125,6 +125,11 @@ func writeBucketPolicy(bucket string, accessPolicyBytes []byte) *probe.Error { return probe.NewError(fs.BucketNameInvalid{Bucket: bucket}) } + // Create bucket config path. + if err := createBucketConfigPath(bucket); err != nil { + return err.Trace() + } + bucketConfigPath, err := getBucketConfigPath(bucket) if err != nil { return err.Trace() @@ -138,11 +143,6 @@ func writeBucketPolicy(bucket string, accessPolicyBytes []byte) *probe.Error { } } - // Create top level directory. - if e := os.MkdirAll(filepath.Dir(bucketPolicyFile), 0700); e != nil { - return probe.NewError(e) - } - // Write bucket policy. if e := ioutil.WriteFile(bucketPolicyFile, accessPolicyBytes, 0600); e != nil { return probe.NewError(e) diff --git a/server_fs_test.go b/server_fs_test.go index b5409bcee..9793b6a34 100644 --- a/server_fs_test.go +++ b/server_fs_test.go @@ -1103,6 +1103,15 @@ func (s *MyAPIFSCacheSuite) TestBucketMultipartList(c *C) { c.Assert(err, IsNil) c.Assert(response3.StatusCode, Equals, http.StatusOK) + // The reason to duplicate this structure here is to verify if the + // unmarshalling works from a client perspective, specifically + // while unmarshalling time.Time type for 'Initiated' field. + // time.Time does not honor xml marshaler, it means that we need + // to encode/format it before giving it to xml marshalling. + + // This below check adds client side verification to see if its + // truly parseable. + // listMultipartUploadsResponse - format for list multipart uploads response. type listMultipartUploadsResponse struct { XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListMultipartUploadsResult" json:"-"` diff --git a/typed-errors.go b/typed-errors.go index 3187a9d69..647ce8bd8 100644 --- a/typed-errors.go +++ b/typed-errors.go @@ -18,55 +18,8 @@ package main import "errors" -// errInvalidCredentials -var errInvalidCredentials = errors.New("Invalid credentials provided") - -// errUnAuthorizedRequest - un authorized request. -var errUnAuthorizedRequest = errors.New("Unauthorized request") - // errSysLogNotSupported - this message is only meaningful on windows var errSysLogNotSupported = errors.New("Syslog logger not supported on windows") // errInvalidArgument means that input argument is invalid. var errInvalidArgument = errors.New("Invalid arguments specified") - -// errMissingAuthHeader means that Authorization header has missing value or it is empty. -var errMissingAuthHeaderValue = errors.New("Missing auth header value") - -// errInvalidAuthHeaderValue means that Authorization header is available but is malformed and not in -// accordance with signature v4. -var errInvalidAuthHeaderValue = errors.New("Invalid auth header value") - -// errInvalidAuthHeaderPrefix means that Authorization header -// has a wrong prefix only supported value should be "AWS4-HMAC-SHA256". -var errInvalidAuthHeaderPrefix = errors.New("Invalid auth header prefix") - -// errMissingFieldsAuthHeader means that Authorization header is available but has some missing fields. -var errMissingFieldsAuthHeader = errors.New("Missing fields in auth header") - -// errMissingFieldsCredentialTag means that Authorization header credentials tag has some missing fields. -var errMissingFieldsCredentialTag = errors.New("Missing fields in crendential tag") - -// errMissingFieldsSignedHeadersTag means that Authorization header signed headers tag has some missing fields. -var errMissingFieldsSignedHeadersTag = errors.New("Missing fields in signed headers tag") - -// errMissingFieldsSignatureTag means that Authorization header signature tag has missing fields. -var errMissingFieldsSignatureTag = errors.New("Missing fields in signature tag") - -// errCredentialTagMalformed means that Authorization header credential tag is malformed. -var errCredentialTagMalformed = errors.New("Invalid credential tag malformed") - -// errInvalidRegion means that the region element from credential tag in Authorization header is invalid. -var errInvalidRegion = errors.New("Invalid region") - -// errAccessKeyIDInvalid means that the accessKeyID element from credential tag in Authorization header is invalid. -var errAccessKeyIDInvalid = errors.New("AccessKeyID invalid") - -// errUnsupportedAlgorithm means that the provided X-Amz-Algorithm is unsupported. -var errUnsupportedAlgorithm = errors.New("Unsupported Algorithm") - -// errPolicyAlreadyExpired means that the client request carries an post policy header which is already expired. -var errPolicyAlreadyExpired = errors.New("Policy already expired") - -// errPolicyMissingFields means that form values and policy header have some fields missing. -var errPolicyMissingFields = errors.New("Some fields are missing or do not match in policy")