Skip to content

Commit

Permalink
Add basic validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec committed Jan 31, 2023
1 parent be41241 commit 6825658
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type Config struct {
Actions Actions `yaml:"actions" validate:"dive"`
Sources map[string]Sources `yaml:"sources" validate:"dive"`
Executors map[string]Executors `yaml:"executors" validate:"dive"`
Aliases Aliases `yaml:"aliases"`
Aliases Aliases `yaml:"aliases" validate:"dive"`
Communications map[string]Communications `yaml:"communications" validate:"required,min=1,dive"`

Filters Filters `yaml:"filters"`
Expand Down Expand Up @@ -310,7 +310,7 @@ type Aliases map[string]Alias

// Alias defines alias configuration for a given command.
type Alias struct {
Command string `yaml:"command"`
Command string `yaml:"command" validate:"required"`
DisplayName string `yaml:"displayName"`
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ func TestLoadedConfigValidationErrors(t *testing.T) {
readTestdataFile(t, "missing-action-bindings.yaml"),
},
},
{
name: "invalid alias",
expErrMsg: heredoc.Doc(`
found critical validation errors: 1 error occurred:
* Key: 'Config.Aliases[eee].Command' Command is a required field`),
configs: [][]byte{
readTestdataFile(t, "invalid-alias.yaml"),
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
communications: {"foo": {}}

aliases:
kc:
command: kubectl
displayName: "Kubectl alias"
kgp:
command: kubectl get pods
displayName: "Kubectl Get Pods"
helm:
command: helm version
displayName: "Helm version"
eee:
command: ""

executors:
'kubectl-read-only':
kubectl:
enabled: true
helm:
botkube/helm:
config: {}
enabled: true
'plugin-based':
botkube/[email protected]:
enabled: false
config:
changeResponseToUpperCase: true
2 changes: 1 addition & 1 deletion pkg/execute/alias/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ExpandPrefix(rawCmd string, aliases config.Aliases) string {
return strings.Replace(rawCmd, aliasWithSpace, targetCmdWithSpace, 1)
}

// Case 3: False positive - alias prefix is a part of the command - continue
// Case 3: False positive - alias prefix is a part of a different binary name - continue
}

return rawCmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/execute/plugin_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package execute
import (
"context"
"fmt"
"github.com/kubeshop/botkube/pkg/bot/interactive"

"github.com/sirupsen/logrus"
"google.golang.org/grpc/status"
"gopkg.in/yaml.v3"

"github.com/kubeshop/botkube/internal/plugin"
"github.com/kubeshop/botkube/pkg/api/executor"
"github.com/kubeshop/botkube/pkg/bot/interactive"
"github.com/kubeshop/botkube/pkg/config"
)

Expand Down

0 comments on commit 6825658

Please sign in to comment.