func HandleCreateRole(
	user *graylog.User, lgc *logic.Logic,
	w http.ResponseWriter, r *http.Request, _ httprouter.Params,
) (interface{}, int, error) {
	// POST /roles Create a new role
	if sc, err := lgc.Authorize(user, "roles:create"); 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
	}

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

	if sc, err := lgc.AddRole(role); err != nil {
		return nil, sc, err
	}
	if err := lgc.Save(); err != nil {
		return nil, 500, err
	}
	return role, sc, nil
}
// HandleCreateRole is the handler of Create Role API.
HandleCreateRole is the handler of Create Role API.
// HandleCreateRole is the handler of Create Role API .
func HandleCreateRole(
	user *graylog.User, lgc *logic.Logic,
	w http.ResponseWriter, r *http.Request, _ httprouter.Params,
) (interface{}, int, error) {
	if sc, err := lgc.Authorize(user, "roles:create"); 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
	}
	role := &graylog.Role{}
	if err := util.MSDecode(body, &role); err != nil {
		lgc.Logger().WithFields(log.Fields{
			"body": body, "error": err,
		}).Warn("Failed to parse request body as Role")
		return nil, 400, err
	}
	if sc, err := lgc.AddRole(role); err != nil {
		return nil, sc, err
	}
	if err := lgc.Save(); err != nil {
		return nil, 500, err
	}
	return role, sc, nil
}
func HandleCreateRole ( user * graylog . User , lgc * logic . Logic , w http . ResponseWriter , r * http . Request , _ httprouter . Params , ) ( interface { } , int , error ) { if sc , err := lgc . Authorize ( user , " " ) ; 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 } role := & graylog . Role { } if err := util . MSDecode ( body , & role ) ; err != nil { lgc . Logger ( ) . WithFields ( log . Fields { " " : body , " " : err , } ) . Warn ( " " ) return nil , 400 , err } if sc , err := lgc . AddRole ( role ) ; err != nil { return nil , sc , err } if err := lgc . Save ( ) ; err != nil { return nil , 500 , err } return role , sc , nil }
HandleCreateRole is the handler of Create Role API.
HandleCreateRole is the handler of Create Role API .
// POST /roles Create a new role