-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.go
123 lines (104 loc) · 3.38 KB
/
example.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
package main
import (
"context"
"fmt"
"github.com/content-services/tang/internal/config"
"github.com/content-services/tang/internal/zestwrapper"
"github.com/content-services/tang/pkg/tangy"
)
func main() {
// Pulp database configuration information
dbConfig := tangy.Database{
Name: "pulp",
Host: "localhost",
Port: 5434,
User: "pulp",
Password: "password",
CACertPath: "",
PoolLimit: 20,
}
// Create new Tangy instance using database config
t, err := tangy.New(dbConfig, tangy.Logger{Enabled: false})
if err != nil {
fmt.Println(err)
return
}
defer t.Close()
// Call helper function that creates and syncs a repository
versionHref, err := CreateRepositoryVersion()
if err != nil {
fmt.Println(err)
return
}
// Use Tangy to search for RPMs, by name, that are associated to a specific repository version, returning up to the first 100 results
rows, err := t.RpmRepositoryVersionPackageSearch(context.Background(), []string{versionHref}, "bear", 100)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("\nPackages\n==================\n")
for _, row := range rows {
fmt.Printf("\nName: %v \nSummary: %v", row.Name, row.Summary)
}
fmt.Printf("\n")
// Use Tangy to search for RPM package groups, by name, that are associated to a specific repository version, returning up to the first 100 results
var pkgGroups []tangy.RpmPackageGroupSearch
pkgGroups, err = t.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{versionHref}, "bir", 100)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("\nPackage Groups\n==================\n")
for _, row := range pkgGroups {
fmt.Printf("\nName: %v \nID: %v", row.Name, row.ID)
}
fmt.Printf("\n")
// Use Tangy to search for RPM environments, by name, that are associated to a specific repository version, returning up to the first 100 results
var pkgEnvs []tangy.RpmEnvironmentSearch
pkgEnvs, err = t.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{versionHref}, "avi", 100)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("\nEnvironments\n==================\n")
for _, row := range pkgEnvs {
fmt.Printf("\nName: %v \nID: %v", row.Name, row.ID)
}
fmt.Printf("\n")
}
func CreateRepositoryVersion() (versionHref string, err error) {
// Create new Pulp API wrapper instance, so we can use it for testing
rpmZest := zestwrapper.NewRpmZest(context.Background(), config.Server{
Url: "http://localhost:8087",
Username: "admin",
Password: "password",
StorageType: "local",
DownloadPolicy: "on_demand",
})
domainName := "example-domain-12231231"
// Create domain and repository, then sync repository, to create a new repository version with rpm packages
_, err = rpmZest.LookupOrCreateDomain(domainName)
if err != nil {
return "", err
}
repoHref, remoteHref, err := rpmZest.CreateRepository(domainName, "zoo", "https://rverdile.fedorapeople.org/dummy-repos/comps/repo2/")
if err != nil {
return "", err
}
syncTask, err := rpmZest.SyncRpmRepository(repoHref, remoteHref)
if err != nil {
return "", err
}
_, err = rpmZest.PollTask(syncTask)
if err != nil {
return "", err
}
resp, err := rpmZest.GetRpmRepositoryByName(domainName, "zoo")
if err != nil {
return "", err
}
if resp.LatestVersionHref == nil {
return "", fmt.Errorf("latest version href is nil")
}
return *resp.LatestVersionHref, nil
}