mirror of
https://github.com/openfaas/faas.git
synced 2025-06-20 13:06:40 +00:00
Differentiate external service auth from user auth
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
@ -15,13 +15,13 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/openfaas/faas-provider/auth"
|
||||
"github.com/openfaas/faas/gateway/handlers"
|
||||
"github.com/openfaas/faas/gateway/requests"
|
||||
"github.com/openfaas/faas/gateway/scaling"
|
||||
)
|
||||
|
||||
// NewExternalServiceQuery proxies service queries to external plugin via HTTP
|
||||
func NewExternalServiceQuery(externalURL url.URL, credentials *auth.BasicAuthCredentials) scaling.ServiceQuery {
|
||||
func NewExternalServiceQuery(externalURL url.URL, authInjector handlers.AuthInjector) scaling.ServiceQuery {
|
||||
timeout := 3 * time.Second
|
||||
|
||||
proxyClient := http.Client{
|
||||
@ -39,17 +39,17 @@ func NewExternalServiceQuery(externalURL url.URL, credentials *auth.BasicAuthCre
|
||||
}
|
||||
|
||||
return ExternalServiceQuery{
|
||||
URL: externalURL,
|
||||
ProxyClient: proxyClient,
|
||||
Credentials: credentials,
|
||||
URL: externalURL,
|
||||
ProxyClient: proxyClient,
|
||||
AuthInjector: authInjector,
|
||||
}
|
||||
}
|
||||
|
||||
// ExternalServiceQuery proxies service queries to external plugin via HTTP
|
||||
type ExternalServiceQuery struct {
|
||||
URL url.URL
|
||||
ProxyClient http.Client
|
||||
Credentials *auth.BasicAuthCredentials
|
||||
URL url.URL
|
||||
ProxyClient http.Client
|
||||
AuthInjector handlers.AuthInjector
|
||||
}
|
||||
|
||||
// ScaleServiceRequest request scaling of replica
|
||||
@ -71,8 +71,8 @@ func (s ExternalServiceQuery) GetReplicas(serviceName string) (scaling.ServiceQu
|
||||
|
||||
req, _ := http.NewRequest(http.MethodGet, urlPath, nil)
|
||||
|
||||
if s.Credentials != nil {
|
||||
req.SetBasicAuth(s.Credentials.User, s.Credentials.Password)
|
||||
if s.AuthInjector != nil {
|
||||
s.AuthInjector.Inject(req)
|
||||
}
|
||||
|
||||
res, err := s.ProxyClient.Do(req)
|
||||
@ -144,8 +144,8 @@ func (s ExternalServiceQuery) SetReplicas(serviceName string, count uint64) erro
|
||||
urlPath := fmt.Sprintf("%ssystem/scale-function/%s", s.URL.String(), serviceName)
|
||||
req, _ := http.NewRequest(http.MethodPost, urlPath, bytes.NewReader(requestBody))
|
||||
|
||||
if s.Credentials != nil {
|
||||
req.SetBasicAuth(s.Credentials.User, s.Credentials.Password)
|
||||
if s.AuthInjector != nil {
|
||||
s.AuthInjector.Inject(req)
|
||||
}
|
||||
|
||||
defer req.Body.Close()
|
||||
|
Reference in New Issue
Block a user