Skip to content

Commit

Permalink
chore: Rename internal constructors s/provider/transport
Browse files Browse the repository at this point in the history
  • Loading branch information
flowchartsman committed Jul 27, 2023
1 parent 3b08231 commit 756acd8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions client_auth_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ func AuthProviderPlugin(pluginName string, authParams string) AuthProvider {
if err := unmarshalParams(authParams, params); err != nil {
return nil, err
}
return auth.NewTLSProvider(params.TLSCertFile, params.TLSKeyFile, transport)
return auth.NewTLSTransport(params.TLSCertFile, params.TLSKeyFile, transport)
}
// also supports KV
return auth.NewTLSProviderFromKV(authParams, transport)
return auth.NewTLSTransportFromKV(authParams, transport)
case AuthPluginToken, AuthPluginClassToken:
params := &AuthParamsToken{}
if seemsJSON(authParams) {
if err := unmarshalParams(authParams, params); err != nil {
return nil, err
}
return auth.NewTokenProvider(params.Token, transport)
return auth.NewTokenTransport(params.Token, transport)
}
// also supports KV
return auth.NewTokenProviderFromKV(authParams, transport)
return auth.NewTokenTransportFromKV(authParams, transport)
case AuthPluginOAuth2, AuthPluginClassOAuth2:
params := &AuthParamsOAuth2{}
if err := unmarshalParams(authParams, params); err != nil {
Expand Down Expand Up @@ -78,7 +78,7 @@ type AuthParamsTLS struct {
// TLS certificate and key file.
func AuthProviderTLS(certFile, keyFile string) AuthProvider {
return func(transport *http.Transport) (http.RoundTripper, error) {
return auth.NewTLSProvider(certFile, keyFile, transport)
return auth.NewTLSTransport(certFile, keyFile, transport)
}
}

Expand Down Expand Up @@ -117,15 +117,15 @@ type AuthParamsToken struct {
// token data.
func AuthProviderToken(token string) AuthProvider {
return func(transport *http.Transport) (http.RoundTripper, error) {
return auth.NewTokenProvider(token, transport)
return auth.NewTokenTransport(token, transport)
}
}

// AuthProviderTokenFile returns a token-based authentication provider from a
// token stored in a file.
func AuthProviderTokenFile(tokenPath string) AuthProvider {
return func(transport *http.Transport) (http.RoundTripper, error) {
return auth.NewTokenProviderFromFile(tokenPath, transport)
return auth.NewTokenTransportFromFile(tokenPath, transport)
}
}

Expand Down
8 changes: 4 additions & 4 deletions internal/auth/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type TLSTransport struct {
T http.RoundTripper
}

// NewTLSProvider initialize the authentication provider
func NewTLSProvider(certificatePath string, privateKeyPath string, transport *http.Transport) (*TLSTransport, error) {
// NewTLSTransport initialize the authentication provider
func NewTLSTransport(certificatePath string, privateKeyPath string, transport *http.Transport) (*TLSTransport, error) {
switch {
case certificatePath == "":
return nil, errors.New("certificate path required")
Expand All @@ -51,7 +51,7 @@ func NewTLSProvider(certificatePath string, privateKeyPath string, transport *ht
}, nil
}

func NewTLSProviderFromKV(paramString string, transport *http.Transport) (*TLSTransport, error) {
func NewTLSTransportFromKV(paramString string, transport *http.Transport) (*TLSTransport, error) {
var (
certificatePath string
privateKeyPath string
Expand All @@ -69,7 +69,7 @@ func NewTLSProviderFromKV(paramString string, transport *http.Transport) (*TLSTr
if certificatePath == "" && privateKeyPath == "" {
return nil, errors.New(`TLS auth params must be in the form of "tlsCertFile:<path>,tlsKeyFile:<path>"`)
}
return NewTLSProvider(certificatePath, privateKeyPath, transport)
return NewTLSTransport(certificatePath, privateKeyPath, transport)
}

func (p *TLSTransport) RoundTrip(req *http.Request) (*http.Response, error) {
Expand Down
14 changes: 7 additions & 7 deletions internal/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type TokenTransport struct {
T http.RoundTripper
}

func NewTokenProvider(tokenData string, transport *http.Transport) (*TokenTransport, error) {
func NewTokenTransport(tokenData string, transport *http.Transport) (*TokenTransport, error) {
tokenData = strings.TrimSpace(tokenData)
if len(tokenData) == 0 {
return nil, errors.New("empty token")
Expand All @@ -47,28 +47,28 @@ func NewTokenProvider(tokenData string, transport *http.Transport) (*TokenTransp
}, nil
}

func NewTokenProviderFromKV(paramString string, transport *http.Transport) (*TokenTransport, error) {
func NewTokenTransportFromKV(paramString string, transport *http.Transport) (*TokenTransport, error) {
switch {
case strings.HasPrefix(paramString, tokenPrefix):
token := paramString[len(tokenPrefix):]
return NewTokenProvider(token, transport)
return NewTokenTransport(token, transport)
case strings.HasPrefix(paramString, filePrefix):
tokenFile := paramString[len(filePrefix):]
return NewTokenProviderFromFile(tokenFile, transport)
return NewTokenTransportFromFile(tokenFile, transport)
default:
return NewTokenProvider(paramString, transport)
return NewTokenTransport(paramString, transport)
}
}

func NewTokenProviderFromFile(tokenPath string, transport *http.Transport) (*TokenTransport, error) {
func NewTokenTransportFromFile(tokenPath string, transport *http.Transport) (*TokenTransport, error) {
fileContents, err := os.ReadFile(tokenPath)
if err != nil {
if os.IsNotExist(err) {
return nil, errors.New("token file not found")
}
return nil, fmt.Errorf("unable to open token file: %v", err)
}
return NewTokenProvider(string(fileContents), transport)
return NewTokenTransport(string(fileContents), transport)
}

func (p *TokenTransport) RoundTrip(req *http.Request) (*http.Response, error) {
Expand Down

0 comments on commit 756acd8

Please sign in to comment.