diff --git a/Makefile b/Makefile index 0c15c346..4cac6b16 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: all build -VERSION := 0.2.1 +VERSION := 0.2.2 all: build diff --git a/build.sh b/build.sh index d4b83e62..7f6aee4f 100755 --- a/build.sh +++ b/build.sh @@ -12,5 +12,7 @@ curl https://glide.sh/get | sh echo "install all the dependencies" glide install +OPA_VERSION=$(grep 'package: github.com/open-policy-agent/opa$' glide.yaml -A 1 | tail -n 1 | awk '{print $2}') + echo "build opa-docker-authz" -CGO_ENABLED=0 go build -ldflags "-X github.com/open-policy-agent/opa-docker-authz.Version=$VERSION" -o opa-docker-authz +CGO_ENABLED=0 go build -ldflags "-X github.com/open-policy-agent/opa-docker-authz/version.Version=$VERSION -X github.com/open-policy-agent/opa-docker-authz/version.OPAVersion=$OPA_VERSION" -o opa-docker-authz diff --git a/glide.yaml b/glide.yaml index a2362c1d..137b5e20 100644 --- a/glide.yaml +++ b/glide.yaml @@ -7,4 +7,4 @@ import: - package: github.com/fsnotify/fsnotify version: 4da3e2cfbabc9f751898f250b49f2439785783a1 - package: github.com/open-policy-agent/opa - version: v0.6.0 + version: v0.8.0 diff --git a/main.go b/main.go index f30c43f9..962a496a 100644 --- a/main.go +++ b/main.go @@ -14,9 +14,10 @@ import ( "os" "github.com/docker/go-plugins-helpers/authorization" - "github.com/open-policy-agent/opa/rego" + version_pkg "github.com/open-policy-agent/opa-docker-authz/version" "github.com/open-policy-agent/opa/ast" "github.com/open-policy-agent/opa/loader" + "github.com/open-policy-agent/opa/rego" ) // DockerAuthZPlugin implements the authorization.Plugin interface. Every @@ -137,7 +138,7 @@ func regoSyntax(p string) int { modules := map[string]*ast.Module{} - for _,m := range result.Modules { + for _, m := range result.Modules { modules[m.Name] = m.Parsed } @@ -153,21 +154,19 @@ func regoSyntax(p string) int { return 0 } -// Version is set by the build. -var Version = "" - func main() { pluginName := flag.String("plugin-name", "opa-docker-authz", "sets the plugin name that will be registered with Docker") allowPath := flag.String("allowPath", "data.docker.authz.allow", "sets the path of the allow decision in OPA") policyFile := flag.String("policy-file", "policy.rego", "sets the path of the policy file to load") version := flag.Bool("version", false, "print the version of the plugin") - check := flag.Bool("check", false , "checks the syntax of the policy-file") + check := flag.Bool("check", false, "checks the syntax of the policy-file") flag.Parse() if *version { - fmt.Println(Version) + fmt.Println("Version:", version_pkg.Version) + fmt.Println("OPA Version:", version_pkg.OPAVersion) os.Exit(0) } diff --git a/version/version.go b/version/version.go new file mode 100644 index 00000000..2e45e495 --- /dev/null +++ b/version/version.go @@ -0,0 +1,11 @@ +// Copyright 2018 The OPA Authors. All rights reserved. +// Use of this source code is governed by an Apache2 +// license that can be found in the LICENSE file. + +package version + +// Version numbers set during build. +var ( + Version = "" + OPAVersion = "" +)