Skip to content

Commit

Permalink
Merge branch 'main' of gitlab.autonubil.net:opsanio/go-wazuh
Browse files Browse the repository at this point in the history
  • Loading branch information
czeumer committed Jan 12, 2024
2 parents 664264a + 303bd66 commit 7db2a8c
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions rest/wazuh.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ type Client struct {
// the network.
RequestEditors []RequestEditorFn

ctx context.Context
userAgent string
token string
user string
password string
insecure bool
trace bool
ctx context.Context
userAgent string
token string
user string
password string
insecure bool
trace bool
proxyEnabled bool
proxyHost string
}

// HTTPRequestDoer performs HTTP requests.
Expand All @@ -120,6 +122,15 @@ func WithContext(ctx context.Context) ClientOption {
}
}

// WithProxy write all requests to the log
func WithProxy(enabled bool, host string) ClientOption {
return func(c *Client) error {
c.proxyEnabled = enabled
c.proxyHost = host
return nil
}
}

// WithInsecure accept all certificates
func WithInsecure(insecure bool) ClientOption {
return func(c *Client) error {
Expand Down Expand Up @@ -275,14 +286,23 @@ func NewClient(baseURL string, opts ...ClientOption) (*Client, error) {
}
// create httpClient, if not already present
c.Client = c
c.innerClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: c.insecure, // test server certificate is not trusted.
},
t := http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: c.insecure, // test server certificate is not trusted.
},
}

if !c.proxyEnabled {
t.Proxy = nil
} else if c.proxyHost != "" {
t.Proxy = func(*http.Request) (*url.URL, error) {
return url.Parse(c.proxyHost)
}
}
c.innerClient = &http.Client{
Transport: &t,
}

return c, nil
}

Expand Down Expand Up @@ -418,7 +438,7 @@ func (c *ClientWithResponses) RevokeAllTokens() error {
return nil
}

//Authenticate login using basic auth to optain a token
// Authenticate login using basic auth to optain a token
func (c *ClientWithResponses) Authenticate() error {
// Authenticate
c.ClientInterface.(*Client).token = ""
Expand Down

0 comments on commit 7db2a8c

Please sign in to comment.