Skip to content

Commit

Permalink
Fix plugins on Windows (#400)
Browse files Browse the repository at this point in the history
* Fix plugins on Windows

Signed-off-by: John Reese <john@reese.dev>

* Run tidy

Signed-off-by: John Reese <john@reese.dev>
  • Loading branch information
jpreese committed Sep 23, 2020
1 parent 67f5f4e commit 01ab5c8
Show file tree
Hide file tree
Showing 16 changed files with 363 additions and 514 deletions.
24 changes: 17 additions & 7 deletions acceptance.bats
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,6 @@
[[ "$output" =~ "No images tagged latest" ]]
}

@test "Can download or symlink plugins" {
run ./conftest plugin install examples/plugins/kubectl/
[ "$status" -eq 0 ]
run ./conftest kubectl
[ "$status" -eq 0 ]
}

@test "The number of tests run is accurate" {
run ./conftest test -p examples/kubernetes/policy examples/kubernetes/service.yaml --no-color
[ "$status" -eq 0 ]
Expand Down Expand Up @@ -314,3 +307,20 @@
[ "$status" -eq 1 ]
[[ "$output" =~ "2 tests, 1 passed, 0 warnings, 1 failure" ]]
}

@test "Can install plugin from directory" {
run ./conftest plugin install contrib/plugins/kubectl
[ "$status" -eq 0 ]

run ./conftest kubectl
[ "$status" -eq 0 ]
}

# Uncomment test when the plugin exists on GitHub
#@test "Can install plugin from URL" {
# run ./conftest plugin install github.com/open-policy-agent/conftest/contrib/plugins/kubectl
# [ "$status" -eq 0 ]
#
# run ./conftest kubectl
# [ "$status" -eq 0 ]
#}
32 changes: 0 additions & 32 deletions contrib/plugins/conftest.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# It uses the conftest utility and expects to find associated policy files in
# a directory called policy


# Check if a specified command exists on the path and is executable
function check_command () {
if ! [[ -x $(command -v "$1") ]] ; then
Expand All @@ -19,7 +18,7 @@ function usage () {
echo "See https://github.com/open-policy-agent/conftest for more information"
echo
echo "Usage:"
echo " kubectl conftest (TYPE[.VERSION][.GROUP] [NAME] | TYPE[.VERSION][.GROUP]/NAME)"
echo " conftest kubectl (TYPE[.VERSION][.GROUP] [NAME] | TYPE[.VERSION][.GROUP]/NAME)"
}

# Check the required commands are available on the PATH
Expand Down
File renamed without changes.
61 changes: 0 additions & 61 deletions examples/plugins/kubectl/kubectl-conftest.sh

This file was deleted.

16 changes: 7 additions & 9 deletions internal/commands/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,17 @@ func NewDefaultCommand() *cobra.Command {
}

func loadPlugins(ctx context.Context) ([]*cobra.Command, error) {
plugins, err := plugin.FindPlugins()
plugins, err := plugin.FindAll()
if err != nil {
return nil, fmt.Errorf("loading plugins: %v", err)
return nil, fmt.Errorf("find plugins: %v", err)
}

var cmds []*cobra.Command
for _, plugin := range plugins {
plugin := plugin
metaData := plugin.MetaData
cmd := &cobra.Command{
Use: metaData.Name,
Short: metaData.Usage,
Long: metaData.Description,
cmd := cobra.Command{
Use: plugin.Name,
Short: plugin.Usage,
Long: plugin.Description,
RunE: func(cmd *cobra.Command, args []string) error {
if err := plugin.Exec(ctx, args); err != nil {
return fmt.Errorf("execute plugin: %v", err)
Expand All @@ -86,7 +84,7 @@ func loadPlugins(ctx context.Context) ([]*cobra.Command, error) {
DisableFlagParsing: true,
}

cmds = append(cmds, cmd)
cmds = append(cmds, &cmd)
}

return cmds, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func NewPluginCommand(ctx context.Context) *cobra.Command {
cmd := cobra.Command{
Use: "plugin",
Short: "manage conftest plugins",
Short: "Manage conftest plugins",
Long: "This command manages conftest plugins",
}

Expand Down
12 changes: 6 additions & 6 deletions internal/commands/plugin_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import (
const installDesc = `
This command installs a plugin from the given path or url
Several locations are supported by the plugin install command. Under the hood
conftest leverages go-getter (https://github.com/hashicorp/go-getter).
The following protocols are supported for downloading plugins:
The following protocols are supported for downloading plugins:
- Local Files
- Git
Expand All @@ -23,9 +22,10 @@ The following protocols are supported for downloading plugins:
- Amazon S3
- Google Cloud GCP
The location of the plugins is specified by passing an URL, e.g.:
The location of the plugins is specified by passing a path or URL, e.g.:
$ conftest plugin install https://github.com/open-policy-agent/conftest/examples/plugins/kubectl
$ conftest plugin install github.com/open-policy-agent/conftest/examples/plugins/kubectl
$ conftest plugin install contrib/plugins/kubectl
Based on the protocol a different mechanism will be used to download the plugin.
The pull command will also try to infer the protocol based on the URL if the
Expand All @@ -43,8 +43,8 @@ func NewPluginInstallCommand(ctx context.Context) *cobra.Command {
Args: cobra.MinimumNArgs(1),

RunE: func(cmd *cobra.Command, args []string) error {
if err := plugin.Download(ctx, args[0]); err != nil {
return fmt.Errorf("install plugin: %v", err)
if err := plugin.Install(ctx, args[0]); err != nil {
return fmt.Errorf("install: %v", err)
}

return nil
Expand Down
57 changes: 0 additions & 57 deletions plugin/cache.go

This file was deleted.

43 changes: 0 additions & 43 deletions plugin/cache_test.go

This file was deleted.

43 changes: 0 additions & 43 deletions plugin/download.go

This file was deleted.

Loading

0 comments on commit 01ab5c8

Please sign in to comment.