Skip to content
Draft
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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ http:
# - SLES12-SP2-LTSS-Updates
# archs: [x86_64]

# OBS credentials:
# obs:
# username: ""
# password: ""
# Build Service credentials:
# build_service:
# api: obs
# username: "user"
# password: "passwd"
```


Expand Down
71 changes: 20 additions & 51 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package cmd
import (
"fmt"
"log"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
"github.com/uyuni-project/minima/get"
"github.com/uyuni-project/minima/updates"
"github.com/uyuni-project/minima/maint"
"github.com/uyuni-project/minima/scc"
"github.com/uyuni-project/minima/storage"
yaml "gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -54,24 +53,23 @@ var (
Run: func(cmd *cobra.Command, args []string) {
initConfig()

var errorflag bool = false
syncers, err := syncersFromConfig(cfgString)
config, err := parseConfig(cfgString)
if err != nil {
log.Fatal(err)
errorflag = true
}

syncers, err := syncersFromConfig(config)
if err != nil {
log.Fatal(err)
}

for _, syncer := range syncers {
log.Printf("Processing repo: %s", syncer.URL.String())
err := syncer.StoreRepo()
if err != nil {
log.Println(err)
errorflag = true
} else {
log.Println("...done.")
log.Fatal(err)
}
}
if errorflag {
os.Exit(1)
log.Println("...done.")
}
},
}
Expand All @@ -82,17 +80,13 @@ var (

// Config maps the configuration in minima.yaml
type Config struct {
Storage get.StorageConfig
SCC get.SCC
OBS updates.OBS
HTTP []get.HTTPRepoConfig
Storage storage.StorageConfig
SCC scc.SCC
BuildService maint.BuildServiceCredentials `yaml:"build_service"`
HTTP []get.HTTPRepo
}

func syncersFromConfig(configString string) ([]*get.Syncer, error) {
config, err := parseConfig(configString)
if err != nil {
return nil, err
}
func syncersFromConfig(config Config) ([]*get.Syncer, error) {
//---passing the flag value to a global variable in get package, to disables syncing of i586 and i686 rpms (usually inside x86_64)
get.SkipLegacy = skipLegacyPackages

Expand All @@ -101,47 +95,22 @@ func syncersFromConfig(configString string) ([]*get.Syncer, error) {
if archs == "" {
archs = "x86_64"
}
config.SCC.Repositories = []get.SCCReposConfig{
config.SCC.Repositories = []scc.SCCRepos{
{
Names: []string{thisRepo},
Archs: strings.Split(archs, ","),
},
}
}

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

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)
if err != nil {
return nil, err
}
}
syncers = append(syncers, get.NewSyncer(*repoURL, archs, storage))
}

return syncers, nil
return get.SyncersFromHTTPRepos(config.HTTP, config.Storage)
}

func parseConfig(configString string) (Config, error) {
Expand Down
16 changes: 9 additions & 7 deletions cmd/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/stretchr/testify/assert"
"github.com/uyuni-project/minima/get"
"github.com/uyuni-project/minima/scc"
"github.com/uyuni-project/minima/storage"
)

const (
Expand All @@ -26,11 +28,11 @@ func TestParseConfig(t *testing.T) {
{
"Valid HTTP repos", validHTTPReposFile,
Config{
Storage: get.StorageConfig{
Storage: storage.StorageConfig{
Type: "file",
Path: "/srv/mirror",
},
HTTP: []get.HTTPRepoConfig{
HTTP: []get.HTTPRepo{
{
URL: "http://test/SLE-Product-SLES15-SP5-Pool/",
Archs: []string{"x86_64", "aarch64", "s390x"},
Expand All @@ -46,14 +48,14 @@ func TestParseConfig(t *testing.T) {
{
"Valid SCC repos", validSCCReposFile,
Config{
Storage: get.StorageConfig{
Storage: storage.StorageConfig{
Type: "file",
Path: "/srv/mirror",
},
SCC: get.SCC{
SCC: scc.SCC{
Username: "user",
Password: "pass",
Repositories: []get.SCCReposConfig{
Repositories: []scc.SCCRepos{
{
Names: []string{"SLE-Manager-Tools15-Pool", "SLE-Manager-Tools15-Updates"},
Archs: []string{"x86_64", "aarch64", "s390x"},
Expand All @@ -70,11 +72,11 @@ func TestParseConfig(t *testing.T) {
{
"Invalid storage", invalidStoragefile,
Config{
Storage: get.StorageConfig{
Storage: storage.StorageConfig{
Type: "memory",
Path: "/srv/mirror",
},
HTTP: []get.HTTPRepoConfig{
HTTP: []get.HTTPRepo{
{
URL: "http://test/SLE-Product-SLES15-SP5-Pool/",
Archs: []string{"x86_64", "aarch64", "s390x"},
Expand Down
Loading