Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func setupLogger(logLevel string) {

func setupSysdigClient(cfg *config.Config) (sysdig.ExtendedClientWithResponsesInterface, error) {
sysdigClient, err := sysdig.NewSysdigClient(
sysdig.WithVersion(Version),
sysdig.WithFallbackAuthentication(
sysdig.WithHostAndTokenFromContext(),
sysdig.WithFixedHostAndToken(cfg.APIHost, cfg.APIToken),
Expand Down
20 changes: 13 additions & 7 deletions internal/infra/sysdig/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package sysdig
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
)

type SysdigAuthentication func(ctx context.Context, req *http.Request) error

type contextKey string

const (
Expand Down Expand Up @@ -46,7 +45,7 @@ func updateReqWithHostURL(req *http.Request, host string) error {
return nil
}

func WithFixedHostAndToken(host, apiToken string) SysdigAuthentication {
func WithFixedHostAndToken(host, apiToken string) RequestEditorFn {
return func(ctx context.Context, req *http.Request) error {
if err := updateReqWithHostURL(req, host); err != nil {
return err
Expand All @@ -56,7 +55,7 @@ func WithFixedHostAndToken(host, apiToken string) SysdigAuthentication {
}
}

func WithHostAndTokenFromContext() SysdigAuthentication {
func WithHostAndTokenFromContext() RequestEditorFn {
return func(ctx context.Context, req *http.Request) error {
if host, ok := ctx.Value(contextKeyHost).(string); ok && host != "" {
if err := updateReqWithHostURL(req, host); err != nil {
Expand All @@ -71,7 +70,7 @@ func WithHostAndTokenFromContext() SysdigAuthentication {
}
}

func WithFallbackAuthentication(auths ...SysdigAuthentication) SysdigAuthentication {
func WithFallbackAuthentication(auths ...RequestEditorFn) RequestEditorFn {
return func(ctx context.Context, req *http.Request) error {
for _, auth := range auths {
if err := auth(ctx, req); err == nil {
Expand All @@ -82,10 +81,17 @@ func WithFallbackAuthentication(auths ...SysdigAuthentication) SysdigAuthenticat
}
}

func NewSysdigClient(requestEditors ...SysdigAuthentication) (ExtendedClientWithResponsesInterface, error) {
func WithVersion(version string) RequestEditorFn {
return func(ctx context.Context, req *http.Request) error {
req.Header.Set("User-Agent", fmt.Sprintf("sysdig-mcp-server/%s", version))
return nil
}
}

func NewSysdigClient(requestEditors ...RequestEditorFn) (ExtendedClientWithResponsesInterface, error) {
editors := make([]ClientOption, len(requestEditors))
for i, e := range requestEditors {
editors[i] = WithRequestEditorFn(RequestEditorFn(e))
editors[i] = WithRequestEditorFn(e)
}

return NewClientWithResponses("", editors...)
Expand Down
2 changes: 1 addition & 1 deletion package.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ buildGoModule, versionCheckHook }:
buildGoModule (finalAttrs: {
pname = "sysdig-mcp-server";
version = "0.5.3";
version = "0.5.4";
src = ./.;
# This hash is automatically re-calculated with `just rehash-package-nix`. This is automatically called as well by `just bump`.
vendorHash = "sha256-jf/px0p88XbfuSPMry/qZcfR0QPTF9IrPegg2CwAd6M=";
Expand Down
Loading