mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-03 20:40:00 -05:00
* add unix socket listener for mmctl local mode * First working PoC * Adds the channel list endpoint * Add team list endpoint * Add a LocalClient to the api test helper and start local mode * Add helper to test with both SystemAdmin and Local clients * Add some docs * Adds TestForAllClients test helper * Incorporating @ashishbhate's proposal for adding test names to the helpers * [MM-24146] Add unix socket listener for mmctl local mode (#14296) * add unix socket listener for mmctl local mode * add a constant for local-mode socket path * reflect review comments * Fix init errors after merge * Adds create channel tests * Always init local mode to allow for enabling-disabling it via config * Check the RemoteAddr of the request before marking session as local * Mark the request as errored if it's local and the origin is remote * Set the socket permissions to read/write when initialising * Fix linter * Replace RemoteAddr check to ditch connections with the IP:PORT shape * added update/move/get/delete command in local mode * merge fix * . Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package api4
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/mattermost/mattermost-server/v5/audit"
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
|
)
|
|
|
|
func (api *API) InitCommandLocal() {
|
|
api.BaseRoutes.Commands.Handle("", api.ApiLocal(localCreateCommand)).Methods("POST")
|
|
api.BaseRoutes.Commands.Handle("", api.ApiLocal(listCommands)).Methods("GET")
|
|
|
|
api.BaseRoutes.Command.Handle("", api.ApiLocal(getCommand)).Methods("GET")
|
|
api.BaseRoutes.Command.Handle("", api.ApiLocal(updateCommand)).Methods("PUT")
|
|
api.BaseRoutes.Command.Handle("/move", api.ApiLocal(moveCommand)).Methods("PUT")
|
|
api.BaseRoutes.Command.Handle("", api.ApiLocal(deleteCommand)).Methods("DELETE")
|
|
}
|
|
|
|
func localCreateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
cmd := model.CommandFromJson(r.Body)
|
|
if cmd == nil {
|
|
c.SetInvalidParam("command")
|
|
return
|
|
}
|
|
|
|
auditRec := c.MakeAuditRecord("localCreateCommand", audit.Fail)
|
|
defer c.LogAuditRec(auditRec)
|
|
c.LogAudit("attempt")
|
|
|
|
rcmd, err := c.App.CreateCommand(cmd)
|
|
if err != nil {
|
|
c.Err = err
|
|
return
|
|
}
|
|
|
|
auditRec.Success()
|
|
c.LogAudit("success")
|
|
auditRec.AddMeta("command", rcmd)
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
w.Write([]byte(rcmd.ToJson()))
|
|
}
|