-
Notifications
You must be signed in to change notification settings - Fork 49
/
rpmrepo.go
62 lines (53 loc) · 1.35 KB
/
rpmrepo.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
package rpmrepo
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/rpmmd"
)
type testRepoServer struct {
Server *httptest.Server
RepoConfig rpmmd.RepoConfig
}
func NewTestServer() *testRepoServer {
server := httptest.NewServer(http.FileServer(http.Dir("../../test/data/testrepo/")))
testrepo := rpmmd.RepoConfig{
Name: "cs9-baseos",
BaseURLs: []string{server.URL},
CheckGPG: common.ToPtr(false),
IgnoreSSL: common.ToPtr(true),
RHSM: false,
}
return &testRepoServer{Server: server, RepoConfig: testrepo}
}
func (trs *testRepoServer) Close() {
trs.Server.Close()
}
// WriteConfig writes the repository config to the specified path in .repo
// format. Assumes the location already exists.
func (trs *testRepoServer) WriteConfig(path string) {
cfgtmpl := `[%[1]s]
name=%[1]s
baseurl=%[2]s
gpgcheck=%[3]s
sslverify=%[4]s
`
checkGPG := "0"
if trs.RepoConfig.CheckGPG != nil && *trs.RepoConfig.CheckGPG {
checkGPG = "1"
}
sslverify := "1"
if trs.RepoConfig.IgnoreSSL != nil && *trs.RepoConfig.IgnoreSSL {
sslverify = "0"
}
config := fmt.Sprintf(cfgtmpl, trs.RepoConfig.Name, trs.RepoConfig.BaseURLs[0], checkGPG, sslverify)
fp, err := os.Create(path)
if err != nil {
panic(err)
}
if _, err := fp.Write([]byte(config)); err != nil {
panic(err)
}
}