Skip to content

Commit

Permalink
fix decode the key (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaneur2020 authored Mar 17, 2023
1 parent 7a00e67 commit 980d682
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godatabend

import (
"context"
"io/ioutil"

"github.com/BurntSushi/toml"
)
Expand Down Expand Up @@ -41,11 +42,18 @@ func NewFileAccessTokenLoader(path string) *FileAccessTokenLoader {
}
}

// try decode as toml, if not toml, return the plain key content
func (l *FileAccessTokenLoader) LoadAccessToken(ctx context.Context, forceRotate bool) (string, error) {
data := &FileAccessTokenData{}
_, err := toml.DecodeFile(l.path, &data)
buf, err := ioutil.ReadFile(l.path)
if err != nil {
return "", err
}
return data.AccessToken, nil
content := string(buf)

data := &FileAccessTokenData{}
if _, err = toml.Decode(content, &data); err == nil {
return data.AccessToken, nil
}

return content, nil
}

0 comments on commit 980d682

Please sign in to comment.