DownloadFile will download a module file from coderd.
(ctx context.Context, request *proto.FileRequest)
| 574 | |
| 575 | // DownloadFile will download a module file from coderd. |
| 576 | func (p *Server) DownloadFile(ctx context.Context, request *proto.FileRequest) ([]byte, error) { |
| 577 | data, err := clientDoWithRetries(ctx, p.client, func(ctx context.Context, client proto.DRPCProvisionerDaemonClient) ([]byte, error) { |
| 578 | // Add some timeout to prevent the stream from hanging indefinitely if something goes wrong. |
| 579 | ctx, cancel := context.WithTimeout(ctx, 5*time.Minute) |
| 580 | defer cancel() |
| 581 | |
| 582 | stream, err := client.DownloadFile(ctx, request) |
| 583 | if err != nil { |
| 584 | return nil, xerrors.Errorf("failed to start DownloadFile stream: %w", err) |
| 585 | } |
| 586 | defer stream.Close() |
| 587 | |
| 588 | file, err := provisionersdk.HandleReceivingDataUpload(stream) |
| 589 | if err != nil { |
| 590 | return nil, xerrors.Errorf("failed to handle receiving data upload: %w", err) |
| 591 | } |
| 592 | data, err := file.Complete() |
| 593 | if err != nil { |
| 594 | return nil, xerrors.Errorf("failed to download file: %w", err) |
| 595 | } |
| 596 | return data, nil |
| 597 | }) |
| 598 | if err != nil { |
| 599 | return nil, xerrors.Errorf("download file %s: %w", request.FileId, err) |
| 600 | } |
| 601 | |
| 602 | return data, nil |
| 603 | } |
| 604 | |
| 605 | func (p *Server) CompleteJob(ctx context.Context, in *proto.CompletedJob) error { |
| 606 | // If the moduleFiles exceed the max message size, we need to upload them separately. |
nothing calls this directly
no test coverage detected