diff --git a/context/blank_context.go b/context/blank_context.go index 166026598..e7e48c878 100644 --- a/context/blank_context.go +++ b/context/blank_context.go @@ -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 } diff --git a/context/context.go b/context/context.go index 4e72e4e2f..86c8767fa 100644 --- a/context/context.go +++ b/context/context.go @@ -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 {