From fe65a0b9eb213bbc8d51dbac3091cb6cf6453101 Mon Sep 17 00:00:00 2001 From: ferreo Date: Wed, 31 Jul 2024 20:54:51 +0100 Subject: [PATCH] Dynamic whitelist for experimental repo --- config/config.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/config/config.go b/config/config.go index bc8b595..6c64c51 100644 --- a/config/config.go +++ b/config/config.go @@ -4,6 +4,7 @@ import ( "brunel/domain" "fmt" "io" + "net/http" "os" "github.com/goccy/go-json" @@ -43,6 +44,10 @@ type Config struct { ActionsUrl string `json:"actionsUrl"` } +type expPkgNames struct { + PackageNames []string `json:"package_names"` +} + func Init() error { err := loadUsers() if err != nil { @@ -103,5 +108,38 @@ func loadConfig() error { Configs = config + xpPkgNames, err := LoadExperimentalPackageNames() + if err != nil { + return err + } + + for i, pkg := range Configs.ExternalPackageFiles { + if pkg.Name == "Debian experimental" { + pkg.Whitelist = xpPkgNames + pkg.UseWhitelist = true + Configs.ExternalPackageFiles[i] = pkg + break + } + } + return nil } + +func LoadExperimentalPackageNames() ([]string, error) { + var epPkgNames expPkgNames + response, err := http.Get("https://raw.githubusercontent.com/PikaOS-Linux/pika-base-debian-container/main/exp_pkg_names.json") + if err != nil { + return nil, err + } + defer response.Body.Close() + + byteValue, _ := io.ReadAll(response.Body) + + err = json.Unmarshal(byteValue, &epPkgNames) + if err != nil { + fmt.Println(err) + return nil, err + } + + return epPkgNames.PackageNames, nil +}