@@ -83,12 +83,14 @@ func ParseCatalogYaml(raw string, isDefault bool) ([]models.CatalogSourceConfig,
8383 // Internal struct to match YAML structure
8484 var parsed struct {
8585 Catalogs []struct {
86- Name string `yaml:"name"`
87- Id string `yaml:"id"`
88- Type string `yaml:"type"`
89- Enabled * bool `yaml:"enabled"`
90- Properties map [string ]interface {} `yaml:"properties"`
91- Labels []string `yaml:"labels"`
86+ Name string `yaml:"name"`
87+ Id string `yaml:"id"`
88+ Type string `yaml:"type"`
89+ Enabled * bool `yaml:"enabled"`
90+ Properties map [string ]interface {} `yaml:"properties"`
91+ Labels []string `yaml:"labels"`
92+ IncludedModels []string `yaml:"includedModels"`
93+ ExcludedModels []string `yaml:"excludedModels"`
9294 } `yaml:"catalogs"`
9395 }
9496
@@ -99,23 +101,17 @@ func ParseCatalogYaml(raw string, isDefault bool) ([]models.CatalogSourceConfig,
99101 catalogs := make ([]models.CatalogSourceConfig , 0 , len (parsed .Catalogs ))
100102 for _ , c := range parsed .Catalogs {
101103 entry := models.CatalogSourceConfig {
102- Id : c .Id ,
103- Name : c .Name ,
104- Type : c .Type ,
105- Enabled : c .Enabled ,
106- Labels : c .Labels ,
107- IsDefault : & isDefault ,
104+ Id : c .Id ,
105+ Name : c .Name ,
106+ Type : c .Type ,
107+ Enabled : c .Enabled ,
108+ Labels : c .Labels ,
109+ IsDefault : & isDefault ,
110+ IncludedModels : c .IncludedModels ,
111+ ExcludedModels : c .ExcludedModels ,
108112 }
109113
110114 if c .Properties != nil {
111- if includedModels , ok := c .Properties ["includedModels" ]; ok {
112- entry .IncludedModels = ExtractStringSlice (includedModels )
113- }
114-
115- if excludedModels , ok := c .Properties ["excludedModels" ]; ok {
116- entry .ExcludedModels = ExtractStringSlice (excludedModels )
117- }
118-
119115 if apiKey , ok := c .Properties [ApiKey ].(string ); ok {
120116 entry .ApiKey = & apiKey
121117 }
@@ -154,12 +150,14 @@ func FindCatalogSourceById(sourceYAML string, catalogId string, isDefault bool)
154150
155151 var parsed struct {
156152 Catalogs []struct {
157- Id string `yaml:"id"`
158- Name string `yaml:"name"`
159- Type string `yaml:"type"`
160- Enabled * bool `yaml:"enabled"`
161- Labels []string `yaml:"labels"`
162- Properties map [string ]interface {} `yaml:"properties"`
153+ Id string `yaml:"id"`
154+ Name string `yaml:"name"`
155+ Type string `yaml:"type"`
156+ Enabled * bool `yaml:"enabled"`
157+ Labels []string `yaml:"labels"`
158+ Properties map [string ]interface {} `yaml:"properties"`
159+ IncludedModels []string `yaml:"includedModels"`
160+ ExcludedModels []string `yaml:"excludedModels"`
163161 } `yaml:"catalogs"`
164162 }
165163
@@ -171,21 +169,17 @@ func FindCatalogSourceById(sourceYAML string, catalogId string, isDefault bool)
171169 if catalog .Id == catalogId {
172170 isDefaultVal := isDefault
173171 result := & models.CatalogSourceConfig {
174- Id : catalog .Id ,
175- Name : catalog .Name ,
176- Type : catalog .Type ,
177- Enabled : catalog .Enabled ,
178- Labels : catalog .Labels ,
179- IsDefault : & isDefaultVal ,
172+ Id : catalog .Id ,
173+ Name : catalog .Name ,
174+ Type : catalog .Type ,
175+ Enabled : catalog .Enabled ,
176+ Labels : catalog .Labels ,
177+ IsDefault : & isDefaultVal ,
178+ IncludedModels : catalog .IncludedModels ,
179+ ExcludedModels : catalog .ExcludedModels ,
180180 }
181181
182182 if catalog .Properties != nil {
183- if included , ok := catalog .Properties ["includedModels" ]; ok {
184- result .IncludedModels = ExtractStringSlice (included )
185- }
186- if excluded , ok := catalog .Properties ["excludedModels" ]; ok {
187- result .ExcludedModels = ExtractStringSlice (excluded )
188- }
189183 if org , ok := catalog .Properties ["allowedOrganization" ].(string ); ok {
190184 result .AllowedOrganization = & org
191185 }
@@ -225,16 +219,17 @@ func ConvertSourceConfigToYamlEntry(payload models.CatalogSourceConfigPayload,
225219
226220 }
227221
222+ if len (properties ) > 0 {
223+ entry ["properties" ] = properties
224+ }
225+
228226 if len (payload .IncludedModels ) > 0 {
229- properties ["includedModels" ] = payload .IncludedModels
227+ entry ["includedModels" ] = payload .IncludedModels
230228 }
231229 if len (payload .ExcludedModels ) > 0 {
232- properties ["excludedModels" ] = payload .ExcludedModels
230+ entry ["excludedModels" ] = payload .ExcludedModels
233231 }
234232
235- if len (properties ) > 0 {
236- entry ["properties" ] = properties
237- }
238233 return entry
239234}
240235
@@ -348,16 +343,16 @@ func UpdateCatalogSourceInYAML(
348343
349344 if payload .IncludedModels != nil {
350345 if len (payload .IncludedModels ) > 0 {
351- properties ["includedModels" ] = payload .IncludedModels
346+ catalogSource ["includedModels" ] = payload .IncludedModels
352347 } else {
353- delete (properties , "includedModels" )
348+ delete (catalogSource , "includedModels" )
354349 }
355350 }
356351 if payload .ExcludedModels != nil {
357352 if len (payload .ExcludedModels ) > 0 {
358- properties ["excludedModels" ] = payload .ExcludedModels
353+ catalogSource ["excludedModels" ] = payload .ExcludedModels
359354 } else {
360- delete (properties , "excludedModels" )
355+ delete (catalogSource , "excludedModels" )
361356 }
362357 }
363358 if payload .AllowedOrganization != nil {
@@ -400,17 +395,11 @@ func BuildOverrideEntryForDefaultSource(catalogId string, payload models.Catalog
400395 entry ["enabled" ] = * payload .Enabled
401396 }
402397
403- properties := make (map [string ]interface {})
404-
405398 if len (payload .IncludedModels ) > 0 {
406- properties ["includedModels" ] = payload .IncludedModels
399+ entry ["includedModels" ] = payload .IncludedModels
407400 }
408401 if len (payload .ExcludedModels ) > 0 {
409- properties ["excludedModels" ] = payload .ExcludedModels
410- }
411-
412- if len (properties ) > 0 {
413- entry ["properties" ] = properties
402+ entry ["excludedModels" ] = payload .ExcludedModels
414403 }
415404
416405 return entry
0 commit comments