diff --git a/.circleci/config.yml b/.circleci/config.yml index 5ef6347..5721e8d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ version: 2 jobs: build: docker: - - image: circleci/golang:1.11.2 + - image: circleci/golang:1.13.4 environment: GO111MODULE=on diff --git a/README.md b/README.md index f755616..3b4c60b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ A framework for running self-updating, signed binary tools from a central, trust DBT consists of a binary ```dbt``` and a config file. The ```dbt``` binary checks a trusted repository for tools, which are themselves signed binaries. -Tools are automatically downloaded, and verified for checksum and signature before running. +Tools are automatically downloaded, and verified for checksum and signature, then if they pass, they're run. e.g. The DBT binary itself auto-updates from the trusted repository, and if it's checksum and signature checks out, it executes a 'Single White Female' on itself, replacing itself on the fly with the new version and then running the downloaded tool. @@ -54,7 +54,19 @@ DBT does your due diligence for you, and lets you get on with your day. Another real-world example: Imagine this, you've got a system of dynamic VM's and Containers, all leveraging common tooling. You might even have a serious DAG or web of 'things' dynamically generating other 'things' in a busy and automated fashion. What is there's a problem, or an upgrade? With normal utility tools and scripts you have to re-bake your machine images and containers to pick up the changes. You might say that that's a good thing. But what if it's not? -With DBT, you have the best of both worlds. You can force your tools to use an explicit version (```dbt -v 1.2.3 ```). You can also dispense with the '-v' and run the latest. Voila! You're automatically picking up the latest version of the tooling from your trusted repository. +With DBT, you have the best of both worlds. You can force your tools to use an explicit version (```dbt -v 1.2.3 -- ```). You can also dispense with the '-v' and run the latest. Voila! You're automatically picking up the latest version of the tooling from your trusted repository. + +# Usage + +Generally speaking, you will run your tools with a command of the form: + + dbt [flags] -- + +Take special note of the `--` That double dash separates the flags for `dbt` itself from those of the command. It can get confusing if you don't spot the double dash and grok it's meaning. + +Without it, any flags you try to run on `` will be consumed by `dbt` itself, and the result will probably not be what you intend. + +Of course, if your command has no flags itself, only positional arguments, you can run it straight without the double dash. # Security @@ -74,9 +86,11 @@ DBT, as you see it here is set up for *my* test repo. You'll need to make some 1. Fork the repo. -2. Change the `metadata.json` file to reflect your own repository setup and preferences. Specifically you need to change the `repository` and `package` lines. +2. Change the `metadata.json` file to reflect your own repository setup and preferences. Specifically you need to change the `repository` and `package` lines. -3. Run `gomason publish`. If you have it all set up correctly, it should build and install the binary as well as the installer script for your version of DBT. +3. You'll also need to change the package name in go.mod, cmd/dbt/main.go, cmd/boilerplate/main.go, and cmd/catalog/main.go. Basically you'll need to wire it up so that your fork is referencing itself, not my public repo. Basic golang stuff. Don't forget to check your changes into your fork. (Sorry. When I work out a good way to make that easier, I will implement it.) + +4. Install `gomason` via `go get github.com/nikogura/gomason`. Then run `gomason publish`. If you have it all set up correctly, it should build and install the binary as well as the installer script for your version of DBT. The details of what all is supported in `metadata.json` can be found in [https://github.com/nikogura/gomason](https://github.com/nikogura/gomason). @@ -92,7 +106,13 @@ Then you should see a file `http://localhost:8081/artifactory/dbt/install_dbt.sh And voila! Your DBT is now installed. -You will, however need to populate the `truststore` file, which by default, with the above config would be located at `http://localhost:8081/artifactory/dbt/truststore`. This file contains the public keys of the entities you trust to create DBT binaries. You can edit this file by hand, it's just a bunch of PEM data squashed together, or you can use one of the tools listed in the next section. +You will, however need to populate the `truststore` file, which by default, with the above config would be located at `http://localhost:8081/artifactory/dbt/truststore`. This file contains the public keys of the entities you trust to create DBT binaries. You can edit this file by hand, it's just a bunch of PEM data squashed together. + +_AUTHOR'S NOTE: When I personally maintain an internal fork, I set up a clone of the fork with 2 upstreams: 'origin' is my internal fork, and 'upstream' which is the public github.com/nikogura/dbt. Then I make all my internal changes as required, and when upstream changes, do a `git pull upstream ...`. Usually the only changes/conflicts are in the `metadata.json`._ + +_Correct the conflicts in `metadata.json`, commit, and `git push origin master` and my CI system takes it from there. It sounds complicated, and it's certainly not trivial, but it's been very reliable to date._ + +_Rest assured, when I come across a better method, I will not keep it to myself._ # Included Tools @@ -106,13 +126,11 @@ There are, however, some common tasks that any user of DBT might want at their f * *Boilerplate* A tool for generating tool boilerplate. You could do it by hand, but why? -* *Trustmgr* A tool for managing who's public keys are trusted by DBT. (Still under construction. For now you'll need to fill the 'truststore' file with the PEM encoded key or keys you've decided to trust.) - If for some reason you don't want to use the included tools, just remove them from your `metadata.json` and they won't publish. # Repository Support -The initial versions of DBT are targeted at the [Artifactory Open Source](https://www.jfrog.com/open-source) repo. Any sort of WebDAV server that supports authenticated REST should work fine though. +The initial versions of DBT are targeted at the [Artifactory Open Source](https://www.jfrog.com/open-source) repo. Any sort of WebDAV server that supports authenticated PUT's and GET's should work fine though. # Configuration @@ -244,7 +262,7 @@ The file can consist of multiple public keys such as: =KIOK -----END PGP PUBLIC KEY BLOCK----- -There's nothing magical about this file. It's just the keys you've decided to trust. You're free to maintain it by hand if you like, or you can use the dbt tool ```trustmgr```. +There's nothing magical about this file. It's just the keys you've decided to trust, concatenated together. Comments after an `-----END PGP PUBLIC KEY BLOCK-----` or before an `-----BEGIN PGP PUBLIC KEY BLOCK---` are ignored, and can be quite useful for humans trying to maintain this file. ## tools diff --git a/cmd/boilerplate/cmd/gen.go b/cmd/boilerplate/cmd/gen.go index 9f21066..40909a8 100644 --- a/cmd/boilerplate/cmd/gen.go +++ b/cmd/boilerplate/cmd/gen.go @@ -1,4 +1,4 @@ -// Copyright © 2018 NAME HERE +// Copyright © 2018 Nik Ogura // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -67,14 +67,4 @@ Then it will generate a basic, working tool for you that will compile and publis func init() { RootCmd.AddCommand(genCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // genCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // genCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/boilerplate/cmd/root.go b/cmd/boilerplate/cmd/root.go index 43bbef8..e6e5460 100644 --- a/cmd/boilerplate/cmd/root.go +++ b/cmd/boilerplate/cmd/root.go @@ -34,13 +34,8 @@ Sure, a DBT tool is just a signed go binary. You can create 'em any old way. Sometimes, however, you have better things to do with your time, and just want to get something working hence DBT boilerplate. `, - // Uncomment the following line if your bare application - // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, } -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { if err := RootCmd.Execute(); err != nil { fmt.Println(err) @@ -49,40 +44,4 @@ func Execute() { } func init() { - cobra.OnInitialize(initConfig) - - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. - //RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.creator.yaml)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. - //RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") -} - -// initConfig reads in config file and ENV variables if set. -func initConfig() { - //if cfgFile != "" { - // // Use config file from the flag. - // viper.SetConfigFile(cfgFile) - //} else { - // // Find home directory. - // home, err := homedir.Dir() - // if err != nil { - // fmt.Println(err) - // os.Exit(1) - // } - // - // // Search config in home directory with name ".creator" (without extension). - // viper.AddConfigPath(home) - // viper.SetConfigName(".boilerplate") - //} - // - //viper.AutomaticEnv() // read in environment variables that match - // - //// If a config file is found, read it in. - //if err := viper.ReadInConfig(); err == nil { - // fmt.Println("Using config file:", viper.ConfigFileUsed()) - //} } diff --git a/cmd/catalog/cmd/list.go b/cmd/catalog/cmd/list.go index d0e9307..2845e77 100644 --- a/cmd/catalog/cmd/list.go +++ b/cmd/catalog/cmd/list.go @@ -1,4 +1,4 @@ -// Copyright © 2017 NAME HERE +// Copyright © 2017 Nik Ogura // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -39,14 +39,4 @@ List available tools. func init() { RootCmd.AddCommand(listCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // listCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/catalog/cmd/root.go b/cmd/catalog/cmd/root.go index 4b93b4e..c730c54 100644 --- a/cmd/catalog/cmd/root.go +++ b/cmd/catalog/cmd/root.go @@ -1,4 +1,4 @@ -// Copyright © 2017 NAME HERE +// Copyright © 2017 Nik Ogura // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,9 +16,7 @@ package cmd import ( "fmt" - homedir "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" - "github.com/spf13/viper" "os" ) @@ -33,13 +31,8 @@ Tool for showing available DBT tools. DBT tools are made available in a trusted repository. This tool show's what's available there. `, - // Uncomment the following line if your bare application - // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, } -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { if err := RootCmd.Execute(); err != nil { fmt.Println(err) @@ -48,29 +41,5 @@ func Execute() { } func init() { - cobra.OnInitialize(initConfig) - RootCmd.PersistentFlags().BoolVarP(&versions, "versions", "v", false, "Show all version information for tools.") - -} - -// initConfig reads in config file and ENV variables if set. -func initConfig() { - // Find home directory. - home, err := homedir.Dir() - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - // Search config in home directory with name ".catalog" (without extension). - viper.AddConfigPath(home) - viper.SetConfigName(".catalog") - - viper.AutomaticEnv() // read in environment variables that match - - // If a config file is found, read it in. - if err := viper.ReadInConfig(); err == nil { - fmt.Println("Using config file:", viper.ConfigFileUsed()) - } } diff --git a/cmd/dbt/main.go b/cmd/dbt/main.go index faa3562..81c0d87 100644 --- a/cmd/dbt/main.go +++ b/cmd/dbt/main.go @@ -1,130 +1,7 @@ package main -import ( - "fmt" - "github.com/nikogura/dbt/pkg/dbt" - "log" - "os" - "syscall" -) - -// DBT the file path of the installed dbt binary -const DBT = "/usr/local/bin/dbt" - -// VERSION the version of dbt. Must match version in metadata.json -const VERSION = "2.2.5" - -// there are only two options for dbt itself, 'version' and 'offline' -var version string -var offline bool +import "github.com/nikogura/dbt/cmd" func main() { - args := os.Args[1:] - - // exit early if there are no args, or if the first arg is 'help' - exitEarlyIf(args) - - dbtObj, err := dbt.NewDbt() - if err != nil { - log.Fatalf("Error creating DBT object: %s", err) - } - - possibles := []string{"-o", "-ov"} - - if dbt.StringInSlice(args[0], possibles) { // set quiet - offline = true - } - - homedir, err := dbt.GetHomeDir() - if err != nil { - log.Fatalf("Failed to discover user homedir: %s\n", err) - } - - // if we're not explicitly offline, try to upgrade in place - if !offline { - // first fetch the current truststore - err = dbtObj.FetchTrustStore(homedir, false) - if err != nil { - log.Fatalf("Failed to fetch current truststore: %s.\n\nIf you want to try in 'offline' mode, try your command again with '-o'.", err) - } - - ok, err := dbtObj.IsCurrent("") - if err != nil { - log.Printf("Failed to confirm whether we're up to date: %s", err) - } - - if !ok { - log.Printf("Downloading and verifying new version of dbt.") - err = dbtObj.UpgradeInPlace("") - if err != nil { - err = fmt.Errorf("upgrade in place failed: %s", err) - log.Fatalf("Error: %s", err) - } - - // Single white female ourself - _ = syscall.Exec(DBT, os.Args, os.Environ()) - } - } - - if len(args) > 0 { - versionPossibles := []string{"-v", "-ov"} - offlinePossibles := []string{"-o"} - - if dbt.StringInSlice(args[0], versionPossibles) { - if len(args) > 2 { - version = args[1] - - err = dbtObj.RunTool(version, args[2:], homedir, offline) - if err != nil { - log.Fatalf("Error running tool: %s", err) - } - - } else { - log.Fatalf("-v flag requires a version.") - } - - } else if dbt.StringInSlice(args[0], offlinePossibles) { - err = dbtObj.RunTool(version, args[1:], homedir, offline) - if err != nil { - log.Fatalf("Error running tool: %s", err) - } - } else { - err = dbtObj.RunTool(version, args, homedir, offline) - if err != nil { - log.Fatalf("Error running tool: %s", err) - } - } - - } else { - helpMessage() - log.Fatal(1) - } -} - -func exitEarlyIf(args []string) { - if len(args) == 0 { // no args, print help and exit - helpMessage() - os.Exit(0) - } - - if args[0] == "help" { // if we asked for help, give the help - helpMessage() - os.Exit(0) - } - -} - -func helpMessage() { - - log.Printf(`DBT Dynamic Binary Toolkit version: %s - -Usage: - -dbt [-o -v ] [tool args] - -v version Specify version of tool to run. (Defaults to latest) - -o offline Offline mode. Does not attempt to upgrade or find tools, just uses what's already on disk, and errors if it's not available. - -Run 'dbt catalog list' to see a list of what tools are available in your repository. - -`, VERSION) + cmd.Execute() } diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..c91fe9f --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,112 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "fmt" + "github.com/nikogura/dbt/pkg/dbt" + "github.com/spf13/cobra" + "log" + "os" + "os/exec" + "syscall" +) + +var toolVersion string +var offline bool + +var rootCmd = &cobra.Command{ + Use: "dbt", + Short: "Dynamic Binary Toolkit", + Long: ` +Dynamic Binary Toolkit + +A framework for running self-updating signed binaries from a trusted repository. + +Run 'dbt -- catalog list' to see a list of what tools are available in your repository. + +`, + Example: "dbt -- catalog list", + Version: "3.0.0", + Run: Run, +} + +func init() { + rootCmd.Flags().StringVarP(&toolVersion, "toolversion", "v", "", "Version of tool to run.") + rootCmd.Flags().BoolVarP(&offline, "offline", "o", false, "Offline mode.") +} + +func Execute() { + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +func Run(cmd *cobra.Command, args []string) { + if len(args) == 0 { + err := cmd.Help() + if err != nil { + log.Fatal(err) + } + os.Exit(0) + } + + dbtObj, err := dbt.NewDbt() + if err != nil { + log.Fatalf("Error creating DBT object: %s", err) + } + + homedir, err := dbt.GetHomeDir() + if err != nil { + log.Fatalf("Failed to discover user homedir: %s\n", err) + } + + dbtBinary, err := exec.LookPath("dbt") + if err != nil { + log.Fatalf("Couldn't find `dbt` in $PATH: %s", err) + } + + // if we're not explicitly offline, try to upgrade in place + if !offline { + // first fetch the current truststore + err = dbtObj.FetchTrustStore(homedir, false) + if err != nil { + log.Fatalf("Failed to fetch remote truststore: %s.\n\nIf you want to try in 'offline' mode, retry your command again with: dbt -o ...", err) + } + + ok, err := dbtObj.IsCurrent(dbtBinary) + if err != nil { + log.Printf("Failed to confirm whether we're up to date: %s", err) + } + + if !ok { + log.Printf("Downloading and verifying new version of dbt.") + err = dbtObj.UpgradeInPlace(dbtBinary) + if err != nil { + err = fmt.Errorf("upgrade in place failed: %s", err) + log.Fatalf("Error: %s", err) + } + + // Single white female ourself + _ = syscall.Exec(dbtBinary, os.Args, os.Environ()) + } + } + + err = dbtObj.RunTool(toolVersion, args, homedir, offline) + if err != nil { + log.Fatal(err) + } +} diff --git a/go.mod b/go.mod index 01267b5..6b2ce7d 100644 --- a/go.mod +++ b/go.mod @@ -1,31 +1,33 @@ module github.com/nikogura/dbt require ( - github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495 + github.com/davecgh/go-spew v1.1.1 github.com/fsnotify/fsnotify v1.4.7 - github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce + github.com/hashicorp/hcl v1.0.0 github.com/inconshreveable/mousetrap v1.0.0 github.com/magiconair/properties v1.8.0 github.com/mattn/go-runewidth v0.0.3 github.com/mitchellh/go-homedir v1.1.0 - github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675 + github.com/mitchellh/mapstructure v1.1.2 github.com/nikogura/gomason v0.0.0-20180623164404-5bb5e6a9169c github.com/pelletier/go-toml v1.2.0 github.com/phayes/freeport v0.0.0-20171002185219-e27662a4a9d6 github.com/pkg/errors v0.8.1 github.com/pmezard/go-difflib v1.0.0 - github.com/spf13/afero v1.1.1 - github.com/spf13/cast v1.2.0 - github.com/spf13/cobra v0.0.0-20180531180338-1e58aa3361fd - github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec - github.com/spf13/pflag v0.0.0-20180601132542-3ebe029320b2 - github.com/spf13/viper v0.0.0-20180507071007-15738813a09d - github.com/stretchr/testify v0.0.0-20171018052257-2aa2c176b9da - golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8 + github.com/spf13/afero v1.1.2 + github.com/spf13/cast v1.3.0 + github.com/spf13/cobra v0.0.5 + github.com/spf13/jwalterweatherman v1.0.0 + github.com/spf13/pflag v1.0.3 + github.com/spf13/viper v1.3.2 + github.com/stretchr/testify v1.2.2 + golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 golang.org/x/net v0.0.0-20180621144259-afe8f62b1d6b - golang.org/x/sys v0.0.0-20180907202204-917fdcba135d - golang.org/x/text v0.0.0-20180617084112-5cec4b58c438 + golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a + golang.org/x/text v0.3.0 gopkg.in/cheggaaa/pb.v1 v1.0.25 gopkg.in/ini.v1 v1.37.0 - gopkg.in/yaml.v2 v2.2.1 + gopkg.in/yaml.v2 v2.2.2 ) + +go 1.13 diff --git a/go.sum b/go.sum index 3a2ff25..892ddd5 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,20 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495 h1:6IyqGr3fnd0tM3YxipK27TUskaOVUjU2nG45yzwcQKY= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce h1:xdsDDbiBDQTKASoGEZ+pEmF1OnWuu8AQ9I8iNbHNeno= github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -15,6 +26,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675 h1:/rdJjIiKG5rRdwG5yxHmSE/7ZREjpyC0kL7GxGT/qJw= github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/nikogura/gomason v0.0.0-20180623164404-5bb5e6a9169c h1:e0CI0XUBwdY0pQlpLCjlr3hOZBlq4XXqbIz8VhQLHcY= github.com/nikogura/gomason v0.0.0-20180623164404-5bb5e6a9169c/go.mod h1:STap11tGPY01wwP5ySN1n9F56xFtxBfDlOgT3UGNdQ0= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= @@ -27,28 +40,51 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/spf13/afero v1.1.1 h1:Lt3ihYMlE+lreX1GS4Qw4ZsNpYQLxIXKBTEOXm3nt6I= github.com/spf13/afero v1.1.1/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.2.0 h1:HHl1DSRbEQN2i8tJmtS6ViPyHx35+p51amrdsiTCrkg= github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.0-20180531180338-1e58aa3361fd h1:81M+Gt4SwR+KFuvy7qiAQhiVY8qPFxwn50AsV3yRGdk= github.com/spf13/cobra v0.0.0-20180531180338-1e58aa3361fd/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= +github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec h1:2ZXvIUGghLpdTVHR1UfvfrzoVlZaE/yOWC5LueIHZig= github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v0.0.0-20180601132542-3ebe029320b2 h1:OAuq3yHhRwcm/kwCSAqf07pUm/EcLZYNz1ket+Bm0SI= github.com/spf13/pflag v0.0.0-20180601132542-3ebe029320b2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v0.0.0-20180507071007-15738813a09d h1:pIz+bbPLk78K39d3u77IlNpJvpS/f0ao8n3sdy82eCs= github.com/spf13/viper v0.0.0-20180507071007-15738813a09d/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM= +github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/testify v0.0.0-20171018052257-2aa2c176b9da h1:/GRWXYJLcWpnjmFCtD64tuNT1YteX36zELue/SXxl5Y= github.com/stretchr/testify v0.0.0-20171018052257-2aa2c176b9da/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8 h1:h7zdf0RiEvWbYBKIx4b+q41xoUVnMmvsGZnIVE5syG8= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/net v0.0.0-20180621144259-afe8f62b1d6b h1:VgWwPFFrh6LyvObbug7TZtI8EX5zwx7WsS6Y4Bqezqo= golang.org/x/net v0.0.0-20180621144259-afe8f62b1d6b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/sys v0.0.0-20180907202204-917fdcba135d h1:kWn1hlsqeUrk6JsLJO0ZFyz9bMg8u85voZlIuc68ZU4= golang.org/x/sys v0.0.0-20180907202204-917fdcba135d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1YthsFqr/5mxHduZW2A= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.0.0-20180617084112-5cec4b58c438 h1:Evl03DW9QA/Q6b0oGwvf5H8aSAL/xt4LweM7hwikMWM= golang.org/x/text v0.0.0-20180617084112-5cec4b58c438/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25 h1:Ev7yu1/f6+d+b3pi5vPdRPc6nNtP1umSfcWiEfRqv6I= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= @@ -56,3 +92,5 @@ gopkg.in/ini.v1 v1.37.0 h1:Jg0A8mA6eCo6oGRA5ZgEwO9u/DIdlWMxyMzad9tN/rI= gopkg.in/ini.v1 v1.37.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/metadata.json b/metadata.json index 75f4601..9d901d4 100644 --- a/metadata.json +++ b/metadata.json @@ -1,5 +1,5 @@ { - "version": "2.2.5", + "version": "3.0.0", "package": "github.com/nikogura/dbt", "description": "Dynamic Binary Toolkit - A framework for running self-updating signed binaries from a central, trusted repository.", "repository": "http://localhost:8081/artifactory/dbt", diff --git a/pkg/dbt/dbt.go b/pkg/dbt/dbt.go index 900ffa3..87423a6 100644 --- a/pkg/dbt/dbt.go +++ b/pkg/dbt/dbt.go @@ -1,3 +1,17 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dbt import ( @@ -10,6 +24,7 @@ import ( "log" "net/http" "os" + "os/exec" "runtime" "syscall" "time" @@ -33,9 +48,6 @@ const ConfigFilePath = ConfigDir + "/dbt.json" // TruststorePath is the actual file path to the downloaded trust store const TruststorePath = TrustDir + "/truststore" -// DbtBinaryPath is the default locaiton where the dbt binary gets installed to -const DbtBinaryPath = "/usr/local/bin/dbt" - // DBT the dbt object itself type DBT struct { Config Config @@ -177,6 +189,10 @@ func (dbt *DBT) FetchTrustStore(homedir string, verbose bool) (err error) { uri := dbt.Config.Dbt.TrustStore + if verbose { + fmt.Printf("Fetching truststore from %q\n", uri) + } + client := &http.Client{ Timeout: 10 * time.Second, } @@ -223,10 +239,6 @@ func (dbt *DBT) FetchTrustStore(homedir string, verbose bool) (err error) { // IsCurrent returns whether the currently running version is the latest version, and possibly an error if the version check fails func (dbt *DBT) IsCurrent(binaryPath string) (ok bool, err error) { - if binaryPath == "" { - binaryPath = DbtBinaryPath - } - latest, err := dbt.FindLatestVersion("") if err != nil { err = errors.Wrap(err, "failed to fetch dbt versions") @@ -242,7 +254,7 @@ func (dbt *DBT) IsCurrent(binaryPath string) (ok bool, err error) { } if !ok { - fmt.Fprint(os.Stderr, fmt.Sprintf("Newer version of dbt available: %s\n\n", latest)) + _, _ = fmt.Fprint(os.Stderr, fmt.Sprintf("Newer version of dbt available: %s\n\n", latest)) } return ok, err @@ -250,10 +262,6 @@ func (dbt *DBT) IsCurrent(binaryPath string) (ok bool, err error) { // UpgradeInPlace upgraded dbt in place func (dbt *DBT) UpgradeInPlace(binaryPath string) (err error) { - if binaryPath == "" { - binaryPath = DbtBinaryPath - } - tmpDir, err := ioutil.TempDir("", "dbt") if err != nil { err = errors.Wrap(err, "failed to create temp dir") @@ -320,6 +328,12 @@ func (dbt *DBT) UpgradeInPlace(binaryPath string) (err error) { // RunTool runs the dbt tool indicated by the args func (dbt *DBT) RunTool(version string, args []string, homedir string, offline bool) (err error) { toolName := args[0] + + if toolName == "--" { + toolName = args[1] + args = args[1:] + } + localPath := fmt.Sprintf("%s/%s/%s", homedir, ToolDir, toolName) // if offline, if tool is present and verifies, run it @@ -425,6 +439,11 @@ func (dbt *DBT) RunTool(version string, args []string, homedir string, offline b func (dbt *DBT) verifyAndRun(homedir string, args []string) (err error) { toolName := args[0] + if toolName == "--" { + toolName = args[1] + args = args[1:] + } + localPath := fmt.Sprintf("%s/%s/%s", homedir, ToolDir, toolName) localChecksumPath := fmt.Sprintf("%s/%s/%s.sha256", homedir, ToolDir, toolName) @@ -467,16 +486,34 @@ func (dbt *DBT) verifyAndRun(homedir string, args []string) (err error) { return err } +var testExec bool + func (dbt *DBT) runExec(homedir string, args []string) (err error) { toolName := args[0] localPath := fmt.Sprintf("%s/%s/%s", homedir, ToolDir, toolName) env := os.Environ() - err = syscall.Exec(localPath, args, env) - if err != nil { - err = errors.Wrap(err, "error running exec") - return err + if testExec { + env = append(env, "GO_WANT_HELPER_PROCESS=1") + cs := []string{"-test.run=TestHelperProcess", "--", localPath} + cs = append(cs, args...) + cmd := exec.Command(os.Args[0], cs...) + bytes, err := cmd.Output() + if err != nil { + err = errors.Wrap(err, "error running exec") + return err + } + + fmt.Printf("\nTest Command Output: %q\n", string(bytes)) + + } else { + err = syscall.Exec(localPath, args, env) + if err != nil { + err = errors.Wrap(err, "error running exec") + return err + } + } return err diff --git a/pkg/dbt/dbt_fixtures.go b/pkg/dbt/dbt_fixtures.go index 0c4c746..843c9e1 100644 --- a/pkg/dbt/dbt_fixtures.go +++ b/pkg/dbt/dbt_fixtures.go @@ -1,3 +1,17 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dbt import "fmt" diff --git a/pkg/dbt/dbt_test.go b/pkg/dbt/dbt_test.go index 480ad1b..c2a1412 100644 --- a/pkg/dbt/dbt_test.go +++ b/pkg/dbt/dbt_test.go @@ -1,3 +1,17 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dbt import ( @@ -63,7 +77,7 @@ func setUp() { func tearDown() { if _, err := os.Stat(tmpDir); !os.IsNotExist(err) { - os.Remove(tmpDir) + _ = os.Remove(tmpDir) } } @@ -269,3 +283,59 @@ func TestGetHomeDir(t *testing.T) { t.Fail() } } + +func TestRunTool(t *testing.T) { + dbt := &DBT{ + Config: dbtConfig, + Verbose: true, + } + + script := `#!/bin/bash +echo "foo" +` + + sig := `-----BEGIN PGP SIGNATURE----- + +iQFABAABCAAqFiEE3Ww86tgfSQ9lgLSizmhGNf2l0x8FAl3nXyUMHGRidEBkYnQu +Y29tAAoJEM5oRjX9pdMf49cIAKXlHna+QX8NZirDmqJkHg/SQXfSSwSpSVBxtD/B +lcgiERJLRy9yUUOxj9mF7uY+0l2Q0N9tqH+ZsqI8T0o6rOw3m9fpRymWhtvZkn/3 +TUGYqXtllm9N5H/XCXm/GmRhS/nwSU/dxt8uEOMxbOGeNoEnSvRLX6UUBe5lzdbQ +p05JqgbJHm7Im/xjqvXeiCkhO6LsiH44PA7fn82XczUExiFf29YbqSxoaTFbNUml +EAIt0IfO16Jj6BfZiqlAdklK6gvyRyMIkQrSwXG0Umb2dPlJjz1x+DCbruUqnQX7 +CP+c4NMnm7ZH7Ap+pII6ZPHdc5KxJNWh6ZVioY7EUINJKZk= +=/zev +-----END PGP SIGNATURE-----` + + fileName := fmt.Sprintf("%s/%s/bar", tmpDir, ToolDir) + checksumFile := fmt.Sprintf("%s/%s/bar.sha256", tmpDir, ToolDir) + sigFile := fmt.Sprintf("%s/%s/bar.asc", tmpDir, ToolDir) + + err := ioutil.WriteFile(fileName, []byte(script), 0755) + if err != nil { + fmt.Printf("Error writing test file: %s", err) + t.Fail() + } + + checksum, err := FileSha256(fileName) + if err != nil { + fmt.Printf("Error checksumming test file: %s", err) + t.Fail() + } + + err = ioutil.WriteFile(checksumFile, []byte(checksum), 0644) + if err != nil { + fmt.Printf("Error writing checksum file: %s", err) + t.Fail() + } + + err = ioutil.WriteFile(sigFile, []byte(sig), 0644) + + testExec = true + + err = dbt.RunTool("", []string{"bar"}, tmpDir, true) + if err != nil { + fmt.Printf("Error running test tool: %s", err) + t.Fail() + } + +} diff --git a/pkg/dbt/repository.go b/pkg/dbt/repository.go index fdccac8..3ba6453 100644 --- a/pkg/dbt/repository.go +++ b/pkg/dbt/repository.go @@ -1,3 +1,17 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dbt import ( @@ -251,7 +265,7 @@ func (dbt *DBT) FetchFile(fileUrl string, destPath string) (err error) { reader := bar.NewProxyReader(resp.Body) // and copy from pb reader - io.Copy(out, reader) + _, _ = io.Copy(out, reader) _, err = io.Copy(out, resp.Body) diff --git a/pkg/dbt/repository_fixtures.go b/pkg/dbt/repository_fixtures.go index 668db12..606a77d 100644 --- a/pkg/dbt/repository_fixtures.go +++ b/pkg/dbt/repository_fixtures.go @@ -1,3 +1,17 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dbt import "fmt" diff --git a/pkg/dbt/repository_test.go b/pkg/dbt/repository_test.go index bb8fce1..47d10d8 100644 --- a/pkg/dbt/repository_test.go +++ b/pkg/dbt/repository_test.go @@ -1,3 +1,17 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dbt import ( diff --git a/pkg/dbt/testrepo.go b/pkg/dbt/testrepo.go index bf57a3e..c481472 100644 --- a/pkg/dbt/testrepo.go +++ b/pkg/dbt/testrepo.go @@ -1,3 +1,17 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dbt import ( @@ -45,7 +59,7 @@ func (tr *TestRepo) HandlerTruststore(w http.ResponseWriter, r *http.Request) { _, err := w.Write([]byte(testTruststore())) if err != nil { w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(fmt.Sprintf("500 - %s", err))) + _, _ = w.Write([]byte(fmt.Sprintf("500 - %s", err))) } } diff --git a/pkg/dbt/util.go b/pkg/dbt/util.go index bc4d7cb..eeecc7b 100644 --- a/pkg/dbt/util.go +++ b/pkg/dbt/util.go @@ -1,3 +1,17 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dbt import ( diff --git a/pkg/dbt/util_fixtures.go b/pkg/dbt/util_fixtures.go index ad095e2..d427a76 100644 --- a/pkg/dbt/util_fixtures.go +++ b/pkg/dbt/util_fixtures.go @@ -1,3 +1,17 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dbt func exampleVersion() string { diff --git a/pkg/dbt/util_test.go b/pkg/dbt/util_test.go index a0fa8f2..e4002b0 100644 --- a/pkg/dbt/util_test.go +++ b/pkg/dbt/util_test.go @@ -1,3 +1,17 @@ +// Copyright © 2019 Nik Ogura +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dbt import ( diff --git a/pre-commit-hook.sh b/pre-commit-hook.sh index 4f3e6e3..35206d2 100755 --- a/pre-commit-hook.sh +++ b/pre-commit-hook.sh @@ -3,7 +3,7 @@ METADATA_VERSION=$(grep version metadata.json | awk '{print $2}' | sed 's/[",]//g') -CODE_VERSION=$(grep VERSION cmd/dbt/main.go | grep -v version | awk '{print $4}' | sed 's/"//g') +CODE_VERSION=$(grep Version: cmd/root.go | grep -v version | awk '{print $2}' | sed 's/"//g' | sed 's/,//g') if [[ ${METADATA_VERSION} != ${CODE_VERSION} ]]; then echo "Versions do not match!"