Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ storage:
#

http:
- url: http://download.opensuse.org/repositories/myrepo1/openSUSE_Leap_42.3/
archs: [x86_64]
repositories:
- urls:
- http://download.opensuse.org/repositories/myrepo1/openSUSE_Leap_42.2/
- http://download.opensuse.org/repositories/myrepo1/openSUSE_Leap_42.3/
archs: [x86_64, aarch64]
- urls:
- http://download.opensuse.org/repositories/myrepo2/openSUSE_Leap_42.2/
- http://download.opensuse.org/repositories/myrepo2/openSUSE_Leap_42.3/
archs: [s390x, ppc64le]

# optional section to download repos from SCC
# scc:
Expand Down
50 changes: 27 additions & 23 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ var (
# bucket: minima-bucket-key

http:
- url: http://download.opensuse.org/repositories/myrepo1/openSUSE_Leap_42.3/
archs: [x86_64]
repositories:
- urls:
- http://download.opensuse.org/repositories/myrepo1/openSUSE_Leap_42.3/
archs: [x86_64]

# optional section to download repos from SCC
# scc:
Expand Down Expand Up @@ -85,7 +87,7 @@ type Config struct {
Storage get.StorageConfig
SCC get.SCC
OBS updates.OBS
HTTP []get.HTTPRepoConfig
HTTP get.HTTP
}

func syncersFromConfig(configString string) ([]*get.Syncer, error) {
Expand All @@ -109,36 +111,38 @@ func syncersFromConfig(configString string) ([]*get.Syncer, error) {
}
}

httpRepoConfigs, err := get.SCCToHTTPConfigs(sccUrl, config.SCC.Username, config.SCC.Password, config.SCC.Repositories)
httpReposConfigs, err := get.SCCToHTTPConfigs(sccUrl, config.SCC.Username, config.SCC.Password, config.SCC.Repositories)
if err != nil {
return nil, err
}
config.HTTP = append(config.HTTP, httpRepoConfigs...)
config.HTTP.Repositories = append(config.HTTP.Repositories, httpReposConfigs...)
}

syncers := []*get.Syncer{}
for _, httpRepo := range config.HTTP {
repoURL, err := url.Parse(httpRepo.URL)
if err != nil {
return nil, err
}

archs := map[string]bool{}
for _, archString := range httpRepo.Archs {
archs[archString] = true
}

var storage get.Storage
switch config.Storage.Type {
case "file":
storage = get.NewFileStorage(filepath.Join(config.Storage.Path, filepath.FromSlash(repoURL.Path)))
case "s3":
storage, err = get.NewS3Storage(config.Storage.AccessKeyID, config.Storage.AccessKeyID, config.Storage.Region, config.Storage.Bucket+repoURL.Path)
for _, reposConfig := range config.HTTP.Repositories {
for _, repoURL := range reposConfig.URLs {
parsedURL, err := url.Parse(repoURL)
if err != nil {
return nil, err
}

archs := map[string]bool{}
for _, archString := range reposConfig.Archs {
archs[archString] = true
}

var storage get.Storage
switch config.Storage.Type {
case "file":
storage = get.NewFileStorage(filepath.Join(config.Storage.Path, filepath.FromSlash(parsedURL.Path)))
case "s3":
storage, err = get.NewS3Storage(config.Storage.AccessKeyID, config.Storage.AccessKeyID, config.Storage.Region, config.Storage.Bucket+parsedURL.Path)
if err != nil {
return nil, err
}
}
syncers = append(syncers, get.NewSyncer(*parsedURL, archs, storage))
}
syncers = append(syncers, get.NewSyncer(*repoURL, archs, storage))
}

return syncers, nil
Expand Down
32 changes: 16 additions & 16 deletions cmd/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ func TestParseConfig(t *testing.T) {
Type: "file",
Path: "/srv/mirror",
},
HTTP: []get.HTTPRepoConfig{
{
URL: "http://test/SLE-Product-SLES15-SP5-Pool/",
Archs: []string{"x86_64", "aarch64", "s390x"},
},
{
URL: "http://test/SLE-Product-SLES15-SP5-Updates/",
Archs: []string{"x86_64", "aarch64"},
HTTP: get.HTTP{
Repositories: []get.HTTPReposConfig{
{
URLs: []string{"http://test/SLE-Product-SLES15-SP5-Pool/", "http://test/SLE-Product-SLES15-SP5-Updates/"},
Archs: []string{"x86_64", "aarch64", "s390x"},
},
{
URLs: []string{"http://test/SLE-Product-SLES15-SP6-Pool/", "http://test/SLE-Product-SLES15-SP6-Updates/"},
Archs: []string{"x86_64", "aarch64"},
},
},
},
},
Expand Down Expand Up @@ -74,14 +76,12 @@ func TestParseConfig(t *testing.T) {
Type: "memory",
Path: "/srv/mirror",
},
HTTP: []get.HTTPRepoConfig{
{
URL: "http://test/SLE-Product-SLES15-SP5-Pool/",
Archs: []string{"x86_64", "aarch64", "s390x"},
},
{
URL: "http://test/SLE-Product-SLES15-SP5-Updates/",
Archs: []string{"x86_64", "aarch64"},
HTTP: get.HTTP{
Repositories: []get.HTTPReposConfig{
{
URLs: []string{"http://test/SLE-Product-SLES15-SP5-Pool/", "http://test/SLE-Product-SLES15-SP5-Updates/"},
Archs: []string{"x86_64", "aarch64", "s390x"},
},
},
},
},
Expand Down
9 changes: 5 additions & 4 deletions cmd/testdata/invalid_storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ storage:
path: /srv/mirror

http:
- url: http://test/SLE-Product-SLES15-SP5-Pool/
archs: [x86_64, aarch64, s390x]
- url: http://test/SLE-Product-SLES15-SP5-Updates/
archs: [x86_64, aarch64]
repositories:
- urls:
- http://test/SLE-Product-SLES15-SP5-Pool/
- http://test/SLE-Product-SLES15-SP5-Updates/
archs: [x86_64, aarch64, s390x]
13 changes: 9 additions & 4 deletions cmd/testdata/valid_http_repos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ storage:
path: /srv/mirror

http:
- url: http://test/SLE-Product-SLES15-SP5-Pool/
archs: [x86_64, aarch64, s390x]
- url: http://test/SLE-Product-SLES15-SP5-Updates/
archs: [x86_64, aarch64]
repositories:
- urls:
- http://test/SLE-Product-SLES15-SP5-Pool/
- http://test/SLE-Product-SLES15-SP5-Updates/
archs: [x86_64, aarch64, s390x]
- urls:
- http://test/SLE-Product-SLES15-SP6-Pool/
- http://test/SLE-Product-SLES15-SP6-Updates/
archs: [x86_64, aarch64]
8 changes: 4 additions & 4 deletions cmd/testdata/valid_scc_repos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ scc:
password: pass
repositories:
- names:
- SLE-Manager-Tools15-Pool
- SLE-Manager-Tools15-Updates
- SLE-Manager-Tools15-Pool
- SLE-Manager-Tools15-Updates
archs: [x86_64, aarch64, s390x]
- names:
- SLE-Product-SLES15-SP5-Pool
- SLE-Product-SLES15-SP5-Updates
- SLE-Product-SLES15-SP5-Pool
- SLE-Product-SLES15-SP5-Updates
archs: [x86_64, s390x]
Loading