MCPcopy Create free account
hub / github.com/cloudbase/garm / GetInstanceGithubRegistrationToken

Method GetInstanceGithubRegistrationToken

runner/metadata.go:547–592  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

545}
546
547func (r *Runner) GetInstanceGithubRegistrationToken(ctx context.Context) (string, error) {
548 // Check if this instance already fetched a registration token or if it was configured using
549 // the Just In Time runner feature. If we're still using the old way of configuring a runner,
550 // we only allow an instance to fetch one token. If the instance fails to bootstrap after a token
551 // is fetched, we reset the token fetched field when re-queueing the instance.
552 if auth.InstanceTokenFetched(ctx) || auth.InstanceHasJITConfig(ctx) {
553 return "", runnerErrors.ErrUnauthorized
554 }
555
556 status := auth.InstanceRunnerStatus(ctx)
557 if status != params.RunnerPending && status != params.RunnerInstalling {
558 return "", runnerErrors.ErrUnauthorized
559 }
560
561 instance, err := auth.InstanceParams(ctx)
562 if err != nil {
563 slog.With(slog.Any("error", err)).ErrorContext(
564 ctx, "failed to get instance params")
565 return "", runnerErrors.ErrUnauthorized
566 }
567
568 poolMgr, err := r.getPoolManagerFromInstance(ctx, instance)
569 if err != nil {
570 return "", fmt.Errorf("error fetching pool manager for instance %s (%s): %w", instance.Name, instance.PoolID, err)
571 }
572
573 token, err := poolMgr.GithubRunnerRegistrationToken()
574 if err != nil {
575 return "", fmt.Errorf("error fetching runner token: %w", err)
576 }
577
578 tokenFetched := true
579 updateParams := params.UpdateInstanceParams{
580 TokenFetched: &tokenFetched,
581 }
582
583 if _, err := r.store.UpdateInstance(r.ctx, instance.Name, updateParams); err != nil {
584 return "", fmt.Errorf("error setting token_fetched for instance: %w", err)
585 }
586
587 if err := r.store.AddInstanceEvent(ctx, instance.Name, params.FetchTokenEvent, params.EventInfo, "runner registration token was retrieved"); err != nil {
588 return "", fmt.Errorf("error recording event: %w", err)
589 }
590
591 return token, nil
592}
593
594func (r *Runner) GetRootCertificateBundle(ctx context.Context) (params.CertificateBundle, error) {
595 instance, err := auth.InstanceParams(ctx)

Calls 8

InstanceTokenFetchedFunction · 0.92
InstanceHasJITConfigFunction · 0.92
InstanceRunnerStatusFunction · 0.92
InstanceParamsFunction · 0.92
UpdateInstanceMethod · 0.65
AddInstanceEventMethod · 0.65