Beispiel #1
0
func (this *ControlPlaneDao) GetUser(userName string, user *userdomain.User) error {
	glog.V(2).Infof("ControlPlaneDao.GetUser: userName=%s", userName)
	store := userdomain.NewStore()
	err := store.Get(datastore.Get(), userdomain.Key(userName), user)
	glog.V(2).Infof("ControlPlaneDao.GetUser: userName=%s, user=%+v, err=%s", userName, user, err)
	if user == nil {
		*user = userdomain.User{}
	}
	return err
}
Beispiel #2
0
//addUser places a new user record into elastic searchp
func (this *ControlPlaneDao) AddUser(newUser userdomain.User, userName *string) error {
	glog.V(2).Infof("ControlPlane.NewUser: %+v", newUser)
	name := strings.TrimSpace(*userName)
	newUser.Password = hashPassword(newUser.Password)

	// save the user
	var existing userdomain.User
	if err := this.GetUser(name, &existing); err != nil && !datastore.IsErrNoSuchEntity(err) {
		return err
	}
	store := userdomain.NewStore()
	return store.Put(datastore.Get(), userdomain.Key(name), &newUser)
}
Beispiel #3
0
//UpdateUser updates the user entry in elastic search. NOTE: It is assumed the
//pasword is NOT hashed when updating the user record
func (this *ControlPlaneDao) UpdateUser(user userdomain.User, unused *int) error {
	glog.V(2).Infof("ControlPlaneDao.UpdateUser: %+v", user)

	id := strings.TrimSpace(user.Name)
	if id == "" {
		return errors.New("empty User.Name not allowed")
	}

	user.Name = id
	user.Password = hashPassword(user.Password)

	store := userdomain.NewStore()
	return store.Put(datastore.Get(), userdomain.Key(user.Name), &user)
}
Beispiel #4
0
// RemoveUser removes the user specified by the userName string
func (this *ControlPlaneDao) RemoveUser(userName string, unused *int) error {
	glog.V(2).Infof("ControlPlaneDao.RemoveUser: %s", userName)
	store := userdomain.NewStore()
	return store.Delete(datastore.Get(), userdomain.Key(userName))
}