Compare commits

...

4 Commits

Author SHA1 Message Date
Ludovic Fernandez
38344b342d Prepare release v2.0.0-alpha6. 2019-06-18 18:10:06 +02:00
Orhan Hirsch
346ff96de2 Kubernetes CRD documentation fixes 2019-06-18 12:20:04 +02:00
Ludovic Fernandez
31614bebc4 Don't allow non flag arguments by default. 2019-06-18 12:10:06 +02:00
Ludovic Fernandez
be888b59a6 doc: fix middleware names for CRD. 2019-06-18 09:50:05 +02:00
9 changed files with 106 additions and 21 deletions

View File

@@ -1,5 +1,15 @@
# Change Log
## [v2.0.0-alpha6](https://github.com/containous/traefik/tree/v2.0.0-alpha6) (2019-06-18)
[All Commits](https://github.com/containous/traefik/compare/v2.0.0-alpha5...v2.0.0-alpha6)
**Bug fixes:**
- **[cli]** Don't allow non flag arguments by default. ([#4970](https://github.com/containous/traefik/pull/4970) by [ldez](https://github.com/ldez))
**Documentation:**
- **[middleware,k8s/crd]** doc: fix middleware names for CRD. ([#4966](https://github.com/containous/traefik/pull/4966) by [ldez](https://github.com/ldez))
- **[middleware]** Kubernetes CRD documentation fixes ([#4971](https://github.com/containous/traefik/pull/4971) by [orhanhenrik](https://github.com/orhanhenrik))
## [v2.0.0-alpha5](https://github.com/containous/traefik/tree/v2.0.0-alpha5) (2019-06-17)
[All Commits](https://github.com/containous/traefik/compare/v2.0.0-alpha4...v2.0.0-alpha5)

View File

@@ -15,6 +15,16 @@ labels:
- "traefik.http.middlewares.test-compress.compress=true"
```
```yaml tab="Kubernetes"
# Enable gzip compression
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: test-compress
spec:
compress: {}
```
```json tab="Marathon"
"labels": {
"traefik.http.middlewares.test-compress.compress": "true"

View File

@@ -19,10 +19,10 @@ labels:
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: addprefix
name: test-maxconn
spec:
addPrefix:
prefix: /bar
maxConn:
amount: 10
```
```json tab="Marathon"

View File

@@ -32,15 +32,16 @@ metadata:
name: test-ratelimit
spec:
rateLimit:
extractorfunc = "client.ip"
rate0:
period = "10s"
average = 100
burst = 200
rate1:
period = "3s"
average = 5
burst = 10
extractorFunc: client.ip
rateset:
rate0:
period: 10s
average: 100
burst: 200
rate1:
period: 3s
average: 5
burst: 10
```
```json tab="Marathon"

View File

@@ -22,7 +22,7 @@ kind: Middleware
metadata:
name: test-stripprefix
spec:
StripPrefix:
stripPrefix:
prefixes:
- /foobar
- /fiibar

View File

@@ -1,4 +1,4 @@
# StripPrefix
# StripPrefixRegex
Removing Prefixes From the Path Before Forwarding the Request (Using a Regex)
{: .subtitle }
@@ -22,7 +22,7 @@ kind: Middleware
metadata:
name: test-stripprefixregex
spec:
StripPrefixRegex:
stripPrefixRegex:
regex: "^/foo/(.*)"
```

View File

@@ -3,7 +3,6 @@
package cli
import (
"errors"
"fmt"
"os"
"path/filepath"
@@ -17,7 +16,9 @@ type Command struct {
Resources []ResourceLoader
Run func([]string) error
Hidden bool
subCommands []*Command
// AllowArg if not set, disallows any argument that is not a known command or a sub-command.
AllowArg bool
subCommands []*Command
}
// AddCommand Adds a sub command.
@@ -40,13 +41,17 @@ func Execute(cmd *Command) error {
}
func execute(cmd *Command, args []string, root bool) error {
// Calls command without args.
if len(args) == 1 {
if err := run(cmd, args); err != nil {
if err := run(cmd, args[1:]); err != nil {
return fmt.Errorf("command %s error: %v", args[0], err)
}
return nil
}
// Special case: if the command is the top level one,
// and the first arg (`args[1]`) is not the command name or a known sub-command,
// then we run the top level command itself.
if root && cmd.Name != args[1] && !contains(cmd.subCommands, args[1]) {
if err := run(cmd, args[1:]); err != nil {
return fmt.Errorf("command %s error: %v", filepath.Base(args[0]), err)
@@ -54,6 +59,7 @@ func execute(cmd *Command, args []string, root bool) error {
return nil
}
// Calls command by its name.
if len(args) >= 2 && cmd.Name == args[1] {
if err := run(cmd, args[2:]); err != nil {
return fmt.Errorf("command %s error: %v", cmd.Name, err)
@@ -61,6 +67,7 @@ func execute(cmd *Command, args []string, root bool) error {
return nil
}
// No sub-command, calls the current command.
if len(cmd.subCommands) == 0 {
if err := run(cmd, args[1:]); err != nil {
return fmt.Errorf("command %s error: %v", cmd.Name, err)
@@ -68,6 +75,7 @@ func execute(cmd *Command, args []string, root bool) error {
return nil
}
// Trying to find the sub-command.
for _, subCmd := range cmd.subCommands {
if len(args) >= 2 && subCmd.Name == args[1] {
return execute(subCmd, args[1:], false)
@@ -84,7 +92,12 @@ func run(cmd *Command, args []string) error {
if cmd.Run == nil {
_ = PrintHelp(os.Stdout, cmd)
return errors.New("command not found")
return fmt.Errorf("command %s is not runnable", cmd.Name)
}
if len(args) > 0 && !isFlag(args[0]) && !cmd.AllowArg {
_ = PrintHelp(os.Stdout, cmd)
return fmt.Errorf("command not found: %v", args)
}
if cmd.Configuration == nil {
@@ -113,3 +126,7 @@ func contains(cmds []*Command, name string) bool {
return false
}
func isFlag(arg string) bool {
return len(arg) > 0 && arg[1] == '-'
}

View File

@@ -86,6 +86,23 @@ func Test_execute(t *testing.T) {
},
expected: expected{result: "root"},
},
{
desc: "root command, with argument, command not found",
args: []string{"", "echo"},
command: func() *Command {
return &Command{
Name: "root",
Description: "This is a test",
Configuration: nil,
Run: func(_ []string) error {
called = "root"
return nil
},
}
},
expected: expected{error: true},
},
{
desc: "one sub command",
args: []string{"", "sub1"},
@@ -114,6 +131,34 @@ func Test_execute(t *testing.T) {
},
expected: expected{result: "sub1"},
},
{
desc: "one sub command, with argument, command not found",
args: []string{"", "sub1", "echo"},
command: func() *Command {
rootCmd := &Command{
Name: "test",
Description: "This is a test",
Configuration: nil,
Run: func(_ []string) error {
called += "root"
return nil
},
}
_ = rootCmd.AddCommand(&Command{
Name: "sub1",
Description: "sub1",
Configuration: nil,
Run: func(_ []string) error {
called += "sub1"
return nil
},
})
return rootCmd
},
expected: expected{error: true},
},
{
desc: "two sub commands",
args: []string{"", "sub2"},
@@ -376,6 +421,7 @@ func Test_execute(t *testing.T) {
Name: "sub1",
Description: "sub1",
Configuration: nil,
AllowArg: true,
Run: func(args []string) error {
called += "sub1-" + strings.Join(args, "-")
return nil
@@ -394,6 +440,7 @@ func Test_execute(t *testing.T) {
Name: "root",
Description: "This is a test",
Configuration: nil,
AllowArg: true,
Run: func(args []string) error {
called += "root-" + strings.Join(args, "-")
return nil

View File

@@ -19,8 +19,8 @@ type Middleware struct {
Headers *Headers `json:"headers,omitempty"`
Errors *ErrorPage `json:"errors,omitempty"`
RateLimit *RateLimit `json:"rateLimit,omitempty"`
RedirectRegex *RedirectRegex `json:"redirectregex,omitempty"`
RedirectScheme *RedirectScheme `json:"redirectscheme,omitempty"`
RedirectRegex *RedirectRegex `json:"redirectRegex,omitempty"`
RedirectScheme *RedirectScheme `json:"redirectScheme,omitempty"`
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
DigestAuth *DigestAuth `json:"digestAuth,omitempty"`
ForwardAuth *ForwardAuth `json:"forwardAuth,omitempty"`