mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
More middleware updates.
This commit is contained in:
@@ -108,9 +108,6 @@ func (c *middlewareContextImpl) Index() int {
|
||||
|
||||
func (s *Server) middlewareWrapperFunc(ctx context.Context) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if len(s.middlewares) == 0 {
|
||||
return
|
||||
}
|
||||
// TODO: we should get rid of this, gin context and middleware context both implement context, don't need a third one here
|
||||
ctx = c.MustGet("ctx").(context.Context)
|
||||
fctx := &middlewareContextImpl{Context: ctx}
|
||||
|
||||
@@ -21,7 +21,6 @@ func main() {
|
||||
funcServer.AddMiddlewareFunc(func(ctx server.MiddlewareContext, w http.ResponseWriter, r *http.Request, app *models.App) error {
|
||||
start := time.Now()
|
||||
fmt.Println("CustomMiddlewareFunc called at:", start)
|
||||
// TODO: probably need a way to let the chain go forward here and return back to the middleware, for things like timing, etc.
|
||||
ctx.Next()
|
||||
fmt.Println("Duration:", (time.Now().Sub(start)))
|
||||
return nil
|
||||
@@ -48,5 +47,6 @@ func (h *CustomMiddleware) Serve(ctx server.MiddlewareContext, w http.ResponseWr
|
||||
return errors.New("Invalid authorization token.")
|
||||
}
|
||||
fmt.Println("auth succeeded!")
|
||||
ctx.Set("user", "I'm in!")
|
||||
return nil
|
||||
}
|
||||
|
||||
20
fn/apps.go
20
fn/apps.go
@@ -7,13 +7,14 @@ import (
|
||||
"os"
|
||||
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
fnclient "github.com/funcy/functions_go/client"
|
||||
apiapps "github.com/funcy/functions_go/client/apps"
|
||||
"github.com/funcy/functions_go/models"
|
||||
"github.com/jmoiron/jsonq"
|
||||
"github.com/urfave/cli"
|
||||
client "gitlab-odx.oracle.com/odx/functions/fn/client"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type appsCmd struct {
|
||||
@@ -101,11 +102,15 @@ func (a *appsCmd) list(c *cli.Context) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
// fmt.Println("err type:", reflect.TypeOf(err))
|
||||
switch err.(type) {
|
||||
case *apiapps.GetAppsAppNotFound:
|
||||
return fmt.Errorf("error: %v", err.(*apiapps.GetAppsAppNotFound).Payload.Error.Message)
|
||||
case *apiapps.GetAppsAppDefault:
|
||||
return fmt.Errorf("unexpected error: %v", err.(*apiapps.GetAppsAppDefault).Payload.Error.Message)
|
||||
case *apiapps.GetAppsDefault:
|
||||
// this is the one getting called, not sure what the one above is?
|
||||
return fmt.Errorf("unexpected error: %v", err.(*apiapps.GetAppsDefault).Payload.Error.Message)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -145,19 +150,6 @@ func (a *appsCmd) create(c *cli.Context) error {
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
const createHeader = `
|
||||
____ __
|
||||
/ __ \_________ ______/ /__
|
||||
/ / / / ___/ __ / ___/ / _ \
|
||||
/ /_/ / / / /_/ / /__/ / __/
|
||||
\_________ \__,_/\___/_/\____ _
|
||||
/ ____/_ ______ _____/ /_(_)___ ____ _____
|
||||
/ /_ / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
|
||||
/ __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__ )
|
||||
/_/ \____/_/ /_/\___/\__/_/\____/_/ /_/____/
|
||||
`
|
||||
|
||||
fmt.Println(createHeader)
|
||||
fmt.Println("Successfully created app: ", resp.Payload.App.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
90
fn/install
Executable file
90
fn/install
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Install script to install fn
|
||||
|
||||
release="0.3.7"
|
||||
|
||||
command_exists() {
|
||||
command -v "$@" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
case "$(uname -m)" in
|
||||
*64)
|
||||
;;
|
||||
*)
|
||||
echo >&2 'Error: you are not using a 64bit platform.'
|
||||
echo >&2 'Functions CLI currently only supports 64bit platforms.'
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if command_exists fn ; then
|
||||
echo >&2 'Warning: "fn" command appears to already exist.'
|
||||
echo >&2 'If you are just upgrading your functions cli client, ignore this and wait a few seconds.'
|
||||
echo >&2 'You may press Ctrl+C now to abort this process.'
|
||||
( set -x; sleep 5 )
|
||||
fi
|
||||
|
||||
user="$(id -un 2>/dev/null || true)"
|
||||
|
||||
sh_c='sh -c'
|
||||
if [ "$user" != 'root' ]; then
|
||||
if command_exists sudo; then
|
||||
sh_c='sudo -E sh -c'
|
||||
elif command_exists su; then
|
||||
sh_c='su -c'
|
||||
else
|
||||
echo >&2 'Error: this installer needs the ability to run commands as root.'
|
||||
echo >&2 'We are unable to find either "sudo" or "su" available to make this happen.'
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
curl=''
|
||||
if command_exists curl; then
|
||||
curl='curl -sSL -o'
|
||||
elif command_exists wget; then
|
||||
curl='wget -qO'
|
||||
elif command_exists busybox && busybox --list-modules | grep -q wget; then
|
||||
curl='busybox wget -qO'
|
||||
else
|
||||
echo >&2 'Error: this installer needs the ability to run wget or curl.'
|
||||
echo >&2 'We are unable to find either "wget" or "curl" available to make this happen.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
url='https://gitlab-odx.oracle.com/odx/functions/fn/releases/download'
|
||||
|
||||
# perform some very rudimentary platform detection
|
||||
case "$(uname)" in
|
||||
Linux)
|
||||
$sh_c "$curl /usr/local/bin/fn $url/$release/fn_linux"
|
||||
$sh_c "chmod +x /usr/local/bin/fn"
|
||||
fn --version
|
||||
exit 0
|
||||
;;
|
||||
Darwin)
|
||||
$sh_c "$curl /usr/local/bin/fn $url/$release/fn_mac"
|
||||
$sh_c "chmod +x /usr/local/bin/fn"
|
||||
fn --version
|
||||
exit 0
|
||||
;;
|
||||
WindowsNT)
|
||||
$sh_c "$curl $url/$release/fn.exe"
|
||||
# TODO how to make executable? chmod?
|
||||
fn.exe --version
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
cat >&2 <<'EOF'
|
||||
|
||||
Either your platform is not easily detectable or is not supported by this
|
||||
installer script (yet - PRs welcome! [fn/install]).
|
||||
Please visit the following URL for more detailed installation instructions:
|
||||
|
||||
https://gitlab-odx.oracle.com/odx/functions
|
||||
|
||||
EOF
|
||||
exit 1
|
||||
Reference in New Issue
Block a user