PrepareHttpRequest injects provider credentials into the supplied HTTP request.
(ctx context.Context, auth *Auth, req *http.Request)
| 5747 | |
| 5748 | // PrepareHttpRequest injects provider credentials into the supplied HTTP request. |
| 5749 | func (m *Manager) PrepareHttpRequest(ctx context.Context, auth *Auth, req *http.Request) error { |
| 5750 | if m == nil { |
| 5751 | return &Error{Code: "provider_not_found", Message: "manager is nil"} |
| 5752 | } |
| 5753 | if auth == nil { |
| 5754 | return &Error{Code: "auth_not_found", Message: "auth is nil"} |
| 5755 | } |
| 5756 | if req == nil { |
| 5757 | return &Error{Code: "invalid_request", Message: "http request is nil"} |
| 5758 | } |
| 5759 | if ctx != nil { |
| 5760 | *req = *req.WithContext(ctx) |
| 5761 | } |
| 5762 | providerKey := executorKeyFromAuth(auth) |
| 5763 | if providerKey == "" { |
| 5764 | return &Error{Code: "provider_not_found", Message: "auth provider is empty"} |
| 5765 | } |
| 5766 | exec := m.executorFor(providerKey) |
| 5767 | if exec == nil { |
| 5768 | return &Error{Code: "provider_not_found", Message: "executor not registered for provider: " + providerKey} |
| 5769 | } |
| 5770 | preparer, ok := exec.(RequestPreparer) |
| 5771 | if !ok || preparer == nil { |
| 5772 | return &Error{Code: "not_supported", Message: "executor does not support http request preparation"} |
| 5773 | } |
| 5774 | return preparer.PrepareRequest(req, auth) |
| 5775 | } |
| 5776 | |
| 5777 | // NewHttpRequest constructs a new HTTP request and injects provider credentials into it. |
| 5778 | func (m *Manager) NewHttpRequest(ctx context.Context, auth *Auth, method, targetURL string, body []byte, headers http.Header) (*http.Request, error) { |
no test coverage detected