weldr: Update projects/source/info to support API v1

This commit changes the store.GetAllSources to distinguish between
getting the source by the Name field, or by the ID (the key to the map)
using GetAllSourcesByName and ...ByID.

SourceConfig.RepoConfig() now takes an id parameter because SourceConfig
only stores the Name, not the ID.

In weldr I split the sourceInfoHandler into 2 separate functions for v0
and v1 behavior, with the core of the old function refactored as
getSourceConfigs and used by both of them.

This also adds new structs for the SourceResponseV0 and SourceResponseV1
as well as helper functions for converting to/from store.SourceConfig
This commit is contained in:
Brian C. Lane 2020-04-30 13:58:51 -07:00 committed by Tom Gundersen
parent ddd2010815
commit 982d292a96
5 changed files with 193 additions and 27 deletions

View file

@ -464,7 +464,22 @@ func (s *Store) GetSource(name string) *SourceConfig {
return &source
}
func (s *Store) GetAllSources() map[string]SourceConfig {
// GetAllSourcesByName returns the sources using the repo name as the key
func (s *Store) GetAllSourcesByName() map[string]SourceConfig {
s.mu.RLock()
defer s.mu.RUnlock()
sources := make(map[string]SourceConfig)
for _, v := range s.sources {
sources[v.Name] = v
}
return sources
}
// GetAllSourcesByID returns the sources using the repo id as the key
func (s *Store) GetAllSourcesByID() map[string]SourceConfig {
s.mu.RLock()
defer s.mu.RUnlock()
@ -499,10 +514,10 @@ func NewSourceConfig(repo rpmmd.RepoConfig, system bool) SourceConfig {
return sc
}
func (s *SourceConfig) RepoConfig() rpmmd.RepoConfig {
func (s *SourceConfig) RepoConfig(name string) rpmmd.RepoConfig {
var repo rpmmd.RepoConfig
repo.Name = s.Name
repo.Name = name
repo.IgnoreSSL = !s.CheckSSL
if s.Type == "yum-baseurl" {