/
rpm_remote.go
129 lines (110 loc) · 3.9 KB
/
rpm_remote.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package pulp_client
import (
"context"
"github.com/content-services/content-sources-backend/pkg/config"
zest "github.com/content-services/zest/release/v2024"
"github.com/rs/zerolog/log"
)
const DownloadPolicyOnDemand = "on_demand"
const DownloadPolicyImmediate = "immediate"
// Creates a remote
func (r *pulpDaoImpl) CreateRpmRemote(ctx context.Context, name string, url string, clientCert *string, clientKey *string, caCert *string) (*zest.RpmRpmRemoteResponse, error) {
ctx, client := getZestClient(ctx)
rpmRpmRemote := *zest.NewRpmRpmRemote(name, url)
if clientCert != nil {
rpmRpmRemote.SetClientCert(*clientCert)
}
if clientKey != nil {
rpmRpmRemote.SetClientKey(*clientKey)
}
if caCert != nil {
rpmRpmRemote.SetCaCert(*caCert)
}
policy := config.Get().Clients.Pulp.DownloadPolicy
if policy == DownloadPolicyOnDemand {
rpmRpmRemote.SetPolicy(zest.POLICY762ENUM_ON_DEMAND)
} else if policy == DownloadPolicyImmediate {
rpmRpmRemote.SetPolicy(zest.POLICY762ENUM_IMMEDIATE)
} else {
log.Logger.Error().Msgf("Unknown download policy %v, defaulting to Immediate", policy)
rpmRpmRemote.SetPolicy(zest.POLICY762ENUM_IMMEDIATE)
}
remoteResp, httpResp, err := client.RemotesRpmAPI.RemotesRpmRpmCreate(ctx, r.domainName).
RpmRpmRemote(rpmRpmRemote).Execute()
if httpResp != nil {
defer httpResp.Body.Close()
}
if err != nil {
return nil, errorWithResponseBody("error creating rpm remote", httpResp, err)
}
return remoteResp, nil
}
// Starts an update task on an existing remote
func (r *pulpDaoImpl) UpdateRpmRemote(ctx context.Context, pulpHref string, url string, clientCert *string, clientKey *string, caCert *string) (string, error) {
ctx, client := getZestClient(ctx)
patchRpmRemote := zest.PatchedrpmRpmRemote{}
if clientCert != nil {
patchRpmRemote.SetClientCert(*clientCert)
}
if clientKey != nil {
patchRpmRemote.SetClientKey(*clientKey)
}
if caCert != nil {
patchRpmRemote.SetCaCert(*caCert)
}
patchRpmRemote.SetUrl(url)
updateResp, httpResp, err := client.RemotesRpmAPI.RemotesRpmRpmPartialUpdate(ctx, pulpHref).
PatchedrpmRpmRemote(patchRpmRemote).Execute()
if httpResp != nil {
defer httpResp.Body.Close()
}
if err != nil {
return "", errorWithResponseBody("error in rpm remote partial update", httpResp, err)
}
defer httpResp.Body.Close()
return updateResp.Task, nil
}
// Finds a remote by name, returning the associated RpmRpmRemoteResponse (containing the PulpHref)
func (r *pulpDaoImpl) GetRpmRemoteByName(ctx context.Context, name string) (*zest.RpmRpmRemoteResponse, error) {
ctx, client := getZestClient(ctx)
readResp, httpResp, err := client.RemotesRpmAPI.RemotesRpmRpmList(ctx, r.domainName).Name(name).Execute()
if httpResp != nil {
httpResp.Body.Close()
}
if err != nil {
return nil, errorWithResponseBody("error listing rpm remotes", httpResp, err)
}
defer httpResp.Body.Close()
results := readResp.GetResults()
if len(results) > 0 {
return &results[0], nil
} else {
return nil, nil
}
}
// Returns a list of RpmRpmRemotes
func (r *pulpDaoImpl) GetRpmRemoteList(ctx context.Context) ([]zest.RpmRpmRemoteResponse, error) {
ctx, client := getZestClient(ctx)
readResp, httpResp, err := client.RemotesRpmAPI.RemotesRpmRpmList(ctx, r.domainName).Execute()
if httpResp != nil {
defer httpResp.Body.Close()
}
if err != nil {
return []zest.RpmRpmRemoteResponse{}, errorWithResponseBody("listing rpm remotes", httpResp, err)
}
results := readResp.GetResults()
return results, nil
}
// Starts a Delete task on an existing remote
func (r *pulpDaoImpl) DeleteRpmRemote(ctx context.Context, pulpHref string) (string, error) {
ctx, client := getZestClient(ctx)
deleteResp, httpResp, err := client.RemotesRpmAPI.RemotesRpmRpmDelete(ctx, pulpHref).Execute()
if httpResp != nil {
defer httpResp.Body.Close()
}
if err != nil {
return "", errorWithResponseBody("error deleting rpm remote", httpResp, err)
}
defer httpResp.Body.Close()
return deleteResp.Task, nil
}