Dynamic whitelist for experimental repo

This commit is contained in:
ferreo 2024-07-31 20:54:51 +01:00
parent ccad5f6a3a
commit fe65a0b9eb

View File

@ -4,6 +4,7 @@ import (
"brunel/domain" "brunel/domain"
"fmt" "fmt"
"io" "io"
"net/http"
"os" "os"
"github.com/goccy/go-json" "github.com/goccy/go-json"
@ -43,6 +44,10 @@ type Config struct {
ActionsUrl string `json:"actionsUrl"` ActionsUrl string `json:"actionsUrl"`
} }
type expPkgNames struct {
PackageNames []string `json:"package_names"`
}
func Init() error { func Init() error {
err := loadUsers() err := loadUsers()
if err != nil { if err != nil {
@ -103,5 +108,38 @@ func loadConfig() error {
Configs = config 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 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
}