Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #78 from netlify/reverse_middlewares
Browse files Browse the repository at this point in the history
Reverse middlewares ordering.
  • Loading branch information
calavera authored Jan 27, 2018
2 parents a213b58 + 5a78f1e commit abed9e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
14 changes: 7 additions & 7 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (

func addCommands() {
middlewares := []middleware.Middleware{
middleware.DebugMiddleware,
middleware.LoggingMiddleware,
middleware.AuthMiddleware,
middleware.ClientMiddleware,
middleware.AuthMiddleware,
middleware.LoggingMiddleware,
middleware.DebugMiddleware,
}

loginMiddlewares := []middleware.Middleware{
middleware.DebugMiddleware,
middleware.LoggingMiddleware,
middleware.NoAuthMiddleware,
middleware.ClientMiddleware,
middleware.NoAuthMiddleware,
middleware.LoggingMiddleware,
middleware.DebugMiddleware,
}

siteMiddlewares := append(middlewares, middleware.SiteConfigMiddleware)
siteMiddlewares := append([]middleware.Middleware{middleware.SiteConfigMiddleware}, middlewares...)

rootCmd.AddCommand(deploy.Setup(siteMiddlewares))
rootCmd.AddCommand(assets.Setup(siteMiddlewares))
Expand Down
7 changes: 7 additions & 0 deletions commands/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func DebugMiddleware(cmd CommandFunc) CommandFunc {
logrus.SetLevel(logrus.DebugLevel)
logrus.WithFields(logrus.Fields{"command": c.Use, "arguments": args}).Debug("PreRun")

logrus.Debug("configure debug middleware")

dump, err := c.Root().Flags().GetBool("debug")
if err != nil {
return err
Expand Down Expand Up @@ -106,6 +108,7 @@ func DebugMiddleware(cmd CommandFunc) CommandFunc {

func LoggingMiddleware(cmd CommandFunc) CommandFunc {
return func(ctx context.Context, c *cobra.Command, args []string) error {
logrus.Debug("configure logging middleware")
entry := logrus.NewEntry(logrus.StandardLogger())
entry.Debugf("setup logger middleware: %v", entry.Level)
ctx = apiContext.WithLogger(ctx, entry)
Expand All @@ -116,6 +119,7 @@ func LoggingMiddleware(cmd CommandFunc) CommandFunc {

func AuthMiddleware(cmd CommandFunc) CommandFunc {
return func(ctx context.Context, c *cobra.Command, args []string) error {
logrus.Debug("configure auth middleware")
creds := auth.ClientCredentials()
logrus.WithField("credentials", creds).Debug("setup credentials")

Expand All @@ -127,6 +131,7 @@ func AuthMiddleware(cmd CommandFunc) CommandFunc {

func NoAuthMiddleware(cmd CommandFunc) CommandFunc {
return func(ctx context.Context, c *cobra.Command, args []string) error {
logrus.Debug("configure no auth middleware")
creds := auth.NoCredentials()
logrus.WithField("credentials", creds).Debug("setup credentials")

Expand All @@ -138,6 +143,7 @@ func NoAuthMiddleware(cmd CommandFunc) CommandFunc {

func ClientMiddleware(cmd CommandFunc) CommandFunc {
return func(ctx context.Context, c *cobra.Command, args []string) error {
logrus.Debug("configure client middleware")
var transport *apiClient.Runtime

if endpoint := c.Flag("endpoint"); endpoint != nil {
Expand Down Expand Up @@ -180,6 +186,7 @@ func ClientMiddleware(cmd CommandFunc) CommandFunc {

func SiteConfigMiddleware(cmd CommandFunc) CommandFunc {
return func(ctx context.Context, c *cobra.Command, args []string) error {
logrus.Debug("configure site middleware")
var siteId string
if siteIdFlag := c.Flag("site-id"); siteIdFlag != nil {
siteId = siteIdFlag.Value.String()
Expand Down
2 changes: 1 addition & 1 deletion commands/sites/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func setupUpdateCommand(middlewares []middleware.Middleware) *cobra.Command {
ccmd.Flags().StringVarP(&cmd.password, "password", "p", "", "site's access password")
ccmd.Flags().BoolVarP(&cmd.forceTLS, "force-tls", "t", false, "force TLS connections")

siteMiddlewares := append(middlewares, middleware.SiteConfigMiddleware)
siteMiddlewares := append([]middleware.Middleware{middleware.SiteConfigMiddleware}, middlewares...)

return middleware.SetupCommand(ccmd, cmd.updateSite, siteMiddlewares)
}
Expand Down

0 comments on commit abed9e8

Please sign in to comment.