diff --git a/pkg/server/api/auth/keys/keys.go b/pkg/auth/auth.go similarity index 74% rename from pkg/server/api/auth/keys/keys.go rename to pkg/auth/auth.go index bc111d94b..8b50e068e 100644 --- a/pkg/server/api/auth/keys/keys.go +++ b/pkg/auth/auth.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package keys +package auth import ( "crypto/rand" @@ -24,9 +24,9 @@ import ( // Static alphaNumeric table used for generating unique keys var alphaNumericTable = []byte("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") -// GenerateRandomAlphaNumeric - generate random alpha numeric value using only uppercase characters +// GenerateAccessKeyID - generate random alpha numeric value using only uppercase characters // takes input as size in integer -func GenerateRandomAlphaNumeric(size int) ([]byte, error) { +func GenerateAccessKeyID(size int) ([]byte, error) { alpha := make([]byte, size) _, err := rand.Read(alpha) if err != nil { @@ -39,13 +39,13 @@ func GenerateRandomAlphaNumeric(size int) ([]byte, error) { return alpha, nil } -// GenerateRandomBase64 - generate random base64 numeric value from a random seed. -func GenerateRandomBase64(size int) ([]byte, error) { +// GenerateSecretAccessKey - generate random base64 numeric value from a random seed. +func GenerateSecretAccessKey(size int) ([]byte, error) { rb := make([]byte, size) _, err := rand.Read(rb) if err != nil { return nil, err } - dest := base64.StdEncoding.EncodeToString(rb) - return []byte(dest), nil + + return []byte(base64.StdEncoding.EncodeToString(rb))[:size], nil } diff --git a/pkg/server/api/auth/keys/keys_test.go b/pkg/auth/auth_test.go similarity index 68% rename from pkg/server/api/auth/keys/keys_test.go rename to pkg/auth/auth_test.go index a3ecb9573..35f5133e4 100644 --- a/pkg/server/api/auth/keys/keys_test.go +++ b/pkg/auth/auth_test.go @@ -14,13 +14,13 @@ * limitations under the License. */ -package keys_test +package auth_test import ( "testing" . "github.com/minio/check" - "github.com/minio/minio/pkg/server/api/auth/keys" + "github.com/minio/minio/pkg/auth" ) func Test(t *testing.T) { TestingT(t) } @@ -29,13 +29,16 @@ type MySuite struct{} var _ = Suite(&MySuite{}) -func (s *MySuite) TestingKeys(c *C) { - value, err := keys.GenerateRandomBase64(keys.MinioSecretID) +func (s *MySuite) TestAuth(c *C) { + secretID, err := auth.GenerateSecretAccessKey(auth.MinioSecretID) c.Assert(err, IsNil) - alphanum, err := keys.GenerateRandomAlphaNumeric(keys.MinioAccessID) + accessID, err := auth.GenerateAccessKeyID(auth.MinioAccessID) c.Assert(err, IsNil) - c.Log(string(value)) - c.Log(string(alphanum)) + c.Assert(len(secretID), Equals, auth.MinioSecretID) + c.Assert(len(accessID), Equals, auth.MinioAccessID) + + c.Log(string(secretID)) + c.Log(string(accessID)) } diff --git a/pkg/server/api/auth/keys/common.go b/pkg/auth/common.go similarity index 98% rename from pkg/server/api/auth/keys/common.go rename to pkg/auth/common.go index 9f94f08b7..e1428c2a3 100644 --- a/pkg/server/api/auth/keys/common.go +++ b/pkg/auth/common.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package keys +package auth import "regexp"