mirror of
https://github.com/openfaas/faas.git
synced 2025-06-24 07:43:25 +00:00
Refactor #843
Code-review/refactoring for #843. Closes #843. FaaSHandlers has had info and query handlers added to its list of types for consistency. Secrets added to queue-worker component ready for next PR. Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
fa076fb2c4
commit
ffd81afd02
@ -89,6 +89,8 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
max_inflight: "1"
|
max_inflight: "1"
|
||||||
ack_wait: "30s" # Max duration of any async task / request
|
ack_wait: "30s" # Max duration of any async task / request
|
||||||
|
basic_auth: "false"
|
||||||
|
secret_mount_path: "/run/secrets/"
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
|
@ -93,6 +93,8 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
max_inflight: "1"
|
max_inflight: "1"
|
||||||
ack_wait: "300s" # Max duration of any async task / request
|
ack_wait: "300s" # Max duration of any async task / request
|
||||||
|
basic_auth: "${BASIC_AUTH:-true}"
|
||||||
|
secret_mount_path: "/run/secrets/"
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
@ -107,6 +109,10 @@ services:
|
|||||||
placement:
|
placement:
|
||||||
constraints:
|
constraints:
|
||||||
- 'node.platform.os == linux'
|
- 'node.platform.os == linux'
|
||||||
|
secrets:
|
||||||
|
- basic-auth-user
|
||||||
|
- basic-auth-password
|
||||||
|
|
||||||
# End services
|
# End services
|
||||||
|
|
||||||
# Start monitoring
|
# Start monitoring
|
||||||
|
6
gateway/Makefile
Normal file
6
gateway/Makefile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
.PHONY: all build
|
||||||
|
TAG?=latest
|
||||||
|
|
||||||
|
all: build
|
||||||
|
build:
|
||||||
|
./build.sh ${TAG}
|
@ -1,5 +1,4 @@
|
|||||||
// Copyright (c) Alex Ellis 2017. All rights reserved.
|
// Copyright (c) Alex Ellis 2017. All rights reserved.
|
||||||
// Copyright (c) OpenFaaS Author(s). All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
@ -85,13 +84,12 @@ func main() {
|
|||||||
faasHandlers.DeployFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)
|
faasHandlers.DeployFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)
|
||||||
faasHandlers.DeleteFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)
|
faasHandlers.DeleteFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)
|
||||||
faasHandlers.UpdateFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)
|
faasHandlers.UpdateFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)
|
||||||
queryFunction := handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)
|
faasHandlers.QueryFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)
|
||||||
|
faasHandlers.InfoHandler = handlers.MakeInfoHandler(handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer))
|
||||||
|
|
||||||
alertHandler := plugin.NewExternalServiceQuery(*config.FunctionsProviderURL)
|
alertHandler := plugin.NewExternalServiceQuery(*config.FunctionsProviderURL)
|
||||||
faasHandlers.Alert = handlers.MakeAlertHandler(alertHandler)
|
faasHandlers.Alert = handlers.MakeAlertHandler(alertHandler)
|
||||||
|
|
||||||
infoHandler := handlers.MakeInfoHandler(handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer))
|
|
||||||
|
|
||||||
if config.UseNATS() {
|
if config.UseNATS() {
|
||||||
log.Println("Async enabled: Using NATS Streaming.")
|
log.Println("Async enabled: Using NATS Streaming.")
|
||||||
natsQueue, queueErr := natsHandler.CreateNatsQueue(*config.NATSAddress, *config.NATSPort, natsHandler.DefaultNatsConfig{})
|
natsQueue, queueErr := natsHandler.CreateNatsQueue(*config.NATSAddress, *config.NATSPort, natsHandler.DefaultNatsConfig{})
|
||||||
@ -120,8 +118,8 @@ func main() {
|
|||||||
handlers.DecorateWithBasicAuth(faasHandlers.ListFunctions, credentials)
|
handlers.DecorateWithBasicAuth(faasHandlers.ListFunctions, credentials)
|
||||||
faasHandlers.ScaleFunction =
|
faasHandlers.ScaleFunction =
|
||||||
handlers.DecorateWithBasicAuth(faasHandlers.ScaleFunction, credentials)
|
handlers.DecorateWithBasicAuth(faasHandlers.ScaleFunction, credentials)
|
||||||
infoHandler = handlers.DecorateWithBasicAuth(infoHandler, credentials)
|
faasHandlers.QueryFunction = handlers.DecorateWithBasicAuth(faasHandlers.QueryFunction, credentials)
|
||||||
queryFunction = handlers.DecorateWithBasicAuth(queryFunction, credentials)
|
faasHandlers.InfoHandler = handlers.DecorateWithBasicAuth(faasHandlers.InfoHandler, credentials)
|
||||||
}
|
}
|
||||||
|
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
@ -137,17 +135,17 @@ func main() {
|
|||||||
ServiceQuery: alertHandler,
|
ServiceQuery: alertHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
functionProxy = handlers.MakeScalingHandler(faasHandlers.Proxy, queryFunction, scalingConfig)
|
functionProxy = handlers.MakeScalingHandler(faasHandlers.Proxy, faasHandlers.QueryFunction, scalingConfig)
|
||||||
}
|
}
|
||||||
// r.StrictSlash(false) // This didn't work, so register routes twice.
|
// r.StrictSlash(false) // This didn't work, so register routes twice.
|
||||||
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}", functionProxy)
|
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}", functionProxy)
|
||||||
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/", functionProxy)
|
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/", functionProxy)
|
||||||
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/{params:.*}", functionProxy)
|
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/{params:.*}", functionProxy)
|
||||||
|
|
||||||
r.HandleFunc("/system/info", infoHandler).Methods(http.MethodGet)
|
r.HandleFunc("/system/info", faasHandlers.InfoHandler).Methods(http.MethodGet)
|
||||||
r.HandleFunc("/system/alert", faasHandlers.Alert)
|
r.HandleFunc("/system/alert", faasHandlers.Alert).Methods(http.MethodPost)
|
||||||
|
|
||||||
r.HandleFunc("/system/function/{name:[-a-zA-Z_0-9]+}", queryFunction).Methods(http.MethodGet)
|
r.HandleFunc("/system/function/{name:[-a-zA-Z_0-9]+}", faasHandlers.QueryFunction).Methods(http.MethodGet)
|
||||||
r.HandleFunc("/system/functions", faasHandlers.ListFunctions).Methods(http.MethodGet)
|
r.HandleFunc("/system/functions", faasHandlers.ListFunctions).Methods(http.MethodGet)
|
||||||
r.HandleFunc("/system/functions", faasHandlers.DeployFunction).Methods(http.MethodPost)
|
r.HandleFunc("/system/functions", faasHandlers.DeployFunction).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/system/functions", faasHandlers.DeleteFunction).Methods(http.MethodDelete)
|
r.HandleFunc("/system/functions", faasHandlers.DeleteFunction).Methods(http.MethodDelete)
|
||||||
|
@ -12,6 +12,9 @@ type HandlerSet struct {
|
|||||||
RoutelessProxy http.HandlerFunc
|
RoutelessProxy http.HandlerFunc
|
||||||
UpdateFunction http.HandlerFunc
|
UpdateFunction http.HandlerFunc
|
||||||
|
|
||||||
|
// QueryFunction - queries the metdata for a function
|
||||||
|
QueryFunction http.HandlerFunc
|
||||||
|
|
||||||
// QueuedProxy - queue work and return synchronous response
|
// QueuedProxy - queue work and return synchronous response
|
||||||
QueuedProxy http.HandlerFunc
|
QueuedProxy http.HandlerFunc
|
||||||
|
|
||||||
@ -20,4 +23,7 @@ type HandlerSet struct {
|
|||||||
|
|
||||||
// ScaleFunction allows a function to be scaled
|
// ScaleFunction allows a function to be scaled
|
||||||
ScaleFunction http.HandlerFunc
|
ScaleFunction http.HandlerFunc
|
||||||
|
|
||||||
|
// InfoHandler provides version and build info
|
||||||
|
InfoHandler http.HandlerFunc
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user