Skip to content

Commit ba2f0ce

Browse files
committed
first cut
Signed-off-by: Khash Sajadi <[email protected]>
1 parent 3f35cc5 commit ba2f0ce

File tree

565 files changed

+304705
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

565 files changed

+304705
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.idea
2+
/copper

Gopkg.lock

+162
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
#
22+
# [prune]
23+
# non-go = false
24+
# go-tests = true
25+
# unused-packages = true
26+
27+
28+
[[constraint]]
29+
name = "github.com/mitchellh/go-homedir"
30+
version = "1.1.0"
31+
32+
[[constraint]]
33+
name = "github.com/spf13/cobra"
34+
version = "0.0.4"
35+
36+
[[constraint]]
37+
name = "github.com/spf13/viper"
38+
version = "1.4.0"
39+
40+
[prune]
41+
go-tests = true
42+
unused-packages = true

build.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
version=$(git describe --tags --always)
4+
5+
if [ -z "$1" ]
6+
then
7+
echo "No channel supplied"
8+
exit 1
9+
fi
10+
11+
channel=$1
12+
force="false"
13+
14+
if [[ $2 == "--force" ]]
15+
then
16+
force="true"
17+
fi
18+
19+
echo "Building $channel/$version"
20+
echo
21+
22+
rm build/*
23+
24+
curl -s http://downloads.cloud66.com.s3.amazonaws.com/copper/versions.json | jq '.versions |= map(if (.channel == "'$channel'") then .version = "'$version'" else . end) | .versions |= map(if (.channel == "'$channel'") then .force = '$force' else . end)' > build/versions.json
25+
echo "Current Versions"
26+
cat build/versions.json | jq -r '.versions | map([.channel, .version] | join(": ")) | .[]'
27+
echo
28+
29+
packr2
30+
# for now we're not building for windows as a result of an issue with gox + godirwalk
31+
gox -ldflags "-X github.com/cloud66-oss/copper/utils.Version=$version -X github.com/cloud66-oss/copper/utils.Channel=$channel" -os="darwin linux" -arch="amd64" -output "build/{{.OS}}_{{.Arch}}_$version"
32+
packr2 clean

build/.keep

Whitespace-only changes.

cmd/cmd-packr.go

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/root.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/mitchellh/go-homedir"
8+
"github.com/spf13/cobra"
9+
"github.com/spf13/viper"
10+
)
11+
12+
var rootCmd = &cobra.Command{
13+
Use: "copper",
14+
Short: "Copper is a configuration validator",
15+
Long: `A simple way to validate configuration files for compliance, best practices and policy enforcement. For more information please
16+
visit https://github.com/cloud66-oss/copper`,
17+
}
18+
19+
var (
20+
cfgFile string
21+
)
22+
23+
func init() {
24+
cobra.OnInitialize(initConfig)
25+
26+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/copper.yaml)")
27+
}
28+
29+
func initConfig() {
30+
if cfgFile != "" {
31+
viper.SetConfigFile(cfgFile)
32+
} else {
33+
home, err := homedir.Dir()
34+
if err != nil {
35+
fmt.Println(err)
36+
os.Exit(1)
37+
}
38+
39+
viper.AddConfigPath(home)
40+
viper.AddConfigPath("/etc/copper")
41+
viper.SetConfigName("copper")
42+
}
43+
44+
_ = viper.ReadInConfig()
45+
}
46+
47+
// Execute runs root
48+
func Execute() {
49+
if err := rootCmd.Execute(); err != nil {
50+
fmt.Println(err)
51+
os.Exit(1)
52+
}
53+
}

cmd/update.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/cloud66-oss/copper/utils"
8+
"github.com/khash/updater"
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/viper"
11+
)
12+
13+
var updateCmd = &cobra.Command{
14+
Use: "update",
15+
Short: "Update copper to the latest version",
16+
Run: updateExec,
17+
}
18+
19+
func init() {
20+
updateCmd.Flags().StringP("channel", "", utils.Channel, "version channel")
21+
_ = viper.BindPFlag("channel", updateCmd.Flags().Lookup("channel"))
22+
23+
rootCmd.AddCommand(updateCmd)
24+
}
25+
26+
func updateExec(cmd *cobra.Command, args []string) {
27+
update(false)
28+
29+
fmt.Println("Updated")
30+
}
31+
32+
func update(silent bool) {
33+
worker, err := updater.NewUpdater(utils.Version, &updater.Options{
34+
RemoteURL: "https://s3.amazonaws.com/downloads.cloud66.com/copper/",
35+
Channel: viper.GetString("channel"),
36+
Silent: silent,
37+
})
38+
if err != nil {
39+
if !silent {
40+
fmt.Println(err)
41+
os.Exit(1)
42+
}
43+
44+
os.Exit(0)
45+
}
46+
47+
err = worker.Run(viper.GetString("channel") != utils.Channel)
48+
if err != nil {
49+
if !silent {
50+
fmt.Println(err)
51+
os.Exit(1)
52+
}
53+
54+
os.Exit(0)
55+
}
56+
}

0 commit comments

Comments
 (0)