Skip to content

Commit

Permalink
Add client helper.
Browse files Browse the repository at this point in the history
v0ctor committed Oct 17, 2023
1 parent 8de636b commit cd281fd
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
28 changes: 28 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -2,3 +2,31 @@ 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, opts ...ClientOption) (*Client, error) {
provider, err := securityprovider.NewSecurityProviderApiKey(
"header",
authHeaderName,
fmt.Sprintf(authHeaderFormat, token),
)

if err != nil {
return nil, err
}

opts = append(
opts,
WithRequestEditorFn(provider.Intercept),
)

return NewClient(host, opts...)
}

0 comments on commit cd281fd

Please sign in to comment.