Skip to content

Commit

Permalink
Add client helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
v0ctor committed Oct 17, 2023
1 parent 8de636b commit cc909b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/netbox-community/go-netbox/v3
go 1.21

require (
github.com/deepmap/oapi-codegen v1.15.0
github.com/oapi-codegen/runtime v1.0.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvF
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deepmap/oapi-codegen v1.15.0 h1:SQqViaeb4k2vMul8gx12oDOIadEtoRqTdLkxjzqtQ90=
github.com/deepmap/oapi-codegen v1.15.0/go.mod h1:a6KoHV7lMRwsPoEg2C6NDHiXYV3EQfiFocOlJ8dgJQE=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
Expand Down
26 changes: 26 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,29 @@ package netbox

//go:generate oapi-codegen -package netbox -generate types -o types.go api/openapi.yaml
//go:generate oapi-codegen -package netbox -generate client -o client.go api/openapi.yaml

import (
"fmt"

"github.com/deepmap/oapi-codegen/pkg/securityprovider"
)

const authHeaderName = "Authorization"
const authHeaderFormat = "Token %v"

func NewClientWithToken(host string, token string) (*ClientWithResponses, error) {
provider, err := securityprovider.NewSecurityProviderApiKey(
"header",
authHeaderName,
fmt.Sprintf(authHeaderFormat, token),
)

if err != nil {
return nil, err
}

return NewClientWithResponses(
host,
WithRequestEditorFn(provider.Intercept),
)
}

0 comments on commit cc909b7

Please sign in to comment.