Skip to content

Commit

Permalink
allow access to the underlying resty client (#76)
Browse files Browse the repository at this point in the history
* allow access to the underlying resty client

* Add generated changelog entries

---------

Co-authored-by: Armin <[email protected]>
Co-authored-by: svc-changelog <[email protected]>
  • Loading branch information
3 people authored Dec 8, 2023
1 parent c73650e commit 57d8779
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
28 changes: 28 additions & 0 deletions _examples/restyclient/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"crypto/tls"
"log"
"os"

"github.com/palantir/tenablesc-client/tenablesc"
)

func main() {
client := tenablesc.NewClient(
os.Getenv("TENABLE_URL"), // Tenable SC host. ensure the url has /rest in their path.
).SetAPIKey(
os.Getenv("TENABLE_ACCESS_KEY"), // Tenable SC access key.
os.Getenv("TENABLE_SECRET_KEY"), // Tenable SC secret key.
)

// Configuring the client's minimum TLS version to be TLS v1.2
client.RestyClient().SetTLSClientConfig(&tls.Config{
MinVersion: tls.VersionTLS12,
})

_, err := client.GetCurrentUser()
if err != nil {
log.Fatal(err)
}
}
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-76.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: allow access to the underlying resty client
links:
- https://github.com/palantir/tenablesc-client/pull/76
11 changes: 8 additions & 3 deletions tenablesc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ type response struct {
//
// Don't forget to SetAPIKey or SetBasicAuth to ensure you make credentialed queries.
func NewClient(baseURL string) *Client {

c := resty.New().
client := resty.New().
SetBaseURL(baseURL).
SetHeader(http.CanonicalHeaderKey("User-Agent"), DefaultUserAgent).
AddRetryCondition(defaultTenableRetryConditions)

return &Client{*c}
return &Client{*client}
}

// SetAPIKey adds the API Key header to all queries with the client.
Expand All @@ -58,6 +57,12 @@ func (c *Client) SetUserAgent(agent string) *Client {
return c
}

// RestyClient returns a pointer to the underlying resty.Client instance.
// This enables access to all the features and options provided by the resty library.
func (c *Client) RestyClient() *resty.Client {
return &c.client
}

func defaultTenableRetryConditions(resp *resty.Response, err error) bool {

// Assume internal server errors, gateway errors, and such are probably transient.
Expand Down

0 comments on commit 57d8779

Please sign in to comment.