1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-11-24 08:22:29 +02:00

More work on auth

This commit is contained in:
Jesús Espino 2020-12-04 11:28:35 +01:00
parent 7382f9c55c
commit 99cefc5356
8 changed files with 35 additions and 12 deletions

View File

@ -11,7 +11,7 @@ import (
)
func runOctoTasks(ctx context.Context) {
cmd := exec.CommandContext(ctx, "./octoserver", "--monitorpid", strconv.FormatInt(int64(os.Getpid()), 10))
cmd := exec.CommandContext(ctx, "./octoserver", "--monitorpid", strconv.FormatInt(int64(os.Getpid()), 10), "--single-user")
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {

View File

@ -80,7 +80,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
NSLog("pid: \(pid)")
let serverProcess = Process()
serverProcess.currentDirectoryPath = cwdUrl.path
serverProcess.arguments = ["-monitorpid", "\(pid)", "-port", "\(serverPort)"]
serverProcess.arguments = ["-monitorpid", "\(pid)", "-port", "\(serverPort)", "--single-user"]
serverProcess.launchPath = executablePath
serverProcess.launch()
self.serverProcess = serverProcess

View File

@ -21,10 +21,11 @@ import (
type API struct {
appBuilder func() *app.App
singleUser bool
}
func NewAPI(appBuilder func() *app.App) *API {
return &API{appBuilder: appBuilder}
func NewAPI(appBuilder func() *app.App, singleUser bool) *API {
return &API{appBuilder: appBuilder, singleUser: singleUser}
}
func (a *API) app() *app.App {

View File

@ -8,7 +8,9 @@ import (
"log"
"net/http"
"strings"
"time"
"github.com/mattermost/mattermost-octo-tasks/server/model"
"github.com/mattermost/mattermost-octo-tasks/server/services/auth"
)
@ -109,6 +111,20 @@ func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
func (a *API) sessionRequired(handler func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if a.singleUser {
now := time.Now().Unix()
session := &model.Session{
ID: "single-user",
Token: "single-user",
UserID: "single-user",
CreateAt: now,
UpdateAt: now,
}
ctx := context.WithValue(r.Context(), "session", session)
handler(w, r.WithContext(ctx))
return
}
token, _ := auth.ParseAuthTokenFromRequest(r)
session, err := a.app().GetSession(token)
if err != nil {

View File

@ -56,6 +56,10 @@ func main() {
// Command line args
pMonitorPid := flag.Int("monitorpid", -1, "a process ID")
pPort := flag.Int("port", config.Port, "the port number")
singleUser := false
if pSingleUser := flag.Bool("single-user", false, "single user mode"); pSingleUser != nil {
singleUser = *pSingleUser
}
flag.Parse()
if pMonitorPid != nil && *pMonitorPid > 0 {
@ -68,7 +72,7 @@ func main() {
config.Port = *pPort
}
server, err := server.New(config)
server, err := server.New(config, singleUser)
if err != nil {
log.Fatal("ListenAndServeTLS: ", err)
}

View File

@ -15,8 +15,10 @@ type User struct {
}
type Session struct {
ID string `json:"id"`
Token string `json:"token"`
UserID string `json:"user_id"`
Props map[string]interface{} `json:"props"`
ID string `json:"id"`
Token string `json:"token"`
UserID string `json:"user_id"`
Props map[string]interface{} `json:"props"`
CreateAt int64 `json:"create_at,omitempty"`
UpdateAt int64 `json:"update_at,omitempty"`
}

View File

@ -35,7 +35,7 @@ type Server struct {
logger *zap.Logger
}
func New(cfg *config.Configuration) (*Server, error) {
func New(cfg *config.Configuration, singleUser bool) (*Server, error) {
logger, err := zap.NewProduction()
if err != nil {
return nil, err
@ -63,7 +63,7 @@ func New(cfg *config.Configuration) (*Server, error) {
webhookClient := webhook.NewClient(cfg)
appBuilder := func() *app.App { return app.New(cfg, store, wsServer, filesBackend, webhookClient) }
api := api.NewAPI(appBuilder)
api := api.NewAPI(appBuilder, singleUser)
webServer := web.NewServer(cfg.WebPath, cfg.Port, cfg.UseSSL)
webServer.AddRoutes(wsServer)

View File

@ -12,7 +12,7 @@ import (
func runOctoTasks(ctx context.Context) *exec.Cmd {
// cmd := exec.CommandContext(ctx, "bin/octoserver.exe", "--monitorpid", strconv.FormatInt(int64(os.Getpid()), 10))
cmd := exec.CommandContext(ctx, "bin/octoserver.exe")
cmd := exec.CommandContext(ctx, "bin/octoserver.exe --single-user")
// cmd := exec.CommandContext(ctx, "cmd.exe", "/C", "start", "./bin/octoserver.exe", "--monitorpid", strconv.FormatInt(int64(os.Getpid()), 10))
// cmd := exec.CommandContext(ctx, "cmd.exe", "/C", "start", "./bin/octoserver.exe")