Skip to content

Commit

Permalink
Implement --debug-global flag & dbus api
Browse files Browse the repository at this point in the history
  • Loading branch information
mikroskeem committed Oct 2, 2022
1 parent 955a3cf commit 73d7212
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/syringe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ func main() {
"SYRINGE_DEBUG",
},
},
&cli.BoolFlag{
Name: "debug-global",
Usage: "Whether to enable debug logging for all Syringe clients. Useful only when dbus is enabled",
Value: false,
EnvVars: []string{
"SYRINGE_DEBUG_GLOBAL",
},
},
},
Commands: []*cli.Command{
{
Expand Down Expand Up @@ -68,7 +76,7 @@ func main() {
},
},
Before: func(cctx *cli.Context) (err error) {
if err = setupLogging(cctx.Bool("debug")); err != nil {
if err = setupLogging(cctx.Bool("debug") || cctx.Bool("debug-global")); err != nil {
return
}

Expand Down
1 change: 1 addition & 0 deletions cmd/syringe/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func serverEntrypoint(clictx *cli.Context) (err error) {
cctx.WithVaultClient(vault),
cctx.WithTemplateMap(tm),
cctx.WithSocketPaths(socketPaths),
cctx.WithGlobalDebug(clictx.Bool("debug-global")),
)

if clictx.Bool("dbus") {
Expand Down
11 changes: 11 additions & 0 deletions internal/ctx/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ func SocketPaths(ctx context.Context) (v []string) {
v = ctx.Value(socketPath).([]string)
return
}

func WithGlobalDebug(gd bool) ContextValueFunc {
return func(ctx context.Context) context.Context {
return context.WithValue(ctx, globalDebug, gd)
}
}

func GlobalDebug(ctx context.Context) (v bool) {
v = ctx.Value(globalDebug).(bool)
return
}
1 change: 1 addition & 0 deletions internal/ctx/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ var (
credentialReqUnit contextValue = "ctx:cru"
credentialReqCred contextValue = "ctx:crc"
socketPath contextValue = "ctx:sp"
globalDebug contextValue = "ctx:gd"
)
10 changes: 10 additions & 0 deletions internal/dbus/syringe_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const intro = introspect.IntrospectDeclarationString + `
<doc:doc><doc:summary>Path to the Unix sockets where Syringe is currently listening on</doc:summary></doc:doc>
</arg>
</method>
<method name="GetGlobalDebug">
<arg direction="out" type="ab">
<doc:doc><doc:summary>Whether global debugging is enabled</doc:summary></doc:doc>
</arg>
</method>
</interface>
` + introspect.IntrospectDataString + `
</node>
Expand All @@ -39,6 +44,11 @@ func (s *syringeService) GetSocketPaths() (v []string, err *dbus.Error) {
return
}

func (s *syringeService) GetGlobalDebug() (v bool, err *dbus.Error) {
v = cctx.GlobalDebug(s.ctx)
return
}

func RegisterSyringeService(ctx context.Context) (err error) {
var conn *dbus.Conn

Expand Down

0 comments on commit 73d7212

Please sign in to comment.