Skip to content

Commit

Permalink
Allow "." in function name
Browse files Browse the repository at this point in the history
This is to begin supporting multiple namespaces in a backwards-
compatible way.

Signed-off-by: Alex Ellis <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Sep 20, 2019
1 parent a7f9772 commit 878cd46
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions logs/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func parseRequest(r *http.Request) (logRequest Request, err error) {
return logRequest, err
}
}

// ignore error because it will default to false if we can't parse it
logRequest.Follow, _ = strconv.ParseBool(getValue(query, "follow"))

Expand Down
15 changes: 12 additions & 3 deletions proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/gorilla/mux"
)

const NameExpression = "-a-zA-Z_0-9."

func varHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
w.WriteHeader(http.StatusOK)
Expand Down Expand Up @@ -94,6 +96,13 @@ func Test_pathParsing(t *testing.T) {
"",
200,
},
{
"simple_name_match",
"/function/echo.openfaas-fn",
"echo.openfaas-fn",
"",
200,
},
{
"simple_name_match_with_trailing_slash",
"/function/echo/",
Expand Down Expand Up @@ -126,9 +135,9 @@ func Test_pathParsing(t *testing.T) {

// Need to create a router that we can pass the request through so that the vars will be added to the context
router := mux.NewRouter()
router.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}", varHandler)
router.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/", varHandler)
router.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/{params:.*}", varHandler)
router.HandleFunc("/function/{name:["+NameExpression+"]+}", varHandler)
router.HandleFunc("/function/{name:["+NameExpression+"]+}/", varHandler)
router.HandleFunc("/function/{name:["+NameExpression+"]+}/{params:.*}", varHandler)

for _, s := range tt {
t.Run(s.name, func(t *testing.T) {
Expand Down
13 changes: 8 additions & 5 deletions serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
"github.com/openfaas/faas-provider/types"
)

// NameExpression for a function / service
const NameExpression = "-a-zA-Z_0-9."

var r *mux.Router

// Mark this as a Golang "package"
Expand Down Expand Up @@ -55,17 +58,17 @@ func Serve(handlers *types.FaaSHandlers, config *types.FaaSConfig) {
r.HandleFunc("/system/functions", handlers.DeleteHandler).Methods("DELETE")
r.HandleFunc("/system/functions", handlers.UpdateHandler).Methods("PUT")

r.HandleFunc("/system/function/{name:[-a-zA-Z_0-9]+}", handlers.ReplicaReader).Methods("GET")
r.HandleFunc("/system/scale-function/{name:[-a-zA-Z_0-9]+}", handlers.ReplicaUpdater).Methods("POST")
r.HandleFunc("/system/function/{name:["+NameExpression+"]+}", handlers.ReplicaReader).Methods("GET")
r.HandleFunc("/system/scale-function/{name:["+NameExpression+"]+}", handlers.ReplicaUpdater).Methods("POST")
r.HandleFunc("/system/info", handlers.InfoHandler).Methods("GET")

r.HandleFunc("/system/secrets", handlers.SecretHandler).Methods(http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete)
r.HandleFunc("/system/logs", handlers.LogHandler).Methods(http.MethodGet)

// Open endpoints
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}", handlers.FunctionProxy)
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/", handlers.FunctionProxy)
r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/{params:.*}", handlers.FunctionProxy)
r.HandleFunc("/function/{name:["+NameExpression+"]+}", handlers.FunctionProxy)
r.HandleFunc("/function/{name:["+NameExpression+"]+}/", handlers.FunctionProxy)
r.HandleFunc("/function/{name:["+NameExpression+"]+}/{params:.*}", handlers.FunctionProxy)

if config.EnableHealth {
r.HandleFunc("/healthz", handlers.HealthHandler).Methods("GET")
Expand Down

0 comments on commit 878cd46

Please sign in to comment.