Skip to content

Commit

Permalink
Better enterprise integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jespino committed Mar 29, 2021
1 parent 94a1a16 commit a8d3d98
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ coverage
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Enterprise files
server/main/imports.go
server/enterprise

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules
Expand Down
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,35 @@ ifeq ($(BUILD_NUMBER),)
BUILD_NUMBER := dev
endif

BUILD_ENTERPRISE_DIR ?= ../focalboard-enterprise
BUILD_ENTERPRISE ?= true
BUILD_ENTERPRISE_READY = false
BUILD_TYPE_NAME = team
BUILD_HASH_ENTERPRISE = none
ifneq ($(wildcard $(BUILD_ENTERPRISE_DIR)/.),)
ifeq ($(BUILD_ENTERPRISE),true)
BUILD_ENTERPRISE_READY = true
BUILD_TYPE_NAME = enterprise
BUILD_HASH_ENTERPRISE = $(shell cd $(BUILD_ENTERPRISE_DIR) && git rev-parse HEAD)
else
BUILD_ENTERPRISE_READY = false
BUILD_TYPE_NAME = team
endif
else
BUILD_ENTERPRISE_READY = false
BUILD_TYPE_NAME = team
endif

ifeq ($(BUILD_ENTERPRISE_READY),true)
IGNORE:=$(shell echo Enterprise build selected, preparing)
IGNORE:=$(shell rm -f server/main/imports.go)
IGNORE:=$(shell cp $(BUILD_ENTERPRISE_DIR)/imports/imports.go server/main/)
IGNORE:=$(shell rm -f server/enterprise)
IGNORE:=$(shell ln -s ../$(BUILD_ENTERPRISE_DIR) server/enterprise)
else
IGNORE:=$(shell rm -f server/main/imports.go)
endif

LDFLAGS += -X "github.com/mattermost/focalboard/server/model.BuildNumber=$(BUILD_NUMBER)"
LDFLAGS += -X "github.com/mattermost/focalboard/server/model.BuildDate=$(BUILD_DATE)"
LDFLAGS += -X "github.com/mattermost/focalboard/server/model.BuildHash=$(BUILD_HASH)"
Expand Down
6 changes: 5 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
"session_refresh_time": 18000,
"localOnly": false,
"enableLocalMode": true,
"localModeSocketLocation": "/var/tmp/focalboard_local.socket"
"localModeSocketLocation": "/var/tmp/focalboard_local.socket",
"authMode": "native",
"mattermostURL": "",
"mattermostClientID": "",
"mattermostClientSecret": ""
}
25 changes: 25 additions & 0 deletions server/einterfaces/einterfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package einterfaces

import (
"github.com/gorilla/mux"
"github.com/mattermost/focalboard/server/model"
)

type MattermostAuth interface {
RegisterRoutes(*mux.Router)
DoesUserHaveWorkspaceAccess(session *model.Session, workspaceID string) bool
}

type MattermostAuthParameters struct {
ServerRoot string
MattermostURL string
ClientID string
ClientSecret string
UseSecureCookie bool
}

type MattermostAuthStore interface {
GetUserById(userID string) (*model.User, error)
CreateUser(user *model.User) error
CreateSession(session *model.Session) error
}
1 change: 1 addition & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/tidwall/gjson v1.7.3 // indirect
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.0.0-20210324051608-47abb6519492 // indirect
google.golang.org/grpc v1.35.0
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
Expand Down
11 changes: 11 additions & 0 deletions server/server/enterprise.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package server

import (
"github.com/mattermost/focalboard/server/einterfaces"
)

var mattermostAuth func(einterfaces.MattermostAuthParameters, einterfaces.MattermostAuthStore) einterfaces.MattermostAuth

func RegisterMattermostAuth(f func(einterfaces.MattermostAuthParameters, einterfaces.MattermostAuthStore) einterfaces.MattermostAuth) {
mattermostAuth = f
}
24 changes: 23 additions & 1 deletion server/server/initHandlers.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
package server

import (
"log"

"github.com/mattermost/focalboard/server/einterfaces"
)

func (s *Server) initHandlers() {
// Additional init handlers go here
cfg := s.config
if cfg.AuthMode == "mattermost" && mattermostAuth != nil {
log.Println("Using Mattermost Auth")
params := einterfaces.MattermostAuthParameters{
ServerRoot: cfg.ServerRoot,
MattermostURL: cfg.MattermostURL,
ClientID: cfg.MattermostClientID,
ClientSecret: cfg.MattermostClientSecret,
UseSecureCookie: cfg.SecureCookie,
}
mmauthHandler := mattermostAuth(params, s.store)
log.Println("CREATING AUTH")
s.webServer.AddRoutes(mmauthHandler)
log.Println("ADDING ROUTES")
s.api.WorkspaceAuthenticator = mmauthHandler
log.Println("SETTING THE AUTHENTICATOR")
}
}

0 comments on commit a8d3d98

Please sign in to comment.