Skip to content

Commit

Permalink
plugin logs
Browse files Browse the repository at this point in the history
  • Loading branch information
hummerdmag committed Aug 26, 2024
1 parent 4891606 commit 1f4a461
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*.out
vendor
db.db
db_plugin.db
shared-local-instance.db
debug
*__debug_bin
Expand Down
7 changes: 6 additions & 1 deletion cmd/config-boltdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ storage:
type: boltdb
boltdb:
path: ./db.db
userStorage: *storage_settings
userStorage:
type: plugin
plugin:
cmd: ./plugins/bin/bolt-user-storage
params: { "path": "./db_plugin.db" }
redirectStd: true
tokenStorage: *storage_settings
tokenBlacklist: *storage_settings
verificationCodeStorage: *storage_settings
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/sessions v1.2.1
github.com/hashicorp/go-hclog v0.14.1
github.com/hashicorp/go-plugin v1.4.5
github.com/hummerd/httpdump v0.9.1
github.com/joho/godotenv v1.4.0
Expand Down Expand Up @@ -70,7 +71,6 @@ require (
github.com/golang/snappy v0.0.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/hashicorp/go-hclog v0.14.1 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.13.6 // indirect
Expand Down
6 changes: 5 additions & 1 deletion impersonation/plugin/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"os/exec"
"time"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
grpcShared "github.com/madappgang/identifo/v2/impersonation/grpc/shared"
"github.com/madappgang/identifo/v2/impersonation/plugin/shared"
"github.com/madappgang/identifo/v2/model"
)

func NewImpersonationProvider(settings model.PluginSettings, timeout time.Duration) (model.ImpersonationProvider, error) {
var err error
params := []string{}
for k, v := range settings.Params {
params = append(params, "-"+k)
Expand All @@ -24,6 +24,10 @@ func NewImpersonationProvider(settings model.PluginSettings, timeout time.Durati
Plugins: shared.PluginMap,
Cmd: exec.Command(settings.Cmd, params...),
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: hclog.New(&hclog.LoggerOptions{
Level: hclog.Debug,
JSONFormat: true,
}),
}

if settings.RedirectStd {
Expand Down
15 changes: 14 additions & 1 deletion plugins/bolt-user-storage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"log/slog"
"os"
"os/signal"
"syscall"
Expand All @@ -13,7 +14,20 @@ import (
"github.com/madappgang/identifo/v2/storage/plugin/shared"
)

type wproxy struct {
}

func (w wproxy) Write(p []byte) (n int, err error) {
return os.Stderr.Write(p)
}

func main() {
slog.SetDefault(slog.New(slog.NewJSONHandler(
wproxy{},
&slog.HandlerOptions{
Level: slog.LevelDebug,
})))

path := flag.String("path", "", "path to database")
flag.Parse()

Expand All @@ -34,7 +48,6 @@ func main() {
Plugins: map[string]plugin.Plugin{
"user-storage": &shared.UserStoragePlugin{Impl: s},
},

// A non-nil value here enables gRPC serving for this plugin...
GRPCServer: plugin.DefaultGRPCServer,
})
Expand Down
6 changes: 5 additions & 1 deletion storage/plugin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"os/exec"

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

// NewUserStorage creates and inits plugin user storage.
func NewUserStorage(settings model.PluginSettings) (model.UserStorage, error) {
var err error
params := []string{}
for k, v := range settings.Params {
params = append(params, "-"+k)
Expand All @@ -24,6 +24,10 @@ func NewUserStorage(settings model.PluginSettings) (model.UserStorage, error) {
Plugins: shared.PluginMap,
Cmd: exec.Command(settings.Cmd, params...),
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: hclog.New(&hclog.LoggerOptions{
Level: hclog.Debug,
JSONFormat: true,
}),
}

if settings.RedirectStd {
Expand Down
7 changes: 5 additions & 2 deletions user_payload_provider/plugin/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os/exec"
"time"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/madappgang/identifo/v2/model"
grpcShared "github.com/madappgang/identifo/v2/user_payload_provider/grpc/shared"
Expand All @@ -13,19 +14,21 @@ import (

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

cfg := &plugin.ClientConfig{
SyncStdout: os.Stdout,
HandshakeConfig: shared.Handshake,
Plugins: shared.PluginMap,
Cmd: exec.Command(settings.Cmd, params...),
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: hclog.New(&hclog.LoggerOptions{
Level: hclog.Debug,
JSONFormat: true,
}),
}

if settings.RedirectStd {
Expand Down
2 changes: 0 additions & 2 deletions web/api/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ func (ar *Router) HandlePing(w http.ResponseWriter, r *http.Request) {

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

ar.logger.Debug("trace pong handler")

pong := pongResponse{
Message: "Pong!",
Date: time.Now(),
Expand Down
10 changes: 6 additions & 4 deletions web/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ func (ar *Router) initRoutes(
panic("Empty API router")
}

pingHandler := negroni.New(
negroni.NewRecovery(),
negroni.WrapFunc(ar.HandlePing),
)
ar.router.Handle("/ping", pingHandler).Methods(http.MethodGet)

baseMiddleware := buildBaseMiddleware(
loggerSettings.DumpRequest,
loggerSettings.Format,
loggerSettings.API,
loggerSettings.LogSensitiveData,
ar.cors,
)

ph := with(baseMiddleware, negroni.WrapFunc(ar.HandlePing))
ar.router.Handle("/ping", ph).Methods(http.MethodGet)

apiMiddlewares := ar.buildAPIMiddleware(baseMiddleware)

// federated oidc
Expand Down

0 comments on commit 1f4a461

Please sign in to comment.