@@ -3,12 +3,11 @@ package sysdig
33import (
44 "context"
55 "errors"
6+ "fmt"
67 "net/http"
78 "net/url"
89)
910
10- type SysdigAuthentication func (ctx context.Context , req * http.Request ) error
11-
1211type contextKey string
1312
1413const (
@@ -46,7 +45,7 @@ func updateReqWithHostURL(req *http.Request, host string) error {
4645 return nil
4746}
4847
49- func WithFixedHostAndToken (host , apiToken string ) SysdigAuthentication {
48+ func WithFixedHostAndToken (host , apiToken string ) RequestEditorFn {
5049 return func (ctx context.Context , req * http.Request ) error {
5150 if err := updateReqWithHostURL (req , host ); err != nil {
5251 return err
@@ -56,7 +55,7 @@ func WithFixedHostAndToken(host, apiToken string) SysdigAuthentication {
5655 }
5756}
5857
59- func WithHostAndTokenFromContext () SysdigAuthentication {
58+ func WithHostAndTokenFromContext () RequestEditorFn {
6059 return func (ctx context.Context , req * http.Request ) error {
6160 if host , ok := ctx .Value (contextKeyHost ).(string ); ok && host != "" {
6261 if err := updateReqWithHostURL (req , host ); err != nil {
@@ -71,7 +70,7 @@ func WithHostAndTokenFromContext() SysdigAuthentication {
7170 }
7271}
7372
74- func WithFallbackAuthentication (auths ... SysdigAuthentication ) SysdigAuthentication {
73+ func WithFallbackAuthentication (auths ... RequestEditorFn ) RequestEditorFn {
7574 return func (ctx context.Context , req * http.Request ) error {
7675 for _ , auth := range auths {
7776 if err := auth (ctx , req ); err == nil {
@@ -82,10 +81,17 @@ func WithFallbackAuthentication(auths ...SysdigAuthentication) SysdigAuthenticat
8281 }
8382}
8483
85- func NewSysdigClient (requestEditors ... SysdigAuthentication ) (ExtendedClientWithResponsesInterface , error ) {
84+ func WithVersion (version string ) RequestEditorFn {
85+ return func (ctx context.Context , req * http.Request ) error {
86+ req .Header .Set ("User-Agent" , fmt .Sprintf ("sysdig-mcp-server/%s" , version ))
87+ return nil
88+ }
89+ }
90+
91+ func NewSysdigClient (requestEditors ... RequestEditorFn ) (ExtendedClientWithResponsesInterface , error ) {
8692 editors := make ([]ClientOption , len (requestEditors ))
8793 for i , e := range requestEditors {
88- editors [i ] = WithRequestEditorFn (RequestEditorFn ( e ) )
94+ editors [i ] = WithRequestEditorFn (e )
8995 }
9096
9197 return NewClientWithResponses ("" , editors ... )
0 commit comments