Skip to content

Commit

Permalink
Update dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
lexbritvin committed Oct 14, 2024
1 parent 430ba81 commit 08e51ed
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 61 deletions.
4 changes: 1 addition & 3 deletions cmd/launchr/launchr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
package main

import (
"os"

"github.com/launchrctl/launchr"

_ "github.com/launchrctl/keyring"
)

func main() {
os.Exit(launchr.Run())
launchr.RunAndExit()
}
78 changes: 51 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,54 +1,78 @@
module github.com/launchrctl/keyring

go 1.21

toolchain go1.21.6
go 1.23.1

require (
filippo.io/age v1.1.1
github.com/launchrctl/launchr v0.7.0
github.com/spf13/cobra v1.8.0
golang.org/x/term v0.16.0
filippo.io/age v1.2.0
github.com/launchrctl/launchr v0.16.2
github.com/spf13/cobra v1.8.1
golang.org/x/term v0.25.0
gopkg.in/yaml.v3 v3.0.1
)

require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/a8m/envsubst v1.4.2 // indirect
github.com/containerd/containerd v1.7.13 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.3+incompatible // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.3.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/moby/moby v25.0.3+incompatible // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/signal v0.7.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/sys/sequential v0.6.0 // indirect
github.com/moby/sys/signal v0.7.1 // indirect
github.com/moby/sys/user v0.3.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/otiai10/copy v1.14.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pterm/pterm v0.12.79 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect
go.opentelemetry.io/otel v1.23.1 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
go.opentelemetry.io/otel/trace v1.23.1 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/tools v0.18.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
Expand Down
6 changes: 3 additions & 3 deletions keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type DataStore interface {
Destroy() error
}

// Keyring is a launchr.Service providing password store functionality.
// Keyring is a [launchr.Service] providing password store functionality.
type Keyring interface {
launchr.Service
DataStore
Expand All @@ -95,7 +95,7 @@ func newKeyringService(cfg launchr.Config) Keyring {
}
}

// ServiceInfo implements launchr.Service interface.
// ServiceInfo implements [launchr.Service] interface.
func (k *keyringService) ServiceInfo() launchr.ServiceInfo {
return launchr.ServiceInfo{}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func (k *keyringService) CleanStorage(item SecretItem) error {
return s.CleanStorage(item)
}

// Exists checks if keyring exists in persistent storage.
// Exists implements DataStore, checks if keyring exists in persistent storage.
func (k *keyringService) Exists() bool {
s, err := k.defaultStore()
if err != nil {
Expand Down
51 changes: 26 additions & 25 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/launchrctl/launchr"
"github.com/launchrctl/launchr/pkg/action"
"github.com/launchrctl/launchr/pkg/jsonschema"
"github.com/launchrctl/launchr/pkg/log"
)

const (
Expand All @@ -27,18 +26,18 @@ func init() {
launchr.RegisterPlugin(&Plugin{})
}

// Plugin is launchr plugin providing keyring.
// Plugin is [launchr.Plugin] plugin providing a keyring.
type Plugin struct {
k Keyring
cfg launchr.Config
}

// PluginInfo implements launchr.Plugin interface.
// PluginInfo implements [launchr.Plugin] interface.
func (p *Plugin) PluginInfo() launchr.PluginInfo {
return launchr.PluginInfo{}
}

// OnAppInit implements launchr.Plugin interface.
// OnAppInit implements [launchr.Plugin] interface.
func (p *Plugin) OnAppInit(app launchr.App) error {
app.GetService(&p.cfg)
p.k = newKeyringService(p.cfg)
Expand All @@ -51,32 +50,34 @@ func (p *Plugin) OnAppInit(app launchr.App) error {
return nil
}

// AddValueProcessors submits new ValueProcessors to action.Manager.
// AddValueProcessors adds a keyring [action.ValueProcessor] to [action.Manager].
func AddValueProcessors(m action.Manager, keyring Keyring) {
getByKey := func(value interface{}, options map[string]interface{}) (interface{}, error) {
getByKey := func(value any, options map[string]any) (any, error) {
return getByKeyProcessor(value, options, keyring)
}

proc := action.NewFuncProcessor([]jsonschema.Type{jsonschema.String}, getByKey)
m.AddValueProcessor(getByKeyProc, proc)
}

func getByKeyProcessor(value interface{}, options map[string]interface{}, k Keyring) (interface{}, error) {
func getByKeyProcessor(value any, options map[string]any, k Keyring) (any, error) {
val, ok := value.(string)
if !ok && value != nil {
return val, fmt.Errorf(
"string type is expected for %q processor. Change value type or remove the processor", getByKeyProc,
"string type is expected for %q processor. Change value type or remove the processor",
getByKeyProc,
)
}

if val != "" {
log.Debug("skipping %s processor, value is not empty. Value remains unchanged", getByKeyProc)
launchr.Term().Warning().Printfln("Skipping processor %q, value is not empty. Value will remain unchanged", getByKeyProc)
launchr.Log().Warn("skipping processor, value is not empty", "processor", getByKeyProc)
return value, nil
}

key, ok := options["key"].(string)
if !ok {
return value, fmt.Errorf("option `key` is required for %q processor", getByKeyProc)
return value, fmt.Errorf(`option "key" is required for %q processor`, getByKeyProc)
}

v, err := k.GetForKey(key)
Expand All @@ -90,27 +91,27 @@ func getByKeyProcessor(value interface{}, options map[string]interface{}, k Keyr

var passphrase string

// CobraAddCommands implements launchr.CobraPlugin interface to provide keyring functionality.
func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
// CobraAddCommands implements [launchr.CobraPlugin] interface to provide keyring functionality.
func (p *Plugin) CobraAddCommands(rootCmd *launchr.Command) error {
var creds CredentialsItem
var loginCmd = &cobra.Command{
var loginCmd = &launchr.Command{
Use: "login",
Short: "Logs in to services like git, docker, etc.",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *launchr.Command, args []string) error {
// Don't show usage help on a runtime error.
cmd.SilenceUsage = true
return login(p.k, creds)
},
}

var cleanAll bool
var logoutCmd = &cobra.Command{
var logoutCmd = &launchr.Command{
Use: "logout [URL]",
Short: "Logs out from a service",
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *launchr.Command, args []string) error {
return ensureCleanOption(cmd, args, "please, either provide an URL or use --all flag", cleanAll)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *launchr.Command, args []string) error {
// Don't show usage help on a runtime error.
cmd.SilenceUsage = true

Expand All @@ -124,11 +125,11 @@ func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
}

var key KeyValueItem
var setKeyCmd = &cobra.Command{
var setKeyCmd = &launchr.Command{
Use: "set [key]",
Short: "Store new key-value pair to keyring",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *launchr.Command, args []string) error {
// Don't show usage help on a runtime error.
cmd.SilenceUsage = true

Expand All @@ -137,13 +138,13 @@ func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
},
}

var unsetKeyCmd = &cobra.Command{
var unsetKeyCmd = &launchr.Command{
Use: "unset [key]",
Short: "Removes key-value pair from keyring",
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *launchr.Command, args []string) error {
return ensureCleanOption(cmd, args, "please, either target key or use --all flag", cleanAll)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *launchr.Command, args []string) error {
// Don't show usage help on a runtime error.
cmd.SilenceUsage = true

Expand All @@ -156,10 +157,10 @@ func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
},
}

var purgeCmd = &cobra.Command{
var purgeCmd = &launchr.Command{
Use: "purge",
Short: "Remove existing keyring file",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *launchr.Command, args []string) error {
// Don't show usage help on a runtime error.
cmd.SilenceUsage = true
return purge(p.k)
Expand Down Expand Up @@ -187,7 +188,7 @@ func (p *Plugin) CobraAddCommands(rootCmd *cobra.Command) error {
return nil
}

func ensureCleanOption(_ *cobra.Command, args []string, message string, cleanAll bool) error {
func ensureCleanOption(_ *launchr.Command, args []string, message string, cleanAll bool) error {
if cleanAll && len(args) > 0 || !cleanAll && len(args) == 0 {
return fmt.Errorf(message)
}
Expand Down
2 changes: 1 addition & 1 deletion yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (s *dataStoreYaml) CleanStorage(item SecretItem) error {
return nil
}

// Exists checks if keyring exists in persistent storage.
// Exists implements DataStore, checks if keyring exists in persistent storage.
func (s *dataStoreYaml) Exists() bool {
ageStorage, ok := s.file.(*ageFile)
if !ok {
Expand Down

0 comments on commit 08e51ed

Please sign in to comment.