(ctx context.Context)
| 27 | ) |
| 28 | |
| 29 | func (s *ScaleSetClient) getActionServiceInfo(ctx context.Context) (_ params.ActionsServiceAdminInfoResponse, err error) { |
| 30 | s.recordOperation("GetActionServiceInfo") |
| 31 | defer func() { |
| 32 | if err != nil { |
| 33 | s.recordFailedOperation("GetActionServiceInfo") |
| 34 | } |
| 35 | }() |
| 36 | |
| 37 | regPath := "/actions/runner-registration" |
| 38 | baseURL := s.ghCli.GithubBaseURL() |
| 39 | url, err := baseURL.Parse(regPath) |
| 40 | if err != nil { |
| 41 | return params.ActionsServiceAdminInfoResponse{}, fmt.Errorf("failed to parse url: %w", err) |
| 42 | } |
| 43 | |
| 44 | entity := s.ghCli.GetEntity() |
| 45 | body := params.ActionsServiceAdminInfoRequest{ |
| 46 | URL: entity.ForgeURL(), |
| 47 | RunnerEvent: "register", |
| 48 | } |
| 49 | |
| 50 | buf := &bytes.Buffer{} |
| 51 | enc := json.NewEncoder(buf) |
| 52 | enc.SetEscapeHTML(false) |
| 53 | |
| 54 | if err := enc.Encode(body); err != nil { |
| 55 | return params.ActionsServiceAdminInfoResponse{}, err |
| 56 | } |
| 57 | req, err := http.NewRequestWithContext(ctx, http.MethodPost, url.String(), buf) |
| 58 | if err != nil { |
| 59 | return params.ActionsServiceAdminInfoResponse{}, fmt.Errorf("failed to create request: %w", err) |
| 60 | } |
| 61 | |
| 62 | req.Header.Set("Content-Type", "application/json") |
| 63 | req.Header.Set("Authorization", fmt.Sprintf("RemoteAuth %s", *s.runnerRegistrationToken.Token)) |
| 64 | |
| 65 | resp, err := s.Do(req) |
| 66 | if err != nil { |
| 67 | return params.ActionsServiceAdminInfoResponse{}, fmt.Errorf("failed to get actions service admin info: %w", err) |
| 68 | } |
| 69 | defer resp.Body.Close() |
| 70 | |
| 71 | data, err := io.ReadAll(resp.Body) |
| 72 | if err != nil { |
| 73 | return params.ActionsServiceAdminInfoResponse{}, fmt.Errorf("failed to read response body: %w", err) |
| 74 | } |
| 75 | data = bytes.TrimPrefix(data, []byte("\xef\xbb\xbf")) |
| 76 | |
| 77 | var info params.ActionsServiceAdminInfoResponse |
| 78 | if err := json.Unmarshal(data, &info); err != nil { |
| 79 | return params.ActionsServiceAdminInfoResponse{}, fmt.Errorf("failed to decode response: %w", err) |
| 80 | } |
| 81 | |
| 82 | return info, nil |
| 83 | } |
| 84 | |
| 85 | func (s *ScaleSetClient) ensureAdminInfo(ctx context.Context) error { |
| 86 | s.mux.Lock() |
no test coverage detected