@@ -3,7 +3,6 @@ package config
33
44import (
55 "github.com/spf13/viper"
6- "golang.org/x/oauth2"
76
87 "github.com/zeabur/cli/pkg/zcontext"
98)
@@ -13,32 +12,18 @@ const (
1312 KeyTokenString = "token"
1413 KeyUser = "user"
1514 KeyUsername = "username"
16-
17- // if we use "token.access_token" as key, the env ZEABUR_TOKEN will override all token details,
18- // because "token" is the prefix of "token.access_token".
19- // Therefore, we use "token_detail" as the key to store all token details.
20-
21- KeyTokenDetail = "token_detail"
22- KeyTokenAccess = KeyTokenDetail + ".access_token"
23- KeyTokenExpiry = KeyTokenDetail + ".expiry"
24- KeyTokenType = KeyTokenDetail + ".token_type"
25- KeyTokenRefresh = KeyTokenDetail + ".refresh_token"
2615)
2716
2817// Keys about CLI behavior
2918const (
30- KeyInteractive = "interactive"
31- KeyAutoRefreshToken = "auto_refresh_token"
32- KeyAutoCheckUpdate = "auto_check_update"
19+ KeyInteractive = "interactive"
20+ KeyAutoCheckUpdate = "auto_check_update"
3321)
3422
3523type Config interface {
36- GetTokenString () string // token string is the single token string, it may be set by user or generated from OAuth2
24+ GetTokenString () string // token string is the single token string, it may be set by user or our login function
3725 SetTokenString (token string )
3826
39- GetToken () * oauth2.Token // token is the detail of token, if the token is from OAuth2, it will be set
40- SetToken (token * oauth2.Token )
41-
4227 GetUser () string // nickname of user
4328 SetUser (user string )
4429 GetUsername () string // it is kind like id of user
@@ -72,29 +57,6 @@ func (c *config) SetTokenString(token string) {
7257 viper .Set (KeyTokenString , token )
7358}
7459
75- func (c * config ) GetToken () * oauth2.Token {
76- token := & oauth2.Token {}
77- token .AccessToken = viper .GetString (KeyTokenAccess )
78- token .RefreshToken = viper .GetString (KeyTokenRefresh )
79- token .TokenType = viper .GetString (KeyTokenType )
80- token .Expiry = viper .GetTime (KeyTokenExpiry )
81- if token .AccessToken == "" || token .RefreshToken == "" || token .TokenType == "" || token .Expiry .IsZero () {
82- return nil
83- }
84- return token
85- }
86-
87- func (c * config ) SetToken (token * oauth2.Token ) {
88- if token == nil {
89- viper .Set (KeyTokenDetail , "" )
90- return
91- }
92- viper .Set (KeyTokenAccess , token .AccessToken )
93- viper .Set (KeyTokenRefresh , token .RefreshToken )
94- viper .Set (KeyTokenType , token .TokenType )
95- viper .Set (KeyTokenExpiry , token .Expiry )
96- }
97-
9860func (c * config ) GetUser () string {
9961 return viper .GetString (KeyUser )
10062}
0 commit comments