Skip to content

Commit

Permalink
chore: add go releaser
Browse files Browse the repository at this point in the history
  • Loading branch information
adikari committed Sep 30, 2022
1 parent 68bfc56 commit 1110049
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ go.work

# End of https://www.toptal.com/developers/gitignore/api/go

dist
safebox
dist/
27 changes: 27 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
before:
hooks:
- go mod tidy
builds:
- binary: safebox
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ incpatch .Version }}-next"

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
48 changes: 0 additions & 48 deletions Makefile

This file was deleted.

10 changes: 8 additions & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ func init() {
}

func list(cmd *cobra.Command, args []string) error {
store, err := getStore()
config, err := loadConfig()

if err != nil {
return errors.Wrap(err, "failed to load config")
}

store, err := store.GetStore(config.Provider)

if err != nil {
return errors.Wrap(err, "failed to instantiate store")
}

var keys []string

for _, value := range Config.Configs {
for _, value := range config.Configs {
keys = append(keys, value.Key)
}

Expand Down
38 changes: 7 additions & 31 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
package cmd

import (
"fmt"
"os"
"strings"

c "github.com/adikari/safebox/v2/config"
"github.com/adikari/safebox/v2/store"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var (
stage string
pathToConfig string
Config *c.Config
TimeFormat = "2006-01-02 15:04:05"
)

var rootCmd = &cobra.Command{
Use: "safebox",
Short: "SafeBox is a secret manager CLI program",
Long: `A Fast and Flexible secret manager built with love by adikari in Go.`,
PersistentPreRunE: prerun,
SilenceUsage: true,
Use: "safebox",
Short: "SafeBox is a secret manager CLI program",
Long: `A Fast and Flexible secret manager built with love by adikari in Go.`,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
cmd.Usage()
},
}

func init() {
rootCmd.PersistentFlags().StringVarP(&stage, "stage", "s", "", "stage to deploy to")
rootCmd.PersistentFlags().StringVarP(&stage, "stage", "s", "dev", "stage to deploy to")

rootCmd.PersistentFlags().StringVarP(&pathToConfig, "config", "c", "safebox.yml", "path to safebox configuration file")
rootCmd.MarkPersistentFlagRequired("stage")
rootCmd.MarkFlagFilename("config")
}

func Execute(version string) {
Expand All @@ -47,17 +43,6 @@ func Execute(version string) {
}
}

func prerun(cmd *cobra.Command, args []string) error {
c, err := loadConfig()

if err != nil {
return errors.Wrap(err, "failed to load config")
}

Config = c
return nil
}

func loadConfig() (*c.Config, error) {
params := c.LoadParam{
Path: pathToConfig,
Expand All @@ -66,12 +51,3 @@ func loadConfig() (*c.Config, error) {

return c.Load(params)
}

func getStore() (store.Store, error) {
switch Config.Provider {
case "ssm":
return store.NewSSMStore()
default:
return nil, fmt.Errorf("invalid provider `%s`", Config.Provider)
}
}
11 changes: 9 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/adikari/safebox/v2/store"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand All @@ -18,13 +19,19 @@ func init() {
}

func run(cmd *cobra.Command, args []string) error {
store, err := getStore()
config, err := loadConfig()

if err != nil {
return errors.Wrap(err, "failed to load config")
}

store, err := store.GetStore(config.Provider)

if err != nil {
return errors.Wrap(err, "failed to instantiate store")
}

err = store.PutMany(Config.Configs)
err = store.PutMany(config.Configs)

if err != nil {
return errors.Wrap(err, "failed to write param")
Expand Down
9 changes: 9 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ func Load(param LoadParam) (*Config, error) {
return nil, fmt.Errorf("could not parse safebox config file %s", param.Path)
}

if rc.Service == "" {
return nil, fmt.Errorf("'service' missing in config file%s", param.Path)
}

c := Config{}
c.Service = rc.Service
c.Provider = rc.Provider

if c.Provider == "" {
c.Provider = store.SsmProvider
}

parseConfig(rc, &c, param)

return &c, nil
Expand Down
25 changes: 25 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package store

import (
"errors"
"fmt"
"strings"
"time"
)

Expand All @@ -14,6 +16,20 @@ type Config struct {
DataType string
}

func (c *Config) Key() string {
parts := strings.Split(*c.Name, "/")
return parts[len(parts)-1]
}

func (c *Config) Path() string {
parts := strings.Split(*c.Name, "/")
return strings.Join(parts[0:len(parts)-1], "/")
}

const (
SsmProvider = "ssm"
)

type ConfigInput struct {
Key string
Value string
Expand All @@ -32,3 +48,12 @@ type Store interface {
GetAll() ([]Config, error)
Delete(key string) error
}

func GetStore(provider string) (Store, error) {
switch provider {
case SsmProvider:
return NewSSMStore()
default:
return nil, fmt.Errorf("invalid provider `%s`", provider)
}
}

0 comments on commit 1110049

Please sign in to comment.