func HandleUpdateRole(
	user *graylog.User, lgc *logic.Logic,
	w http.ResponseWriter, r *http.Request, ps httprouter.Params,
) (interface{}, int, error) {
	// PUT /roles/{rolename} Update an existing role
	name := ps.ByName("rolename")
	if sc, err := lgc.Authorize(user, "roles:edit", name); err != nil {
		return nil, sc, err
	}
	body, sc, err := validateRequestBody(
		r.Body, &validateReqBodyPrms{
			Required:     set.NewStrSet("name", "permissions"),
			Optional:     set.NewStrSet("description"),
			Ignored:      set.NewStrSet("read_only"),
			ExtForbidden: true,
		})
	if err != nil {
		return nil, sc, err
	}

	prms := &graylog.RoleUpdateParams{}
	if err := util.MSDecode(body, prms); err != nil {
		lgc.Logger().WithFields(log.Fields{
			"body": body, "error": err,
		}).Info("Failed to parse request body as Role")
		return nil, 400, err
	}

	role, sc, err := lgc.UpdateRole(name, prms)
	if err != nil {
		return nil, sc, err
	}
	if err := lgc.Save(); err != nil {
		return nil, 500, err
	}
	return role, sc, nil
}
// HandleUpdateRole is the handler of Update Role API.
HandleUpdateRole is the handler of Update Role API.
// HandleUpdateRole is the handler of Update Role API .
func HandleUpdateRole(
	user *graylog.User, lgc *logic.Logic,
	w http.ResponseWriter, r *http.Request, ps httprouter.Params,
) (interface{}, int, error) {
	name := ps.ByName("rolename")
	if sc, err := lgc.Authorize(user, "roles:edit", name); err != nil {
		return nil, sc, err
	}
	body, sc, err := validateRequestBody(
		r.Body, &validateReqBodyPrms{
			Required:     set.NewStrSet("name", "permissions"),
			Optional:     set.NewStrSet("description"),
			Ignored:      set.NewStrSet("read_only"),
			ExtForbidden: true,
		})
	if err != nil {
		return nil, sc, err
	}
	prms := &graylog.RoleUpdateParams{}
	if err := util.MSDecode(body, prms); err != nil {
		lgc.Logger().WithFields(log.Fields{
			"body": body, "error": err,
		}).Info("Failed to parse request body as Role")
		return nil, 400, err
	}
	role, sc, err := lgc.UpdateRole(name, prms)
	if err != nil {
		return nil, sc, err
	}
	if err := lgc.Save(); err != nil {
		return nil, 500, err
	}
	return role, sc, nil
}
func HandleUpdateRole ( user * graylog . User , lgc * logic . Logic , w http . ResponseWriter , r * http . Request , ps httprouter . Params , ) ( interface { } , int , error ) { name := ps . ByName ( " " ) if sc , err := lgc . Authorize ( user , " " , name ) ; err != nil { return nil , sc , err } body , sc , err := validateRequestBody ( r . Body , & validateReqBodyPrms { Required : set . NewStrSet ( " " , " " ) , Optional : set . NewStrSet ( " " ) , Ignored : set . NewStrSet ( " " ) , ExtForbidden : true , } ) if err != nil { return nil , sc , err } prms := & graylog . RoleUpdateParams { } if err := util . MSDecode ( body , prms ) ; err != nil { lgc . Logger ( ) . WithFields ( log . Fields { " " : body , " " : err , } ) . Info ( " " ) return nil , 400 , err } role , sc , err := lgc . UpdateRole ( name , prms ) if err != nil { return nil , sc , err } if err := lgc . Save ( ) ; err != nil { return nil , 500 , err } return role , sc , nil }
HandleUpdateRole is the handler of Update Role API.
HandleUpdateRole is the handler of Update Role API .
// PUT /roles/{rolename} Update an existing role