MCPcopy Create free account
hub / github.com/Scalingo/cli / StoreAuth

Method StoreAuth

config/auth.go:77–112  ·  view source on GitHub ↗
(ctx context.Context, user *scalingo.User, token string)

Source from the content-addressed store, hash-verified

75}
76
77func (a *CliAuthenticator) StoreAuth(ctx context.Context, user *scalingo.User, token string) error {
78 authConfig, err := existingAuth(ctx)
79 if err != nil {
80 return errors.Wrap(ctx, err, "read existing authentication config")
81 }
82
83 var c auth.ConfigPerHostV2
84 err = json.Unmarshal(authConfig.AuthConfigPerHost, &c)
85 if err != nil {
86 fmt.Println("Auth: error while reading auth file. Recreating a new one.")
87 c = make(auth.ConfigPerHostV2)
88 }
89
90 authHost, err := a.authHost(ctx)
91 if err != nil {
92 return errors.Wrapf(ctx, err, "fail to get authentication service host")
93 }
94
95 c[authHost] = auth.CredentialsData{
96 Tokens: &auth.UserToken{
97 Token: token,
98 },
99 User: user,
100 }
101
102 authConfig.LastUpdate = time.Now()
103 authConfig.AuthDataVersion = auth.ConfigVersionV21
104
105 buffer, err := json.Marshal(&c)
106 if err != nil {
107 return errors.Wrapf(ctx, err, "fail to marshal the configuration to JSON")
108 }
109
110 authConfig.AuthConfigPerHost = json.RawMessage(buffer)
111 return writeAuthFile(ctx, authConfig)
112}
113
114func (a *CliAuthenticator) LoadAuth(ctx context.Context) (*scalingo.User, *auth.UserToken, error) {
115 file, err := os.OpenFile(C.AuthFile, os.O_RDONLY, 0600)

Callers 3

SetCurrentUserFunction · 0.95
TestStoreAuthFunction · 0.95
TestExistingAuthFunction · 0.95

Calls 3

authHostMethod · 0.95
existingAuthFunction · 0.85
writeAuthFileFunction · 0.85

Tested by 2

TestStoreAuthFunction · 0.76
TestExistingAuthFunction · 0.76