Skip to content

Commit

Permalink
Revert "Reinstate analytics (#139)"
Browse files Browse the repository at this point in the history
This reverts commit 4b62d9e.
  • Loading branch information
systemizer committed Sep 27, 2018
1 parent 4b62d9e commit 1e7134a
Show file tree
Hide file tree
Showing 16 changed files with 8 additions and 195 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# This makefile is meant for humans

VERSION := $(shell git describe --tags --always --dirty="-dev")
ANALYTICS_WRITE_KEY ?=
LDFLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.AnalyticsWriteKey=$(ANALYTICS_WRITE_KEY)"'
LDFLAGS := -ldflags='-X "main.Version=$(VERSION)"'

test:
GO111MODULE=on go test -v ./...
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ To configure chamber to use the S3 backend, set `CHAMBER_SECRET_BACKEND` to `S3`

This feature is experimental, and not currently meant for production work.

## Analytics

`chamber` includes some usage analytics code which Segment uses internally for tracking usage of internal tools. This analytics code is turned off by default, and can only be enabled via a linker flag at build time, which we do not set for public github releases.

## Releasing

To cut a new release, just push a tag named `v<semver>` where `<semver>` is a
Expand Down
13 changes: 0 additions & 13 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/pkg/errors"
"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
analytics "gopkg.in/segmentio/analytics-go.v3"
)

// deleteCmd represents the delete command
Expand All @@ -32,18 +31,6 @@ func delete(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "Failed to validate key")
}

if analyticsEnabled && analyticsClient != nil {
analyticsClient.Enqueue(analytics.Track{
UserId: username,
Event: "Ran Command",
Properties: analytics.NewProperties().
Set("command", "delete").
Set("chamber-version", chamberVersion).
Set("service", service).
Set("key", key).
Set("backend", backend),
})
}
secretStore, err := getSecretStore()
if err != nil {
return errors.Wrap(err, "Failed to get secret store")
Expand Down
13 changes: 0 additions & 13 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/pkg/errors"
"github.com/spf13/cobra"
analytics "gopkg.in/segmentio/analytics-go.v3"
)

// execCmd represents the exec command
Expand Down Expand Up @@ -38,18 +37,6 @@ func execRun(cmd *cobra.Command, args []string) error {
dashIx := cmd.ArgsLenAtDash()
services, command, commandArgs := args[:dashIx], args[dashIx], args[dashIx+1:]

if analyticsEnabled && analyticsClient != nil {
analyticsClient.Enqueue(analytics.Track{
UserId: username,
Event: "Ran Command",
Properties: analytics.NewProperties().
Set("command", "exec").
Set("chamber-version", chamberVersion).
Set("services", services).
Set("backend", backend),
})
}

env := environ(os.Environ())
secretStore, err := getSecretStore()
if err != nil {
Expand Down
13 changes: 0 additions & 13 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/magiconair/properties"
"github.com/pkg/errors"
"github.com/spf13/cobra"
analytics "gopkg.in/segmentio/analytics-go.v3"
)

// exportCmd represents the export command
Expand All @@ -38,18 +37,6 @@ func init() {
func runExport(cmd *cobra.Command, args []string) error {
var err error

if analyticsEnabled && analyticsClient != nil {
analyticsClient.Enqueue(analytics.Track{
UserId: username,
Event: "Ran Command",
Properties: analytics.NewProperties().
Set("command", "export").
Set("chamber-version", chamberVersion).
Set("services", args).
Set("backend", backend),
})
}

secretStore, err := getSecretStore()
if err != nil {
return err
Expand Down
14 changes: 0 additions & 14 deletions cmd/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/pkg/errors"
"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
analytics "gopkg.in/segmentio/analytics-go.v3"
)

// historyCmd represents the history command
Expand All @@ -35,19 +34,6 @@ func history(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "Failed to validate key")
}

if analyticsEnabled && analyticsClient != nil {
analyticsClient.Enqueue(analytics.Track{
UserId: username,
Event: "Ran Command",
Properties: analytics.NewProperties().
Set("command", "history").
Set("chamber-version", chamberVersion).
Set("service", service).
Set("key", key).
Set("backend", backend),
})
}

secretStore, err := getSecretStore()
if err != nil {
return errors.Wrap(err, "Failed to get secret store")
Expand Down
13 changes: 0 additions & 13 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/pkg/errors"
"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
analytics "gopkg.in/segmentio/analytics-go.v3"
)

var (
Expand Down Expand Up @@ -52,18 +51,6 @@ func importRun(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "Failed to decode input as json")
}

if analyticsEnabled && analyticsClient != nil {
analyticsClient.Enqueue(analytics.Track{
UserId: username,
Event: "Ran Command",
Properties: analytics.NewProperties().
Set("command", "import").
Set("chamber-version", chamberVersion).
Set("service", service).
Set("backend", backend),
})
}

secretStore, err := getSecretStore()
if err != nil {
return errors.Wrap(err, "Failed to get secret store")
Expand Down
14 changes: 1 addition & 13 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/pkg/errors"
"github.com/spf13/cobra"
analytics "gopkg.in/segmentio/analytics-go.v3"
)

// listCmd represents the list command
Expand All @@ -34,22 +33,11 @@ func list(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "Failed to validate service")
}

if analyticsEnabled && analyticsClient != nil {
analyticsClient.Enqueue(analytics.Track{
UserId: username,
Event: "Ran Command",
Properties: analytics.NewProperties().
Set("command", "list").
Set("chamber-version", chamberVersion).
Set("service", service).
Set("backend", backend),
})
}

secretStore, err := getSecretStore()
if err != nil {
return errors.Wrap(err, "Failed to get secret store")
}

secrets, err := secretStore.List(service, withValues)
if err != nil {
return errors.Wrap(err, "Failed to list store contents")
Expand Down
14 changes: 0 additions & 14 deletions cmd/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/pkg/errors"
"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
analytics "gopkg.in/segmentio/analytics-go.v3"
)

var (
Expand Down Expand Up @@ -42,19 +41,6 @@ func read(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "Failed to validate key")
}

if analyticsEnabled && analyticsClient != nil {
analyticsClient.Enqueue(analytics.Track{
UserId: username,
Event: "Ran Command",
Properties: analytics.NewProperties().
Set("command", "read").
Set("chamber-version", chamberVersion).
Set("service", service).
Set("key", key).
Set("backend", backend),
})
}

secretStore, err := getSecretStore()
if err != nil {
return errors.Wrap(err, "Failed to get secret store")
Expand Down
45 changes: 4 additions & 41 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
analytics "gopkg.in/segmentio/analytics-go.v3"
)

// Regex's used to validate service and key names
Expand All @@ -20,12 +19,6 @@ var (
verbose bool
numRetries int
chamberVersion string
backend string

analyticsEnabled bool
analyticsWriteKey string
analyticsClient analytics.Client
username string
)

const (
Expand All @@ -47,11 +40,9 @@ var Backends = []string{SSMBackend, S3Backend}

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "chamber",
Short: "CLI for storing secrets",
SilenceUsage: true,
PersistentPreRun: prerun,
PersistentPostRun: postrun,
Use: "chamber",
Short: "CLI for storing secrets",
SilenceUsage: true,
}

func init() {
Expand All @@ -61,12 +52,8 @@ func init() {

// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute(vers string, writeKey string) {
func Execute(vers string) {
chamberVersion = vers

analyticsWriteKey = writeKey
analyticsEnabled = analyticsWriteKey != ""

if cmd, err := RootCmd.ExecuteC(); err != nil {
if strings.Contains(err.Error(), "arg(s)") || strings.Contains(err.Error(), "usage") {
cmd.Usage()
Expand Down Expand Up @@ -112,27 +99,3 @@ func getSecretStore() (store.Store, error) {
}
return s, err
}

func prerun(cmd *cobra.Command, args []string) {
backend = strings.ToUpper(os.Getenv(BackendEnvVar))

if analyticsEnabled {
// set up analytics client
analyticsClient, _ = analytics.NewWithConfig(analyticsWriteKey, analytics.Config{
BatchSize: 1,
})

username = os.Getenv("USER")
analyticsClient.Enqueue(analytics.Identify{
UserId: username,
Traits: analytics.NewTraits().
Set("chamber-version", chamberVersion),
})
}
}

func postrun(cmd *cobra.Command, args []string) {
if analyticsEnabled && analyticsClient != nil {
analyticsClient.Close()
}
}
11 changes: 0 additions & 11 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"

"github.com/spf13/cobra"
analytics "gopkg.in/segmentio/analytics-go.v3"
)

// versionCmd represents the version command
Expand All @@ -21,15 +20,5 @@ func init() {

func versionRun(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stdout, "chamber %s\n", chamberVersion)
if analyticsEnabled && analyticsClient != nil {
analyticsClient.Enqueue(analytics.Track{
UserId: username,
Event: "Ran Command",
Properties: analytics.NewProperties().
Set("command", "version").
Set("chamber-version", chamberVersion).
Set("backend", backend),
})
}
return nil
}
14 changes: 0 additions & 14 deletions cmd/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/pkg/errors"
"github.com/segmentio/chamber/store"
"github.com/spf13/cobra"
analytics "gopkg.in/segmentio/analytics-go.v3"
)

var (
Expand Down Expand Up @@ -40,19 +39,6 @@ func write(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "Failed to validate key")
}

if analyticsEnabled && analyticsClient != nil {
analyticsClient.Enqueue(analytics.Track{
UserId: username,
Event: "Ran Command",
Properties: analytics.NewProperties().
Set("command", "write").
Set("chamber-version", chamberVersion).
Set("service", service).
Set("backend", backend).
Set("key", key),
})
}

value := args[2]
if value == "-" {
// Read value from standard input
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ require (
github.com/magiconair/properties v1.8.0
github.com/pkg/errors v0.8.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.2 // indirect
github.com/stretchr/testify v1.2.2
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
gopkg.in/segmentio/analytics-go.v3 v3.0.0
)
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/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/segmentio/backo-go v0.0.0-20160424052352-204274ad699c h1:rsRTAcCR5CeNLkvgBVSjQoDGRRt6kggsE6XYBqCv2KQ=
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c/go.mod h1:kJ9mm9YmoWSkk+oQ+5Cj8DEoRCX2JT6As4kEtIIOp1M=
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=
gopkg.in/segmentio/analytics-go.v3 v3.0.0 h1:CyPSnB9Y3MhF/lL71ARYukL7Si55KADW9fGJFDEPG0E=
gopkg.in/segmentio/analytics-go.v3 v3.0.0/go.mod h1:4QqqlTlSSpVlWA9/9nDcPw+FkM2yv1NQoYjUbL9/JAw=
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import "github.com/segmentio/chamber/cmd"

var (
// This is updated by linker flags during build
Version = "dev"
AnalyticsWriteKey = ""
Version = "dev"
)

func main() {
cmd.Execute(Version, AnalyticsWriteKey)
cmd.Execute(Version)
}
Loading

0 comments on commit 1e7134a

Please sign in to comment.