Beispiel #1
0
func (s *MySuite) TestingKeys(c *C) {
	value, err := keys.GenerateRandomBase64(keys.MinioSecretID)
	c.Assert(err, IsNil)

	alphanum, err := keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
	c.Assert(err, IsNil)

	c.Log(string(value))
	c.Log(string(alphanum))
}
Beispiel #2
0
func (s *MySuite) TestConfig(c *C) {
	conf := Config{}
	conf.ConfigLock = new(sync.RWMutex)
	conf.ConfigPath, _ = ioutil.TempDir("/tmp", "minio-test-")
	defer os.RemoveAll(conf.ConfigPath)
	conf.ConfigFile = filepath.Join(conf.ConfigPath, "config.json")
	if _, err := os.Stat(conf.ConfigFile); os.IsNotExist(err) {
		_, err = os.Create(conf.ConfigFile)
		if err != nil {
			c.Fatal(err)
		}
	}

	accesskey, _ := keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
	secretkey, _ := keys.GenerateRandomBase64(keys.MinioSecretID)

	user := User{
		Name:      "gnubot",
		AccessKey: string(accesskey),
		SecretKey: string(secretkey),
	}

	conf.AddUser(user)
	err := conf.WriteConfig()
	c.Assert(err, IsNil)

	err = conf.ReadConfig()
	c.Assert(err, IsNil)

	accesskey, _ = keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
	secretkey, _ = keys.GenerateRandomBase64(keys.MinioSecretID)
	user = User{
		Name:      "minio",
		AccessKey: string(accesskey),
		SecretKey: string(secretkey),
	}
	conf.AddUser(user)
	err = conf.WriteConfig()
	c.Assert(err, IsNil)
}
Beispiel #3
0
func (web *webAPI) accessHandler(w http.ResponseWriter, req *http.Request) {
	var err error
	var accesskey, secretkey []byte
	username := req.FormValue("username")
	if len(username) <= 0 {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	err = web.conf.ReadConfig()
	if err != nil {
		log.Error.Println(iodine.New(err, nil))
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(err.Error()))
		return
	}

	if web.conf.IsUserExists(username) {
		w.WriteHeader(http.StatusConflict)
		return
	}

	var user = config.User{}
	user.Name = username

	accesskey, err = keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
	if err != nil {
		log.Error.Println(iodine.New(err, nil))
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(err.Error()))
		return
	}
	user.AccessKey = string(accesskey)

	secretkey, err = keys.GenerateRandomBase64(keys.MinioSecretID)
	if err != nil {
		log.Error.Println(iodine.New(err, nil))
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(err.Error()))
		return
	}
	user.SecretKey = string(secretkey)

	web.conf.AddUser(user)
	err = web.conf.WriteConfig()
	if err != nil {
		log.Error.Println(iodine.New(err, nil))
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(err.Error()))
		return
	}

	err = web.conf.ReadConfig()
	if err != nil {
		log.Error.Println(iodine.New(err, nil))
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(err.Error()))
		return
	}

	// Get user back for sending it over HTTP reply
	user = web.conf.GetUser(username)
	w.Write(writeResponse(w, user))
}