MCPcopy Create free account
hub / github.com/rilldata/rill / CurrentUserID

Method CurrentUserID

cli/pkg/cmdutil/helper.go:284–330  ·  view source on GitHub ↗

CurrentUserID fetches the ID of the current user. It caches the result in ~/.rill, along with a hash of the current admin token for cache invalidation in case of login/logout.

(ctx context.Context)

Source from the content-addressed store, hash-verified

282// CurrentUserID fetches the ID of the current user.
283// It caches the result in ~/.rill, along with a hash of the current admin token for cache invalidation in case of login/logout.
284func (h *Helper) CurrentUserID(ctx context.Context) (string, error) {
285 if h.AdminToken() == "" {
286 return "", nil
287 }
288
289 newHash := hashStr(h.AdminToken(), h.AdminURL())
290
291 oldHash, err := h.DotRill.GetUserCheckHash()
292 if err != nil {
293 return "", err
294 }
295
296 if oldHash == newHash {
297 userID, err := h.DotRill.GetUserID()
298 if err != nil {
299 return "", err
300 }
301 return userID, nil
302 }
303
304 c, err := h.Client()
305 if err != nil {
306 return "", err
307 }
308
309 res, err := c.GetCurrentUser(ctx, &adminv1.GetCurrentUserRequest{})
310 if err != nil {
311 return "", err
312 }
313
314 var userID string
315 if res.User != nil {
316 userID = res.User.Id
317 }
318
319 err = h.DotRill.SetUserID(userID)
320 if err != nil {
321 return "", err
322 }
323
324 err = h.DotRill.SetUserCheckHash(newHash)
325 if err != nil {
326 return "", err
327 }
328
329 return userID, nil
330}
331
332func (h *Helper) ProjectNamesByGitRemote(ctx context.Context, org, remote, subPath string) ([]string, error) {
333 if org == "" || remote == "" {

Callers 2

TelemetryMethod · 0.95
StartCmdFunction · 0.80

Calls 9

AdminTokenMethod · 0.95
AdminURLMethod · 0.95
ClientMethod · 0.95
hashStrFunction · 0.85
GetUserCheckHashMethod · 0.80
GetUserIDMethod · 0.80
SetUserIDMethod · 0.80
SetUserCheckHashMethod · 0.80
GetCurrentUserMethod · 0.65

Tested by

no test coverage detected