fishi0x01/saidumlo

View on GitHub
src/main/main.go

Summary

Maintainability
A
0 mins
Test Coverage
package main
 
import (
2: cannot find package "gopkg.in/alecthomas/kingpin.v2" in any of:
"gopkg.in/alecthomas/kingpin.v2"
"os"
"strconv"
)
 
var (
sdlVersion = ""
 
// Ops Ids
readOperationID = "read"
writeOperationID = "write"
 
// cmd config values
configFile = ".secrets.yml"
verbose = false
vaultID = ""
)
 
// CommandWithSecretGroups represents a command which addresses specific secret groups.
type CommandWithSecretGroups struct {
SecretGroups []string
VaultID string
}
 
func printVersion(c *kingpin.ParseContext) error {
logInfo(sdlVersion)
return nil
}
 
func (arg *CommandWithSecretGroups) read(c *kingpin.ParseContext) error {
arg.VaultID = vaultID
arg.processCommandWithSecretGroups(readOperationID)
return nil
}
 
func (arg *CommandWithSecretGroups) write(c *kingpin.ParseContext) error {
arg.VaultID = vaultID
arg.processCommandWithSecretGroups(writeOperationID)
return nil
}
 
func configureCommands(app *kingpin.Application) {
// version
app.Command("version", "Print the version.").Action(printVersion)
 
// read
readArg := &CommandWithSecretGroups{}
readCmd := app.Command("read", "Read secret groups.").Action(readArg.read)
readCmd.Arg("secretGroup", "The secret groups to read.").StringsVar(&readArg.SecretGroups)
 
// write
writeArg := &CommandWithSecretGroups{}
writeCmd := app.Command("write", "Write secret groups.").Action(writeArg.write)
writeCmd.Arg("secretGroup", "The secret groups to write.").StringsVar(&writeArg.SecretGroups)
 
// flags
app.Flag("vault", "Vault").Short('b').StringVar(&vaultID)
app.Flag("config-file", "Config file").Default(configFile).Short('f').StringVar(&configFile)
app.Flag("verbose", "Verbose").Default(strconv.FormatBool(verbose)).Short('v').BoolVar(&verbose)
}
 
func main() {
app := kingpin.New("saidumlo", "SaiDumLo client secret management tool.")
configureCommands(app)
kingpin.MustParse(app.Parse(os.Args[1:]))
}