-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmanifest.go
54 lines (46 loc) · 1.28 KB
/
manifest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package candlepin_client
import (
"context"
"fmt"
"os"
caliri "github.com/content-services/caliri/release/v4"
)
func (c *cpClientImpl) ImportManifest(ctx context.Context, filename string) error {
ctx, client, err := getCandlepinClient(ctx)
if err != nil {
return err
}
file, err := os.Open(filename)
if err != nil {
return fmt.Errorf("Could not open manifest %w", err)
}
defer file.Close()
asyncTask, httpResp, err := client.OwnerAPI.ImportManifestAsync(ctx, DevelOrgKey).Force([]string{"SIGNATURE_CONFLICT"}).Input(file).Execute()
if httpResp != nil {
defer httpResp.Body.Close()
}
if err != nil {
return errorWithResponseBody("couldn't import manifest", httpResp, err)
}
for asyncTask.EndTime == nil {
asyncTask, err = c.pollTask(ctx, *asyncTask)
if err != nil {
return err
}
}
return nil
}
func (c *cpClientImpl) pollTask(ctx context.Context, asyncTask caliri.AsyncJobStatusDTO) (*caliri.AsyncJobStatusDTO, error) {
ctx, client, err := getCandlepinClient(ctx)
if err != nil {
return nil, err
}
async, httpResp, err := client.JobsAPI.GetJobStatus(ctx, *asyncTask.Id).Execute()
if httpResp != nil {
defer httpResp.Body.Close()
}
if err != nil {
return async, errorWithResponseBody("couldn't fetch async job", httpResp, err)
}
return async, nil
}