2024-07-28 20:59:50 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"brunel/domain"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2024-07-31 21:54:51 +02:00
|
|
|
"net/http"
|
2024-07-28 20:59:50 +02:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/goccy/go-json"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Users map[string]domain.User
|
|
|
|
var Configs Config
|
|
|
|
|
|
|
|
// Struct representing an individual package file entries
|
|
|
|
type PackageFile struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Subrepos []string `json:"subrepos"`
|
|
|
|
Priority int `json:"priority"`
|
|
|
|
UseWhitelist bool `json:"usewhitelist"`
|
|
|
|
Whitelist []string `json:"whitelist"`
|
|
|
|
Blacklist []string `json:"blacklist"`
|
|
|
|
Packagepath string `json:"packagepath"`
|
|
|
|
Compression string `json:"compression"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Struct for the overall configuration
|
|
|
|
type Config struct {
|
|
|
|
Hostname string `json:"hostname"`
|
|
|
|
Port int `json:"port"`
|
|
|
|
UpstreamFallback bool `json:"upstreamFallback"`
|
|
|
|
LocalPackageFiles []PackageFile `json:"localPackageFiles"`
|
|
|
|
ExternalPackageFiles []PackageFile `json:"externalPackageFiles"`
|
|
|
|
LTOBlocklist []string `json:"ltoBlocklist"`
|
2024-08-02 22:07:39 +02:00
|
|
|
I386List []string `json:"i386List"`
|
2024-07-28 20:59:50 +02:00
|
|
|
DeboutputDir string `json:"deboutputDir"`
|
|
|
|
Salt string `json:"salt"`
|
2024-07-29 23:40:26 +02:00
|
|
|
Buildrepo string `json:"buildRepo"`
|
|
|
|
Buildbranch string `json:"buildBranch"`
|
|
|
|
GitCache string `json:"gitCache"`
|
|
|
|
GitToken string `json:"gitToken"`
|
|
|
|
GitUser string `json:"gitUser"`
|
|
|
|
ActionsUrl string `json:"actionsUrl"`
|
2024-07-28 20:59:50 +02:00
|
|
|
}
|
|
|
|
|
2024-07-31 21:54:51 +02:00
|
|
|
type expPkgNames struct {
|
|
|
|
PackageNames []string `json:"package_names"`
|
|
|
|
}
|
|
|
|
|
2024-08-02 22:07:39 +02:00
|
|
|
type i386List struct {
|
|
|
|
PackageNames []string `json:"i386_whitelist"`
|
|
|
|
}
|
|
|
|
|
2024-07-28 20:59:50 +02:00
|
|
|
func Init() error {
|
|
|
|
err := loadUsers()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = loadConfig()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadUsers() error {
|
|
|
|
jsonFile, err := os.Open("users.json")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer jsonFile.Close()
|
|
|
|
|
|
|
|
byteValue, _ := io.ReadAll(jsonFile)
|
|
|
|
|
|
|
|
var users []domain.User
|
|
|
|
err = json.Unmarshal(byteValue, &users)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var usersMap = make(map[string]domain.User, len(users))
|
|
|
|
for _, user := range users {
|
|
|
|
usersMap[user.Username] = user
|
|
|
|
}
|
|
|
|
|
|
|
|
Users = usersMap
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadConfig() error {
|
|
|
|
jsonFile, err := os.Open("config.json")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer jsonFile.Close()
|
|
|
|
|
|
|
|
byteValue, _ := io.ReadAll(jsonFile)
|
|
|
|
|
|
|
|
var config Config
|
|
|
|
err = json.Unmarshal(byteValue, &config)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-08-02 22:35:32 +02:00
|
|
|
config.I386List, err = loadI386List()
|
2024-08-02 22:07:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-07-28 20:59:50 +02:00
|
|
|
Configs = config
|
|
|
|
|
2024-08-02 22:07:39 +02:00
|
|
|
xpPkgNames, err := loadExperimentalPackageNames()
|
2024-07-31 21:54:51 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-28 20:59:50 +02:00
|
|
|
return nil
|
|
|
|
}
|
2024-07-31 21:54:51 +02:00
|
|
|
|
2024-08-02 22:07:39 +02:00
|
|
|
func loadI386List() ([]string, error) {
|
|
|
|
var i386List i386List
|
2024-10-19 12:36:12 +02:00
|
|
|
response, err := http.Get("https://git.pika-os.com/repo-tools/pin-generation/raw/branch/main/generated-output/i386/i386_src_whitelist.json")
|
2024-08-02 22:07:39 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer response.Body.Close()
|
|
|
|
|
|
|
|
byteValue, _ := io.ReadAll(response.Body)
|
|
|
|
|
|
|
|
err = json.Unmarshal(byteValue, &i386List)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return i386List.PackageNames, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadExperimentalPackageNames() ([]string, error) {
|
2024-07-31 21:54:51 +02:00
|
|
|
var epPkgNames expPkgNames
|
2024-10-19 12:36:12 +02:00
|
|
|
response, err := http.Get("https://git.pika-os.com/repo-tools/pin-generation/raw/branch/main/generated-output/exp_pkg_names.json")
|
2024-07-31 21:54:51 +02:00
|
|
|
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
|
|
|
|
}
|