Skip to content

Commit

Permalink
save working
Browse files Browse the repository at this point in the history
  • Loading branch information
robertvolkmann committed Mar 7, 2025
1 parent a6e0f7c commit 11b9460
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions metal.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package metalgo

import (
"crypto/tls"
"fmt"
"net/http"
"net/url"
"time"

"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"

"github.com/metal-stack/metal-go/api/client"
"github.com/metal-stack/metal-go/api/client/audit"
"github.com/metal-stack/metal-go/api/client/filesystemlayout"
Expand Down Expand Up @@ -69,13 +72,43 @@ type option func(driver *driver)

// AuthType sets the authType for HMAC-Auth
func AuthType(authType string) option {
return func(transport *httptransport.Runtime) {
transport.DefaultAuthentication = authType
}
}

func BearerToken(bearer string) option {
return func(driver *driver) {
if bearer != "" {
transport.DefaultAuthentication = runtime.ClientAuthInfoWriterFunc(func(request runtime.ClientRequest, registry strfmt.Registry) error {
security.AddUserTokenToClientRequest(request, bearer)
return nil
})
}
}
}

func HMACAuth(hmac, authType string) option {
return func(driver *driver) {
driver.hmacAuthType = authType
if hmac != "" {
auth := security.NewHMACAuth(driver.hmacAuthType, []byte(hmac))

transport.DefaultAuthentication = runtime.ClientAuthInfoWriterFunc(func(request runtime.ClientRequest, registry strfmt.Registry) error {
auth.AddAuthToClientRequest(request, time.Now())
return nil
})
}
}
}

func Transport(cfg *tls.Config) option {
return func(transport *httptransport.Runtime) {
transport.Transport = Transport
}
}

// NewDriver Create a new Driver for Metal to given url. Either bearer OR hmacKey must be set.
// The returned *Driver will be deprecated at some point in time, please migrate to use the Client interface instead.
// Deprecated: Use NewClient instead
func NewDriver(baseURL, bearer, hmacKey string, options ...option) (Client, error) {
parsedURL, err := url.Parse(baseURL)
if err != nil {
Expand All @@ -86,6 +119,7 @@ func NewDriver(baseURL, bearer, hmacKey string, options ...option) (Client, erro
}

transport := httptransport.New(parsedURL.Host, parsedURL.Path, []string{parsedURL.Scheme})
transport.Transport = ...

Check failure on line 122 in metal.go

View workflow job for this annotation

GitHub Actions / Build

expected operand, found '...' (typecheck)

Check failure on line 122 in metal.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected ..., expected expression

Check failure on line 122 in metal.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected ..., expected expression
c := client.New(transport, strfmt.Default)

Check failure on line 123 in metal.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected ) at end of statement (typecheck)

Check failure on line 123 in metal.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected ) at end of statement) (typecheck)

driver := &driver{
Expand All @@ -105,9 +139,11 @@ func NewDriver(baseURL, bearer, hmacKey string, options ...option) (Client, erro

transport.DefaultAuthentication = runtime.ClientAuthInfoWriterFunc(driver.auther)

// TODO: remove *Driver return at some point in the future in order to get rid off the handwritten wrappers
// see: https://github.com/metal-stack/metal-go/issues/33
return driver, nil
return c, nil
}

func NewClient(baseURL string, options ...option) (Client, error) {

}

func (d *driver) auther(rq runtime.ClientRequest, rg strfmt.Registry) error {
Expand Down

0 comments on commit 11b9460

Please sign in to comment.