From d06a39bd511e2d7133dc559cde000b7f4209f8ab Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Sun, 17 Nov 2019 09:55:46 +0000 Subject: [PATCH] =?UTF-8?q?weldr:=20move=20RepoConfig=20=E2=86=92=20Source?= =?UTF-8?q?Config=20conversion=20to=20store?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This puts it aside the already existing SourceConfig → RepoConfig conversion and makes `sourceInfoHandler` a bit easier to parse. --- internal/store/store.go | 22 ++++++++++++++++++++++ internal/weldr/api.go | 19 +------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/internal/store/store.go b/internal/store/store.go index 4c8fdef8d..1b4c01c82 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -606,6 +606,28 @@ func (s *Store) GetAllSources() map[string]SourceConfig { return sources } +func NewSourceConfig(repo rpmmd.RepoConfig, system bool) SourceConfig { + sc := SourceConfig{ + Name: repo.Id, + CheckGPG: true, + CheckSSL: true, + System: system, + } + + if repo.BaseURL != "" { + sc.URL = repo.BaseURL + sc.Type = "yum-baseurl" + } else if repo.Metalink != "" { + sc.URL = repo.Metalink + sc.Type = "yum-metalink" + } else if repo.MirrorList != "" { + sc.URL = repo.MirrorList + sc.Type = "yum-mirrorlist" + } + + return sc +} + func (s *SourceConfig) RepoConfig() rpmmd.RepoConfig { var repo rpmmd.RepoConfig diff --git a/internal/weldr/api.go b/internal/weldr/api.go index 12d78eebe..f56a308d4 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -210,24 +210,7 @@ func (api *API) sourceInfoHandler(writer http.ResponseWriter, request *http.Requ } // check if the source is in the base repo if name == api.repo.Id || name == "*" { - cfg := store.SourceConfig{ - Name: api.repo.Id, - CheckGPG: true, - CheckSSL: true, - System: true, - } - - if api.repo.BaseURL != "" { - cfg.URL = api.repo.BaseURL - cfg.Type = "yum-baseurl" - } else if api.repo.Metalink != "" { - cfg.URL = api.repo.Metalink - cfg.Type = "yum-metalink" - } else if api.repo.MirrorList != "" { - cfg.URL = api.repo.MirrorList - cfg.Type = "yum-mirrorlist" - } - sources[cfg.Name] = cfg + sources[api.repo.Id] = store.NewSourceConfig(api.repo, true) // check if the source is in the store } else if source := api.store.GetSource(name); source != nil { sources[source.Name] = *source