mirror of
https://github.com/openfaas/faas.git
synced 2025-06-23 15:23:29 +00:00
Enable basic auth for service query / scaling on provider
- this is a blocking issue for auth with Docker Swarm fixes #879 Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
e7cfaa1b9b
commit
3598da2e51
@ -17,12 +17,13 @@ import (
|
||||
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/openfaas/faas-provider/auth"
|
||||
"github.com/openfaas/faas/gateway/handlers"
|
||||
"github.com/openfaas/faas/gateway/requests"
|
||||
)
|
||||
|
||||
// NewExternalServiceQuery proxies service queries to external plugin via HTTP
|
||||
func NewExternalServiceQuery(externalURL url.URL) handlers.ServiceQuery {
|
||||
func NewExternalServiceQuery(externalURL url.URL, credentials *auth.BasicAuthCredentials) handlers.ServiceQuery {
|
||||
proxyClient := http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
@ -40,6 +41,7 @@ func NewExternalServiceQuery(externalURL url.URL) handlers.ServiceQuery {
|
||||
return ExternalServiceQuery{
|
||||
URL: externalURL,
|
||||
ProxyClient: proxyClient,
|
||||
Credentials: credentials,
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,6 +49,7 @@ func NewExternalServiceQuery(externalURL url.URL) handlers.ServiceQuery {
|
||||
type ExternalServiceQuery struct {
|
||||
URL url.URL
|
||||
ProxyClient http.Client
|
||||
Credentials *auth.BasicAuthCredentials
|
||||
}
|
||||
|
||||
// ScaleServiceRequest request scaling of replica
|
||||
@ -65,10 +68,13 @@ func (s ExternalServiceQuery) GetReplicas(serviceName string) (handlers.ServiceQ
|
||||
|
||||
req, _ := http.NewRequest(http.MethodGet, urlPath, nil)
|
||||
|
||||
if s.Credentials != nil {
|
||||
req.SetBasicAuth(s.Credentials.User, s.Credentials.Password)
|
||||
}
|
||||
|
||||
res, err := s.ProxyClient.Do(req)
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Println(urlPath, err)
|
||||
} else {
|
||||
|
||||
@ -129,6 +135,11 @@ 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)
|
||||
}
|
||||
|
||||
defer req.Body.Close()
|
||||
res, err := s.ProxyClient.Do(req)
|
||||
|
||||
|
Reference in New Issue
Block a user