Skip to content

Commit 1e141ac

Browse files
committed
Implement HO golang client API ExtractArtifact(filename string)
1 parent 7c37f2c commit 1e141ac

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

frontend/src/libhoclient/host_orchestrator_client.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ type UserArtifactsClient interface {
108108
// Upload artifact into the artifacts repository.
109109
// Artifacts are identified by their SHA256 checksum in the artifacts repository
110110
UploadArtifact(filename string) error
111+
// Extract artifact into the artifacts repository.
112+
// Artifacts are identified by their SHA256 checksum in the artifacts repository
113+
ExtractArtifact(filename string) error
111114
// Creates a directory in the host where user artifacts can be uploaded to.
112115
CreateUploadDir() (string, error)
113116
// Uploads file into the given directory.
@@ -590,6 +593,24 @@ func (c *HostOrchestratorClientImpl) ExtractFile(uploadDir string, filename stri
590593
return result, nil
591594
}
592595

596+
func (c *HostOrchestratorClientImpl) ExtractArtifact(filename string) (*hoapi.Operation, error) {
597+
checksum, err := sha256Checksum(filename)
598+
if err != nil {
599+
return err
600+
}
601+
path := "/v1/userartifacts/" + checksum + "_extracted"
602+
res := &hoapi.StatArtifactResponse{}
603+
// Early return if the artifact already exist.
604+
if err := c.HTTPHelper.NewGetRequest(path).JSONResDo(res); err == nil {
605+
return nil
606+
}
607+
rb := c.HTTPHelper.NewPostRequest("/v1/userartifacts/"+checksum+"/:extract", nil)
608+
if err := rb.JSONResDo(result); err != nil {
609+
return nil, err
610+
}
611+
return result, nil
612+
}
613+
593614
func (c *HostOrchestratorClientImpl) CreateBugReport(group string, opts CreateBugReportOpts, dst io.Writer) error {
594615
op := &hoapi.Operation{}
595616
path := "/cvds/" + group + "/:bugreport"

0 commit comments

Comments
 (0)