Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump-up(docker): update parser to the latest to be able to parse all keywords #805

Merged
merged 2 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions acceptance.bats
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@
[[ "$output" =~ "unallowed image found [\"openjdk:8-jdk-alpine\"]" ]]
}

@test "Can parse newly introduced keywords for docker" {
run bash -c "cat <<EOF | ./conftest parse --parser dockerfile -
# syntax=docker/dockerfile:1.4
FROM alpine
COPY --link /foo /bar
EOF"
[ "$status" -eq 0 ]
}

@test "Can disable color" {
run ./conftest test -p examples/kubernetes/policy examples/kubernetes/service.yaml --no-color
[ "$status" -eq 0 ]
Expand Down
4 changes: 2 additions & 2 deletions builtins/parse_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package builtins
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/open-policy-agent/conftest/parser"
Expand Down Expand Up @@ -97,7 +97,7 @@ func parseConfigFile(bctx rego.BuiltinContext, op1 *ast.Term) (*ast.Term, error)
if err != nil {
return nil, fmt.Errorf("create config parser: %w", err)
}
contents, err := ioutil.ReadFile(filePath)
contents, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("read config file %s: %w", filePath, err)
}
Expand Down
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/open-policy-agent/conftest

go 1.17
go 1.19

require (
cuelang.org/go v0.4.0
Expand All @@ -18,13 +18,13 @@ require (
github.com/jstemmer/go-junit-report v0.9.1
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/magiconair/properties v1.8.5
github.com/moby/buildkit v0.9.3
github.com/moby/buildkit v0.11.5
github.com/olekukonko/tablewriter v0.0.5
github.com/open-policy-agent/opa v0.51.0
github.com/opencontainers/image-spec v1.1.0-rc2
github.com/pkg/errors v0.9.1
github.com/shteou/go-ignore v0.3.1
github.com/spdx/tools-golang v0.2.0
github.com/spdx/tools-golang v0.3.1-0.20230104082527-d6f58551be3f
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.10.0
github.com/subosito/gotenv v1.2.0
Expand All @@ -46,9 +46,10 @@ require (
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/aws/aws-sdk-go v1.44.26 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/cockroachdb/apd/v2 v2.0.1 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
github.com/docker/docker v20.10.21+incompatible // indirect
github.com/docker/docker v23.0.0-rc.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
Expand All @@ -67,7 +68,7 @@ require (
github.com/hashicorp/hcl/v2 v2.9.1 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
Expand Down Expand Up @@ -104,5 +105,5 @@ require (
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
2,332 changes: 12 additions & 2,320 deletions go.sum

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions internal/commands/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"

"github.com/open-policy-agent/opa/format"
Expand Down Expand Up @@ -40,7 +39,7 @@ func NewFormatCommand() *cobra.Command {
return fmt.Errorf("stat: %w", err)
}

contents, err := ioutil.ReadFile(policy.Package.Location.File)
contents, err := os.ReadFile(policy.Package.Location.File)
if err != nil {
return fmt.Errorf("read policy: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package parser
import (
"bufio"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -297,7 +297,7 @@ func parseConfigurations(paths []string, parser string) (map[string]interface{},

func getConfigurationContent(path string) ([]byte, error) {
if path == "-" {
contents, err := ioutil.ReadAll(bufio.NewReader(os.Stdin))
contents, err := io.ReadAll(bufio.NewReader(os.Stdin))
if err != nil {
return nil, fmt.Errorf("read standard in: %w", err)
}
Expand All @@ -310,7 +310,7 @@ func getConfigurationContent(path string) ([]byte, error) {
return nil, fmt.Errorf("get abs: %w", err)
}

contents, err := ioutil.ReadFile(filePath)
contents, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("open file: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions parser/spdx/spdx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Created: 2021-08-26T01:46:00Z
}

inputMap := input.(map[string]interface{})
creationInfo := inputMap["CreationInfo"].(map[string]interface{})
currentDataLicense := creationInfo["DataLicense"]
currentDataLicense := inputMap["dataLicense"]
expectedDataLicense := "conftest-demo"
if currentDataLicense != expectedDataLicense {
t.Errorf("DataLicense of the SPDX file have: %s, want: %s", currentDataLicense, expectedDataLicense)
Expand Down
3 changes: 1 addition & 2 deletions plugin/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package plugin
import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -87,7 +86,7 @@ func installFromURL(ctx context.Context, url string) error {
// Before allowing the plugin to be stored in the plugin directory,
// make sure the plugin has a valid configuration file by first downloading
// the plugin into a temporary directory and validating its configuration.
tempDirectory, err := ioutil.TempDir(CacheDirectory(), "conftest-plugin-*")
tempDirectory, err := os.MkdirTemp(CacheDirectory(), "conftest-plugin-*")
if err != nil {
return fmt.Errorf("create tmp dir: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package plugin
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -52,7 +51,7 @@ func FindAll() ([]*Plugin, error) {
return []*Plugin{}, nil
}

files, err := ioutil.ReadDir(CacheDirectory())
files, err := os.ReadDir(CacheDirectory())
if err != nil {
return nil, fmt.Errorf("read plugin cache: %w", err)
}
Expand Down Expand Up @@ -155,7 +154,7 @@ func FromDirectory(directory string) (*Plugin, error) {
const configurationFileName = "plugin.yaml"

configPath := filepath.Join(directory, configurationFileName)
data, err := ioutil.ReadFile(configPath)
data, err := os.ReadFile(configPath)
if err != nil {
return nil, fmt.Errorf("read config: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions plugin/xdg_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package plugin

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -151,7 +150,7 @@ func TestFind(t *testing.T) {
}

dir := filepath.ToSlash(filepath.Join(homeDir))
tmp, err := ioutil.TempDir(dir, "")
tmp, err := os.MkdirTemp(dir, "")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -191,7 +190,7 @@ func TestFind(t *testing.T) {
}

dir := filepath.ToSlash(filepath.Join(homeDir))
tmp, err := ioutil.TempDir(dir, "")
tmp, err := os.MkdirTemp(dir, "")
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions policy/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -136,7 +135,7 @@ func LoadWithData(policyPaths []string, dataPaths []string, capabilities string,

documentContents := make(map[string]string)
for _, documentPath := range allDocumentPaths {
contents, err := ioutil.ReadFile(documentPath)
contents, err := os.ReadFile(documentPath)
if err != nil {
return nil, fmt.Errorf("read file: %w", err)
}
Expand Down