-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathrpm_distributions.go
86 lines (73 loc) · 2.82 KB
/
rpm_distributions.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package pulp_client
import (
"context"
zest "github.com/content-services/zest/release/v2024"
)
// CreateRpmDistribution Creates a Distribution
func (r *pulpDaoImpl) CreateRpmDistribution(ctx context.Context, publicationHref string, name string, basePath string, contentGuardHref *string) (*string, error) {
ctx, client := getZestClient(ctx)
dist := *zest.NewRpmRpmDistribution(basePath, name)
if contentGuardHref != nil {
dist.SetContentGuard(*contentGuardHref)
}
dist.SetPublication(publicationHref)
resp, httpResp, err := client.DistributionsRpmAPI.DistributionsRpmRpmCreate(ctx, r.domainName).RpmRpmDistribution(dist).Execute()
if httpResp != nil {
defer httpResp.Body.Close()
}
if err != nil {
return nil, errorWithResponseBody("error creating rpm distributions", httpResp, err)
}
taskHref := resp.GetTask()
return &taskHref, nil
}
func (r *pulpDaoImpl) FindDistributionByPath(ctx context.Context, path string) (*zest.RpmRpmDistributionResponse, error) {
ctx, client := getZestClient(ctx)
resp, httpResp, err := client.DistributionsRpmAPI.DistributionsRpmRpmList(ctx, r.domainName).BasePath(path).Execute()
if httpResp != nil {
defer httpResp.Body.Close()
}
if err != nil {
return nil, errorWithResponseBody("error listing rpm distributions", httpResp, err)
}
res := resp.GetResults()
if len(res) > 0 {
return &res[0], nil
} else {
return nil, nil
}
}
func (r *pulpDaoImpl) DeleteRpmDistribution(ctx context.Context, rpmDistributionHref string) (string, error) {
ctx, client := getZestClient(ctx)
resp, httpResp, err := client.DistributionsRpmAPI.DistributionsRpmRpmDelete(ctx, rpmDistributionHref).Execute()
if httpResp != nil {
defer httpResp.Body.Close()
}
if err != nil {
if err.Error() == "404 Not Found" {
return "", nil
}
return "", errorWithResponseBody("error deleting rpm distribution", httpResp, err)
}
return resp.Task, nil
}
func (r *pulpDaoImpl) UpdateRpmDistribution(ctx context.Context, rpmDistributionHref string, rpmPublicationHref string, distributionName string, basePath string, contentGuardHref *string) (string, error) {
ctx, client := getZestClient(ctx)
patchedRpmDistribution := zest.PatchedrpmRpmDistribution{}
patchedRpmDistribution.Name = &distributionName
patchedRpmDistribution.BasePath = &basePath
var pub zest.NullableString
pub.Set(&rpmPublicationHref)
patchedRpmDistribution.SetPublication(rpmPublicationHref)
var cGuard zest.NullableString
cGuard.Set(contentGuardHref)
patchedRpmDistribution.ContentGuard = cGuard
resp, httpResp, err := client.DistributionsRpmAPI.DistributionsRpmRpmPartialUpdate(ctx, rpmDistributionHref).PatchedrpmRpmDistribution(patchedRpmDistribution).Execute()
if httpResp != nil {
defer httpResp.Body.Close()
}
if err != nil {
return "", errorWithResponseBody("error listing rpm distributions", httpResp, err)
}
return resp.Task, nil
}