feature: Basic auth support with fission router (#2292)

This commit is contained in:
Pradeep Lakshmi Narasimha
2022-02-01 19:40:40 +05:30
committed by GitHub
parent 4b307be939
commit 590eefaa52
18 changed files with 466 additions and 6 deletions
+7
View File
@@ -18,6 +18,7 @@ package function
import (
"context"
"fmt"
"io"
"net/http"
"net/url"
@@ -178,6 +179,11 @@ func doHTTPRequest(ctx context.Context, url string, headers []string, method, bo
return nil, errors.Wrap(err, "error creating HTTP request")
}
accesstoken, ok := os.LookupEnv(util.FISSION_AUTH_TOKEN)
if ok && len(accesstoken) != 0 {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %v", accesstoken))
}
for _, header := range headers {
headerKeyValue := strings.SplitN(header, ":", 2)
if len(headerKeyValue) != 2 {
@@ -185,6 +191,7 @@ func doHTTPRequest(ctx context.Context, url string, headers []string, method, bo
}
req.Header.Set(headerKeyValue[0], headerKeyValue[1])
}
hc := &http.Client{Transport: otelhttp.NewTransport(http.DefaultTransport)}
resp, err := hc.Do(req.WithContext(ctx))
if err != nil {