More work on auth
This commit is contained in:
parent
7382f9c55c
commit
99cefc5356
8 changed files with 35 additions and 12 deletions
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func runOctoTasks(ctx context.Context) {
|
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
|
cmd.Stdout = os.Stdout
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -80,7 +80,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
NSLog("pid: \(pid)")
|
NSLog("pid: \(pid)")
|
||||||
let serverProcess = Process()
|
let serverProcess = Process()
|
||||||
serverProcess.currentDirectoryPath = cwdUrl.path
|
serverProcess.currentDirectoryPath = cwdUrl.path
|
||||||
serverProcess.arguments = ["-monitorpid", "\(pid)", "-port", "\(serverPort)"]
|
serverProcess.arguments = ["-monitorpid", "\(pid)", "-port", "\(serverPort)", "--single-user"]
|
||||||
serverProcess.launchPath = executablePath
|
serverProcess.launchPath = executablePath
|
||||||
serverProcess.launch()
|
serverProcess.launch()
|
||||||
self.serverProcess = serverProcess
|
self.serverProcess = serverProcess
|
||||||
|
|
|
@ -21,10 +21,11 @@ import (
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
appBuilder func() *app.App
|
appBuilder func() *app.App
|
||||||
|
singleUser bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAPI(appBuilder func() *app.App) *API {
|
func NewAPI(appBuilder func() *app.App, singleUser bool) *API {
|
||||||
return &API{appBuilder: appBuilder}
|
return &API{appBuilder: appBuilder, singleUser: singleUser}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) app() *app.App {
|
func (a *API) app() *app.App {
|
||||||
|
|
|
@ -8,7 +8,9 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-octo-tasks/server/model"
|
||||||
"github.com/mattermost/mattermost-octo-tasks/server/services/auth"
|
"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) {
|
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) {
|
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)
|
token, _ := auth.ParseAuthTokenFromRequest(r)
|
||||||
session, err := a.app().GetSession(token)
|
session, err := a.app().GetSession(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -56,6 +56,10 @@ func main() {
|
||||||
// Command line args
|
// Command line args
|
||||||
pMonitorPid := flag.Int("monitorpid", -1, "a process ID")
|
pMonitorPid := flag.Int("monitorpid", -1, "a process ID")
|
||||||
pPort := flag.Int("port", config.Port, "the port number")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
if pMonitorPid != nil && *pMonitorPid > 0 {
|
if pMonitorPid != nil && *pMonitorPid > 0 {
|
||||||
|
@ -68,7 +72,7 @@ func main() {
|
||||||
config.Port = *pPort
|
config.Port = *pPort
|
||||||
}
|
}
|
||||||
|
|
||||||
server, err := server.New(config)
|
server, err := server.New(config, singleUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("ListenAndServeTLS: ", err)
|
log.Fatal("ListenAndServeTLS: ", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,6 @@ type Session struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
Props map[string]interface{} `json:"props"`
|
Props map[string]interface{} `json:"props"`
|
||||||
|
CreateAt int64 `json:"create_at,omitempty"`
|
||||||
|
UpdateAt int64 `json:"update_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ type Server struct {
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *config.Configuration) (*Server, error) {
|
func New(cfg *config.Configuration, singleUser bool) (*Server, error) {
|
||||||
logger, err := zap.NewProduction()
|
logger, err := zap.NewProduction()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -63,7 +63,7 @@ func New(cfg *config.Configuration) (*Server, error) {
|
||||||
webhookClient := webhook.NewClient(cfg)
|
webhookClient := webhook.NewClient(cfg)
|
||||||
|
|
||||||
appBuilder := func() *app.App { return app.New(cfg, store, wsServer, filesBackend, webhookClient) }
|
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 := web.NewServer(cfg.WebPath, cfg.Port, cfg.UseSSL)
|
||||||
webServer.AddRoutes(wsServer)
|
webServer.AddRoutes(wsServer)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
func runOctoTasks(ctx context.Context) *exec.Cmd {
|
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", "--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", "--monitorpid", strconv.FormatInt(int64(os.Getpid()), 10))
|
||||||
// cmd := exec.CommandContext(ctx, "cmd.exe", "/C", "start", "./bin/octoserver.exe")
|
// cmd := exec.CommandContext(ctx, "cmd.exe", "/C", "start", "./bin/octoserver.exe")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue