Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1409281
Share HTML template renderers and create a watcher framework
zeripath Jun 28, 2022
07dc4f2
placate lint
zeripath Jul 3, 2022
f265ce5
fix windows
zeripath Jul 3, 2022
726bf7c
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 4, 2022
aa90128
Init needs a ctx
zeripath Jul 4, 2022
0209fa4
make SSPI also share the templates too
zeripath Jul 4, 2022
a04e94a
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 5, 2022
7dd067b
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 6, 2022
f61f79c
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 9, 2022
cbdc8bc
use todo only
zeripath Jul 10, 2022
9e63150
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 12, 2022
1159e0f
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 12, 2022
959595b
Switch to use syncthing/notify instead of fsnotify/fsnotify
zeripath Jul 16, 2022
aca2416
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Jul 16, 2022
426eb8f
Revert "Switch to use syncthing/notify instead of fsnotify/fsnotify"
zeripath Jul 17, 2022
f3b8468
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Jul 31, 2022
eb8cf0f
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Aug 12, 2022
408a726
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Aug 22, 2022
ab27d13
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Aug 23, 2022
bfab646
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Aug 24, 2022
3841573
as per review
zeripath Aug 24, 2022
2dbfc50
Fix tests
zeripath Aug 24, 2022
0ff8921
placate lint
zeripath Aug 24, 2022
a442905
Merge branch 'main' into load-templates-once-and-better-reload
zeripath Aug 27, 2022
c5bdfef
Update modules/templates/htmlrenderer.go
zeripath Aug 27, 2022
55c4ec6
placate lint
zeripath Aug 27, 2022
f7a5cd7
as per wxiaoguang
zeripath Aug 28, 2022
aec5c2f
Merge remote-tracking branch 'origin/main' into load-templates-once-a…
zeripath Aug 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make SSPI also share the templates too
Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Jul 4, 2022
commit 0209fa416bb647d6d5185dbcf45f7a268781c074
5 changes: 3 additions & 2 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
package v1

import (
gocontext "context"
"fmt"
"net/http"
"reflect"
Expand Down Expand Up @@ -605,7 +606,7 @@ func buildAuthGroup() *auth.Group {
}

// Routes registers all v1 APIs routes to web application.
func Routes() *web.Route {
func Routes(ctx gocontext.Context) *web.Route {
m := web.NewRoute()

m.Use(securityHeaders())
Expand All @@ -623,7 +624,7 @@ func Routes() *web.Route {
m.Use(context.APIContexter())

group := buildAuthGroup()
if err := group.Init(); err != nil {
if err := group.Init(ctx); err != nil {
log.Error("Could not initialize '%s' auth method, error: %s", group.Name(), err)
}

Expand Down
2 changes: 1 addition & 1 deletion routers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func NormalRoutes(ctx context.Context) *web.Route {
}

r.Mount("/", web_routers.Routes(ctx))
r.Mount("/api/v1", apiv1.Routes())
r.Mount("/api/v1", apiv1.Routes(ctx))
r.Mount("/api/internal", private.Routes())
if setting.Packages.Enabled {
r.Mount("/api/packages", packages_router.Routes(ctx))
Expand Down
2 changes: 1 addition & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func Routes(ctx gocontext.Context) *web.Route {
common = append(common, context.Contexter(ctx))

group := buildAuthGroup()
if err := group.Init(); err != nil {
if err := group.Init(ctx); err != nil {
log.Error("Could not initialize '%s' auth method, error: %s", group.Name(), err)
}

Expand Down
5 changes: 3 additions & 2 deletions services/auth/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package auth

import (
"context"
"net/http"
"reflect"
"strings"
Expand Down Expand Up @@ -51,14 +52,14 @@ func (b *Group) Name() string {
}

// Init does nothing as the Basic implementation does not need to allocate any resources
func (b *Group) Init() error {
func (b *Group) Init(ctx context.Context) error {
for _, method := range b.methods {
initializable, ok := method.(Initializable)
if !ok {
continue
}

if err := initializable.Init(); err != nil {
if err := initializable.Init(ctx); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion services/auth/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Method interface {
type Initializable interface {
// Init should be called exactly once before using any of the other methods,
// in order to allow the plugin to allocate necessary resources
Init() error
Init(ctx context.Context) error
}

// Named represents a named thing
Expand Down
12 changes: 3 additions & 9 deletions services/auth/sspi_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package auth

import (
"context"
"errors"
"net/http"
"strings"
Expand Down Expand Up @@ -52,21 +53,14 @@ type SSPI struct {
}

// Init creates a new global websspi.Authenticator object
func (s *SSPI) Init() error {
func (s *SSPI) Init(ctx context.Context) error {
config := websspi.NewConfig()
var err error
sspiAuth, err = websspi.New(config)
if err != nil {
return err
}
s.rnd = render.New(render.Options{
Extensions: []string{".tmpl"},
Directory: "templates",
Funcs: templates.NewFuncMap(),
Asset: templates.GetAsset,
AssetNames: templates.GetTemplateAssetNames,
IsDevelopment: !setting.IsProd,
})
_, s.rnd = templates.HTMLRenderer(ctx)
return nil
}

Expand Down