Beispiel #1
0
// change the current config to a spesific version
func (c *ConfigVersion) Post(req *Request) {

	var p config.Provider
	c.pipeline.ViewConfig(func(conf *config.AppConfig) {
		p = conf.Provider()
	})

	vars := mux.Vars(req.r)
	version, ok := vars["version"]
	if !ok {
		http.Error(req.w, "must append config version", http.StatusBadRequest)
		return
	}

	// get the config that this version is looking for
	conf, err := p.GetConfig(version)
	if err != nil {
		logrus.Error(err)
		http.Error(req.w, err.Error(), http.StatusBadRequest)
		return
	}

	_, err = p.PutConfig(conf, req.u)
	if err != nil {
		logrus.Error(err)
		http.Error(req.w, err.Error(), http.StatusBadRequest)
		return
	}

	c.pipeline.Refresh(conf)

}
Beispiel #2
0
func authUser(confProvider config.Provider, r *http.Request) (*config.User, error) {

	// check for a session token
	session := r.Header.Get(SESSION_HEADER_NAME)

	// create user doesn't require auth
	if r.URL.Path == "/api/user" && r.Method == "POST" {
		return confProvider.GetUserByUserName("admin")
	}

	// fetch the user id from the session store for this token
	if session != "" {
		userName, err := GlobalSession.Get(session)
		if err != nil {
			return nil, err
		}

		//  get the user by the given id
		return confProvider.GetUser(userName)
	}
	user, password, ok := r.BasicAuth()
	if !ok {
		return nil, fmt.Errorf("Auth not provided")
	}

	// fetch the user
	u, err := confProvider.GetUserByUserName(user)
	if err != nil {
		return nil, err
	}

	// check to see if the password is correct
	if !config.CheckUserPassword(u, password) {
		return nil, fmt.Errorf("The provided password is incorrect for user %s", user)
	}

	return u, nil
}