-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CLI usage with no pre-set context/config #420
Changes from all commits
c4a1684
6953f57
3f13864
c57f1cb
3dfd468
5b857c3
ddf0f62
ca7c55d
1948291
75a4c78
05907d8
d7a9a00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,6 @@ import ( | |
"github.com/authzed/zed/internal/console" | ||
) | ||
|
||
// ErrTokenNotFound is returned if there is no Token in a ConfigStore. | ||
var ErrTokenNotFound = errors.New("token does not exist") | ||
|
||
type Token struct { | ||
Name string | ||
Endpoint string | ||
|
@@ -72,7 +69,8 @@ type SecretStore interface { | |
Put(s Secrets) error | ||
} | ||
|
||
func GetToken(name string, ss SecretStore) (Token, error) { | ||
// Returns an empty token if no token exists. | ||
func GetTokenIfExists(name string, ss SecretStore) (Token, error) { | ||
secrets, err := ss.Get() | ||
if err != nil { | ||
return Token{}, err | ||
|
@@ -84,7 +82,22 @@ func GetToken(name string, ss SecretStore) (Token, error) { | |
} | ||
} | ||
|
||
return Token{}, ErrTokenNotFound | ||
return Token{}, nil | ||
} | ||
|
||
func TokenExists(name string, ss SecretStore) (bool, error) { | ||
secrets, err := ss.Get() | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
for _, token := range secrets.Tokens { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is fine but makes me think Also maybe this would make sense as a method on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, as I was going through this there were a bunch of things that seemed like they could be reorganized. I want to get the fix out and then loop back. |
||
if name == token.Name { | ||
return true, nil | ||
} | ||
} | ||
|
||
return false, nil | ||
} | ||
|
||
func PutToken(t Token, ss SecretStore) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't CLI override... override the context?