(ctx context.Context, instance string, pool params.Pool, labels []string)
| 489 | } |
| 490 | |
| 491 | func (g *githubClient) GetEntityJITConfig(ctx context.Context, instance string, pool params.Pool, labels []string) (jitConfigMap map[string]string, runner *github.Runner, err error) { |
| 492 | rgID, err := g.GetEntityRunnerGroupIDByName(ctx, pool.GitHubRunnerGroup) |
| 493 | if err != nil { |
| 494 | return nil, nil, fmt.Errorf("failed to get runner group: %w", err) |
| 495 | } |
| 496 | slog.DebugContext(ctx, "using runner group", "group_name", pool.GitHubRunnerGroup, "runner_group_id", rgID) |
| 497 | req := github.GenerateJITConfigRequest{ |
| 498 | Name: instance, |
| 499 | RunnerGroupID: rgID, |
| 500 | Labels: labels, |
| 501 | // nolint:golangci-lint,godox |
| 502 | // TODO(gabriel-samfira): Should we make this configurable? |
| 503 | WorkFolder: github.Ptr("_work"), |
| 504 | } |
| 505 | |
| 506 | metrics.GithubOperationCount.WithLabelValues( |
| 507 | "GetEntityJITConfig", // label: operation |
| 508 | g.entity.LabelScope(), // label: scope |
| 509 | ).Inc() |
| 510 | |
| 511 | var ret *github.JITRunnerConfig |
| 512 | var response *github.Response |
| 513 | |
| 514 | switch g.entity.EntityType { |
| 515 | case params.ForgeEntityTypeRepository: |
| 516 | ret, response, err = g.GenerateRepoJITConfig(ctx, g.entity.Owner, g.entity.Name, &req) |
| 517 | case params.ForgeEntityTypeOrganization: |
| 518 | ret, response, err = g.GenerateOrgJITConfig(ctx, g.entity.Owner, &req) |
| 519 | case params.ForgeEntityTypeEnterprise: |
| 520 | ret, response, err = g.enterprise.GenerateEnterpriseJITConfig(ctx, g.entity.Owner, &req) |
| 521 | } |
| 522 | if err == nil && response != nil { |
| 523 | g.recordLimits(response.Rate) |
| 524 | } |
| 525 | if err != nil { |
| 526 | metrics.GithubOperationFailedCount.WithLabelValues( |
| 527 | "GetEntityJITConfig", // label: operation |
| 528 | g.entity.LabelScope(), // label: scope |
| 529 | ).Inc() |
| 530 | if response != nil && response.StatusCode == http.StatusUnauthorized { |
| 531 | return nil, nil, fmt.Errorf("failed to get JIT config: %w", err) |
| 532 | } |
| 533 | return nil, nil, fmt.Errorf("failed to get JIT config: %w", err) |
| 534 | } |
| 535 | |
| 536 | defer func(run *github.Runner) { |
| 537 | if err != nil && run != nil { |
| 538 | innerErr := g.RemoveEntityRunner(ctx, run.GetID()) |
| 539 | slog.With(slog.Any("error", innerErr)).ErrorContext( |
| 540 | ctx, "failed to remove runner", |
| 541 | "runner_id", run.GetID(), string(g.entity.EntityType), g.entity.String()) |
| 542 | } |
| 543 | }(ret.Runner) |
| 544 | |
| 545 | decoded, err := base64.StdEncoding.DecodeString(*ret.EncodedJITConfig) |
| 546 | if err != nil { |
| 547 | return nil, nil, fmt.Errorf("failed to decode JIT config: %w", err) |
| 548 | } |
nothing calls this directly
no test coverage detected