Skip to content

Commit 1f4a461

Browse files
committed
plugin logs
1 parent 4891606 commit 1f4a461

File tree

9 files changed

+43
-13
lines changed

9 files changed

+43
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*.out
1515
vendor
1616
db.db
17+
db_plugin.db
1718
shared-local-instance.db
1819
debug
1920
*__debug_bin

cmd/config-boltdb.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ storage:
1111
type: boltdb
1212
boltdb:
1313
path: ./db.db
14-
userStorage: *storage_settings
14+
userStorage:
15+
type: plugin
16+
plugin:
17+
cmd: ./plugins/bin/bolt-user-storage
18+
params: { "path": "./db_plugin.db" }
19+
redirectStd: true
1520
tokenStorage: *storage_settings
1621
tokenBlacklist: *storage_settings
1722
verificationCodeStorage: *storage_settings

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/google/uuid v1.3.0
1717
github.com/gorilla/mux v1.8.0
1818
github.com/gorilla/sessions v1.2.1
19+
github.com/hashicorp/go-hclog v0.14.1
1920
github.com/hashicorp/go-plugin v1.4.5
2021
github.com/hummerd/httpdump v0.9.1
2122
github.com/joho/godotenv v1.4.0
@@ -70,7 +71,6 @@ require (
7071
github.com/golang/snappy v0.0.1 // indirect
7172
github.com/google/go-cmp v0.5.9 // indirect
7273
github.com/gorilla/securecookie v1.1.1 // indirect
73-
github.com/hashicorp/go-hclog v0.14.1 // indirect
7474
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
7575
github.com/jmespath/go-jmespath v0.4.0 // indirect
7676
github.com/klauspost/compress v1.13.6 // indirect

impersonation/plugin/provider.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
"os/exec"
66
"time"
77

8+
"github.com/hashicorp/go-hclog"
89
"github.com/hashicorp/go-plugin"
910
grpcShared "github.com/madappgang/identifo/v2/impersonation/grpc/shared"
1011
"github.com/madappgang/identifo/v2/impersonation/plugin/shared"
1112
"github.com/madappgang/identifo/v2/model"
1213
)
1314

1415
func NewImpersonationProvider(settings model.PluginSettings, timeout time.Duration) (model.ImpersonationProvider, error) {
15-
var err error
1616
params := []string{}
1717
for k, v := range settings.Params {
1818
params = append(params, "-"+k)
@@ -24,6 +24,10 @@ func NewImpersonationProvider(settings model.PluginSettings, timeout time.Durati
2424
Plugins: shared.PluginMap,
2525
Cmd: exec.Command(settings.Cmd, params...),
2626
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
27+
Logger: hclog.New(&hclog.LoggerOptions{
28+
Level: hclog.Debug,
29+
JSONFormat: true,
30+
}),
2731
}
2832

2933
if settings.RedirectStd {

plugins/bolt-user-storage/main.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"flag"
5+
"log/slog"
56
"os"
67
"os/signal"
78
"syscall"
@@ -13,7 +14,20 @@ import (
1314
"github.com/madappgang/identifo/v2/storage/plugin/shared"
1415
)
1516

17+
type wproxy struct {
18+
}
19+
20+
func (w wproxy) Write(p []byte) (n int, err error) {
21+
return os.Stderr.Write(p)
22+
}
23+
1624
func main() {
25+
slog.SetDefault(slog.New(slog.NewJSONHandler(
26+
wproxy{},
27+
&slog.HandlerOptions{
28+
Level: slog.LevelDebug,
29+
})))
30+
1731
path := flag.String("path", "", "path to database")
1832
flag.Parse()
1933

@@ -34,7 +48,6 @@ func main() {
3448
Plugins: map[string]plugin.Plugin{
3549
"user-storage": &shared.UserStoragePlugin{Impl: s},
3650
},
37-
3851
// A non-nil value here enables gRPC serving for this plugin...
3952
GRPCServer: plugin.DefaultGRPCServer,
4053
})

storage/plugin/user.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55
"os/exec"
66

7+
"github.com/hashicorp/go-hclog"
78
"github.com/hashicorp/go-plugin"
89
"github.com/madappgang/identifo/v2/model"
910
grpcShared "github.com/madappgang/identifo/v2/storage/grpc/shared"
@@ -12,7 +13,6 @@ import (
1213

1314
// NewUserStorage creates and inits plugin user storage.
1415
func NewUserStorage(settings model.PluginSettings) (model.UserStorage, error) {
15-
var err error
1616
params := []string{}
1717
for k, v := range settings.Params {
1818
params = append(params, "-"+k)
@@ -24,6 +24,10 @@ func NewUserStorage(settings model.PluginSettings) (model.UserStorage, error) {
2424
Plugins: shared.PluginMap,
2525
Cmd: exec.Command(settings.Cmd, params...),
2626
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
27+
Logger: hclog.New(&hclog.LoggerOptions{
28+
Level: hclog.Debug,
29+
JSONFormat: true,
30+
}),
2731
}
2832

2933
if settings.RedirectStd {

user_payload_provider/plugin/provider.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os/exec"
66
"time"
77

8+
"github.com/hashicorp/go-hclog"
89
"github.com/hashicorp/go-plugin"
910
"github.com/madappgang/identifo/v2/model"
1011
grpcShared "github.com/madappgang/identifo/v2/user_payload_provider/grpc/shared"
@@ -13,19 +14,21 @@ import (
1314

1415
// NewTokenPayloadProvider creates and inits plugin for payload provider.
1516
func NewTokenPayloadProvider(settings model.PluginSettings, timeout time.Duration) (model.TokenPayloadProvider, error) {
16-
var err error
1717
params := []string{}
1818
for k, v := range settings.Params {
1919
params = append(params, "-"+k)
2020
params = append(params, v)
2121
}
2222

2323
cfg := &plugin.ClientConfig{
24-
SyncStdout: os.Stdout,
2524
HandshakeConfig: shared.Handshake,
2625
Plugins: shared.PluginMap,
2726
Cmd: exec.Command(settings.Cmd, params...),
2827
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
28+
Logger: hclog.New(&hclog.LoggerOptions{
29+
Level: hclog.Debug,
30+
JSONFormat: true,
31+
}),
2932
}
3033

3134
if settings.RedirectStd {

web/api/hello.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ func (ar *Router) HandlePing(w http.ResponseWriter, r *http.Request) {
3434

3535
locale := r.Header.Get("Accept-Language")
3636

37-
ar.logger.Debug("trace pong handler")
38-
3937
pong := pongResponse{
4038
Message: "Pong!",
4139
Date: time.Now(),

web/api/routes.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ func (ar *Router) initRoutes(
1919
panic("Empty API router")
2020
}
2121

22+
pingHandler := negroni.New(
23+
negroni.NewRecovery(),
24+
negroni.WrapFunc(ar.HandlePing),
25+
)
26+
ar.router.Handle("/ping", pingHandler).Methods(http.MethodGet)
27+
2228
baseMiddleware := buildBaseMiddleware(
2329
loggerSettings.DumpRequest,
2430
loggerSettings.Format,
2531
loggerSettings.API,
2632
loggerSettings.LogSensitiveData,
2733
ar.cors,
2834
)
29-
30-
ph := with(baseMiddleware, negroni.WrapFunc(ar.HandlePing))
31-
ar.router.Handle("/ping", ph).Methods(http.MethodGet)
32-
3335
apiMiddlewares := ar.buildAPIMiddleware(baseMiddleware)
3436

3537
// federated oidc

0 commit comments

Comments
 (0)