Skip to content

Commit b098e08

Browse files
authored
fix: Ensure that organization names are always converted to lower-case (#32)
Co-authored-by: Thomas Meckel <tmeckel@users.noreply.github.com>
1 parent 5f23c91 commit b098e08

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

internal/config/auth_config.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ type authConfig struct {
5959
// lastly encrypted storage.
6060
func (c *authConfig) GetToken(organizationName string) (token string, err error) {
6161
logger := zap.L().Sugar()
62+
63+
organizationName = strings.ToLower(organizationName)
64+
6265
logger.Debugf("getting token for organization %s", organizationName)
6366
token, err = c.GetTokenFromEnvOrConfig(organizationName)
6467
if err != nil {
@@ -73,17 +76,21 @@ func (c *authConfig) GetToken(organizationName string) (token string, err error)
7376
// TokenFromEnvOrConfig retrieves an authentication token from environment variables or the config
7477
// file as fallback, but does not support reading the token from system keyring. Most consumers
7578
// should use TokenForHost.
76-
func (c *authConfig) GetTokenFromEnvOrConfig(host string) (token string, err error) {
79+
func (c *authConfig) GetTokenFromEnvOrConfig(organizationName string) (token string, err error) {
80+
organizationName = strings.ToLower(organizationName)
81+
7782
if token, ok := os.LookupEnv(azdoToken); ok {
7883
return token, nil
7984
}
80-
token, err = c.cfg.Get([]string{Organizations, host, "pat"})
85+
token, err = c.cfg.Get([]string{Organizations, organizationName, "pat"})
8186
return
8287
}
8388

8489
// TokenFromKeyring will retrieve the auth token for the given organizationName,
8590
// only searching in encrypted storage.
8691
func (c *authConfig) GetTokenFromKeyring(organizationName string) (token string, err error) {
92+
organizationName = strings.ToLower(organizationName)
93+
8794
token, err = keyring.Get(keyringServiceName(organizationName), "")
8895
if err != nil {
8996
return
@@ -182,6 +189,8 @@ func (c *authConfig) GetOrganizations() []string {
182189
// in encrypted storage and will fall back to the plain text config file.
183190
func (c *authConfig) Login(organizationName, organizationURL, token, gitProtocol string, secureStorage bool) error {
184191
var setErr error
192+
193+
organizationName = strings.ToLower(organizationName)
185194
if secureStorage {
186195
if setErr = keyring.Set(keyringServiceName(organizationName), "", token); setErr == nil {
187196
// Clean up the previous oauth_token from the config file.
@@ -204,6 +213,7 @@ func (c *authConfig) Logout(organizationName string) (err error) {
204213
if organizationName == "" {
205214
return nil
206215
}
216+
organizationName = strings.ToLower(organizationName)
207217
err = c.cfg.Remove([]string{Organizations, organizationName})
208218
if err != nil {
209219
return

0 commit comments

Comments
 (0)