Skip to content

Commit 72cd66d

Browse files
authored
Merge pull request ActiveState#3356 from ActiveState/DX-2895
State Tool does not call login API each invocation; uses JWT from svc
2 parents 010bfe5 + 1909f79 commit 72cd66d

File tree

17 files changed

+1022
-151
lines changed

17 files changed

+1022
-151
lines changed

cmd/state-svc/internal/resolver/resolver.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,40 @@ func (r *Resolver) GetProcessesInUse(ctx context.Context, execDir string) ([]*gr
262262
return processes, nil
263263
}
264264

265+
func (r *Resolver) GetJwt(ctx context.Context) (*graph.Jwt, error) {
266+
if err := r.auth.MaybeRenew(); err != nil {
267+
return nil, errs.Wrap(err, "Could not renew auth token")
268+
}
269+
270+
if !r.auth.Authenticated() {
271+
return nil, nil
272+
}
273+
274+
user := r.auth.User()
275+
if user == nil {
276+
return nil, errs.New("user is nil")
277+
}
278+
279+
jwt := &graph.Jwt{
280+
Token: r.auth.BearerToken(),
281+
User: &graph.User{
282+
UserID: user.UserID.String(),
283+
Username: user.Username,
284+
Email: user.Email,
285+
Organizations: []*graph.Organization{},
286+
},
287+
}
288+
289+
for _, org := range user.Organizations {
290+
jwt.User.Organizations = append(jwt.User.Organizations, &graph.Organization{
291+
URLname: org.URLname,
292+
Role: org.Role,
293+
})
294+
}
295+
296+
return jwt, nil
297+
}
298+
265299
func handlePanics(recovered interface{}, stack []byte) {
266300
if recovered != nil {
267301
multilog.Error("Panic: %v", recovered)

0 commit comments

Comments
 (0)