downloadFileViaPublicAPI downloads a file from a public GitHub repository using an unauthenticated API call. Used as a last-resort fallback when both authenticated API and git clone fail (e.g. enterprise SAML tokens).
(ctx context.Context, owner, repo, path, ref string)
| 985 | // using an unauthenticated API call. Used as a last-resort fallback when both |
| 986 | // authenticated API and git clone fail (e.g. enterprise SAML tokens). |
| 987 | func downloadFileViaPublicAPI(ctx context.Context, owner, repo, path, ref string) ([]byte, error) { |
| 988 | remoteLog.Printf("Attempting unauthenticated public API download for %s/%s/%s@%s", owner, repo, path, ref) |
| 989 | body, err := fetchPublicGitHubContentsAPI(ctx, owner, repo, path, ref) |
| 990 | if err != nil { |
| 991 | return nil, fmt.Errorf("unauthenticated public API also failed for %s/%s/%s@%s: %w", owner, repo, path, ref, err) |
| 992 | } |
| 993 | |
| 994 | var fileContent struct { |
| 995 | Content string `json:"content"` |
| 996 | Encoding string `json:"encoding"` |
| 997 | } |
| 998 | if err := json.Unmarshal(body, &fileContent); err != nil { |
| 999 | return nil, fmt.Errorf("failed to parse public API file response: %w", err) |
| 1000 | } |
| 1001 | if fileContent.Content == "" { |
| 1002 | return nil, fmt.Errorf("empty content returned from public API for %s/%s/%s@%s", owner, repo, path, ref) |
| 1003 | } |
| 1004 | |
| 1005 | content, err := base64.StdEncoding.DecodeString(fileContent.Content) |
| 1006 | if err != nil { |
| 1007 | return nil, fmt.Errorf("failed to decode base64 content from public API: %w", err) |
| 1008 | } |
| 1009 | return content, nil |
| 1010 | } |
| 1011 | |
| 1012 | func retryDownloadViaResolvedSymlink( |
| 1013 | client *api.RESTClient, |
no test coverage detected