diff --git a/handlers/namespace.go b/handlers/namespace.go new file mode 100644 index 00000000..f39b0c50 --- /dev/null +++ b/handlers/namespace.go @@ -0,0 +1,26 @@ +package handlers + +import ( + "encoding/json" + "log" + "net/http" +) + +// Swarm does not use namespaces, so we return an empty list. see https://github.com/openfaas-incubator/connector-sdk/pull/46 +func NamespaceLister() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + namespaces := []string{} + nsJSON, err := json.Marshal(namespaces) + + if err != nil { + log.Printf("Unable to marshal namespaces into JSON %q", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte("\"error\": \"unable to return namespaces\"")) + } + + w.WriteHeader(http.StatusOK) + w.Write(nsJSON) + } +} + diff --git a/main.go b/main.go index f550361c..248c1512 100644 --- a/main.go +++ b/main.go @@ -64,6 +64,8 @@ func main() { InfoHandler: handlers.MakeInfoHandler(version.BuildVersion(), version.GitCommit), SecretHandler: handlers.MakeSecretsHandler(dockerClient), LogHandler: logs.NewLogHandlerFunc(handlers.NewLogRequester(dockerClient), cfg.FaaSConfig.WriteTimeout), + ListNamespaceHandler: handlers.NamespaceLister(), + } bootstrapConfig := bootTypes.FaaSConfig{