Add Context.SetAuthToken

This commit is contained in:
Mislav Marohnić 2019-10-18 18:47:42 +02:00
parent de85294c79
commit 2aa77fb8ea
2 changed files with 19 additions and 4 deletions

View file

@ -26,6 +26,10 @@ func (c *blankContext) AuthToken() (string, error) {
return c.authToken, nil
}
func (c *blankContext) SetAuthToken(t string) {
c.authToken = t
}
func (c *blankContext) AuthLogin() (string, error) {
return c.authLogin, nil
}

View file

@ -10,6 +10,7 @@ import (
// Context represents the interface for querying information about the current environment
type Context interface {
AuthToken() (string, error)
SetAuthToken(string)
AuthLogin() (string, error)
Branch() (string, error)
SetBranch(string)
@ -36,10 +37,11 @@ func InitDefaultContext() Context {
// A Context implementation that queries the filesystem
type fsContext struct {
config *configEntry
remotes Remotes
branch string
baseRepo *GitHubRepository
config *configEntry
remotes Remotes
branch string
baseRepo *GitHubRepository
authToken string
}
func (c *fsContext) configFile() string {
@ -54,11 +56,16 @@ func (c *fsContext) getConfig() (*configEntry, error) {
return nil, err
}
c.config = entry
c.authToken = ""
}
return c.config, nil
}
func (c *fsContext) AuthToken() (string, error) {
if c.authToken != "" {
return c.authToken, nil
}
config, err := c.getConfig()
if err != nil {
return "", err
@ -66,6 +73,10 @@ func (c *fsContext) AuthToken() (string, error) {
return config.Token, nil
}
func (c *fsContext) SetAuthToken(t string) {
c.authToken = t
}
func (c *fsContext) AuthLogin() (string, error) {
config, err := c.getConfig()
if err != nil {