Renaming keys as auth, working towards signature v4 support for all put objects

master
Harshavardhana 10 years ago
parent b71f15d32d
commit 770fd23afa
  1. 14
      pkg/auth/auth.go
  2. 17
      pkg/auth/auth_test.go
  3. 2
      pkg/auth/common.go

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package keys package auth
import ( import (
"crypto/rand" "crypto/rand"
@ -24,9 +24,9 @@ import (
// Static alphaNumeric table used for generating unique keys // Static alphaNumeric table used for generating unique keys
var alphaNumericTable = []byte("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") 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 // takes input as size in integer
func GenerateRandomAlphaNumeric(size int) ([]byte, error) { func GenerateAccessKeyID(size int) ([]byte, error) {
alpha := make([]byte, size) alpha := make([]byte, size)
_, err := rand.Read(alpha) _, err := rand.Read(alpha)
if err != nil { if err != nil {
@ -39,13 +39,13 @@ func GenerateRandomAlphaNumeric(size int) ([]byte, error) {
return alpha, nil return alpha, nil
} }
// GenerateRandomBase64 - generate random base64 numeric value from a random seed. // GenerateSecretAccessKey - generate random base64 numeric value from a random seed.
func GenerateRandomBase64(size int) ([]byte, error) { func GenerateSecretAccessKey(size int) ([]byte, error) {
rb := make([]byte, size) rb := make([]byte, size)
_, err := rand.Read(rb) _, err := rand.Read(rb)
if err != nil { if err != nil {
return nil, err return nil, err
} }
dest := base64.StdEncoding.EncodeToString(rb)
return []byte(dest), nil return []byte(base64.StdEncoding.EncodeToString(rb))[:size], nil
} }

@ -14,13 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
package keys_test package auth_test
import ( import (
"testing" "testing"
. "github.com/minio/check" . "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) } func Test(t *testing.T) { TestingT(t) }
@ -29,13 +29,16 @@ type MySuite struct{}
var _ = Suite(&MySuite{}) var _ = Suite(&MySuite{})
func (s *MySuite) TestingKeys(c *C) { func (s *MySuite) TestAuth(c *C) {
value, err := keys.GenerateRandomBase64(keys.MinioSecretID) secretID, err := auth.GenerateSecretAccessKey(auth.MinioSecretID)
c.Assert(err, IsNil) c.Assert(err, IsNil)
alphanum, err := keys.GenerateRandomAlphaNumeric(keys.MinioAccessID) accessID, err := auth.GenerateAccessKeyID(auth.MinioAccessID)
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Log(string(value)) c.Assert(len(secretID), Equals, auth.MinioSecretID)
c.Log(string(alphanum)) c.Assert(len(accessID), Equals, auth.MinioAccessID)
c.Log(string(secretID))
c.Log(string(accessID))
} }

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package keys package auth
import "regexp" import "regexp"
Loading…
Cancel
Save