Skip to content

Commit e8bf9fd

Browse files
authored
Merge pull request ActiveState#3369 from ActiveState/version/0-44-1-RC2
Version 0.44.1-RC2
2 parents 431e80d + 9b2812a commit e8bf9fd

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

cmd/state/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,14 @@ func run(args []string, isInteractive bool, cfg *config.Instance, out output.Out
168168
if auth.AvailableAPIToken() != "" {
169169
jwt, err := svcmodel.GetJWT(context.Background())
170170
if err != nil {
171-
return locale.NewError("err_main_jwt", "", errs.JoinMessage(err))
171+
multilog.Critical("Could not get JWT: %v", errs.JoinMessage(err))
172+
}
173+
if err != nil || jwt == nil {
174+
// Could not authenticate; user got logged out
175+
auth.Logout()
176+
} else {
177+
auth.UpdateSession(jwt)
172178
}
173-
auth.UpdateSession(jwt)
174179
}
175180

176181
projectfile.RegisterMigrator(migrator.NewMigrator(auth, cfg))

pkg/platform/authentication/auth.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,18 @@ func (s *Auth) Sync() error {
122122

123123
// MaybeRenew will renew the JWT if it has expired
124124
// This should only be called from the state-svc.
125-
func (s *Auth) MaybeRenew() error {
125+
func (s *Auth) MaybeRenew() (rerr error) {
126+
defer func() {
127+
if rerr == nil {
128+
return
129+
}
130+
131+
var errUnauthorized *apiAuth.PostLoginUnauthorized
132+
if errors.As(rerr, &errUnauthorized) {
133+
logging.Warning("API token invalid, clearing stored token: %s", errUnauthorized.Error())
134+
rerr = s.Logout()
135+
}
136+
}()
126137
// If we're out of sync then we should just always renew
127138
if s.SyncRequired() {
128139
err := s.Sync()
@@ -185,6 +196,7 @@ func (s *Auth) updateRollbarPerson() {
185196
}
186197

187198
func (s *Auth) resetSession() {
199+
s.client = nil
188200
s.clientAuth = nil
189201
s.lastRenewal = nil
190202
s.bearerToken = ""
@@ -359,10 +371,7 @@ func (s *Auth) Logout() error {
359371
return locale.WrapError(err, "err_logout_cfg", "Could not update config, if this persists please try running '[ACTIONABLE]state clean config[/RESET]'.")
360372
}
361373

362-
s.client = nil
363-
s.clientAuth = nil
364-
s.bearerToken = ""
365-
s.user = nil
374+
s.resetSession()
366375

367376
// This is a bit of a hack, but it's safe to assume that the global legacy use-case should be reset whenever we logout a specific instance
368377
// Handling it any other way would be far too error-prone by comparison

pkg/platform/model/svc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ func (m *SvcModel) GetJWT(ctx context.Context) (*mono_models.JWT, error) {
190190
return nil, errs.Wrap(err, "Error sending messages request")
191191
}
192192

193-
jwt := mono_models.JWT{}
193+
jwt := &mono_models.JWT{}
194194
err := json.Unmarshal(resp.Payload, &jwt)
195195
if err != nil {
196196
return nil, errs.Wrap(err, "Error unmarshaling JWT")
197197
}
198198

199-
return &jwt, nil
199+
return jwt, nil
200200
}
201201

202202
func jsonFromMap(m map[string]interface{}) string {

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.44.1-RC1
1+
0.44.1-RC2

0 commit comments

Comments
 (0)