Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add openziti to core contracts #876

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clients/doc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package clients
5 changes: 5 additions & 0 deletions clients/http/authinjector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ func (_ *emptyAuthenticationInjector) AddAuthenticationData(_ *http.Request) err
// Do nothing to the request; used for unit tests
return nil
}

func (_ *emptyAuthenticationInjector) RoundTripper() http.RoundTripper {
// Do nothing to the request; used for unit tests
return nil
}
3 changes: 2 additions & 1 deletion clients/http/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func makeRequest(req *http.Request, authInjector interfaces.AuthenticationInject
}
}

client := &http.Client{}
client := &http.Client{Transport: authInjector.RoundTripper()}

resp, err := client.Do(req)
if err != nil {
return nil, errors.NewCommonEdgeX(errors.KindServiceUnavailable, "failed to send a http request", err)
Expand Down
10 changes: 9 additions & 1 deletion clients/interfaces/authinjector.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ import (
"net/http"
)

// AuthenticationInjector defines an interface to obtain a JWT for remote service calls
// AuthenticationInjector defines an interface to obtain a JWT and secure transport for remote service calls
type AuthenticationInjector interface {
// AddAuthenticationData mutates an HTTP request to add authentication data
// (suth as an Authorization: header) to an outbound HTTP request
AddAuthenticationData(_ *http.Request) error
// Returns the configured *http.Transport to use when making the request
SecureTransportProvider
}

// SecureTransportProvider defines an interface to obtain a secure http.Transport to use when making http requests
type SecureTransportProvider interface {
// Returns the configured *http.Transport to use when making the request
RoundTripper() http.RoundTripper
}