From 1a180113cbd6c73ab5da4c829eade34f28b78bb1 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Wed, 29 Jun 2022 12:13:32 +0200 Subject: [PATCH] Try 06 --- .../{repositories/apk.go => repo-apk.go} | 4 ++-- .../{repositories/deb.go => repo-deb.go} | 2 +- .../{repositories/helm.go => repo-helm.go} | 0 .../{repositories/main.go => repo.go} | 0 pkg/templater/services.go | 21 +++++++++++++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) rename pkg/templater/{repositories/apk.go => repo-apk.go} (95%) rename pkg/templater/{repositories/deb.go => repo-deb.go} (90%) rename pkg/templater/{repositories/helm.go => repo-helm.go} (100%) rename pkg/templater/{repositories/main.go => repo.go} (100%) diff --git a/pkg/templater/repositories/apk.go b/pkg/templater/repo-apk.go similarity index 95% rename from pkg/templater/repositories/apk.go rename to pkg/templater/repo-apk.go index e8e3e8a..c43cd4c 100644 --- a/pkg/templater/repositories/apk.go +++ b/pkg/templater/repo-apk.go @@ -43,8 +43,8 @@ func (hr *APKRepository) Delete() error { return err } lines := strings.Split(string(fileBytes), "\n") - for i, line := range lines { - + for _, line := range lines { + fmt.Println(line) } return nil } diff --git a/pkg/templater/repositories/deb.go b/pkg/templater/repo-deb.go similarity index 90% rename from pkg/templater/repositories/deb.go rename to pkg/templater/repo-deb.go index d0644c1..4f1adba 100644 --- a/pkg/templater/repositories/deb.go +++ b/pkg/templater/repo-deb.go @@ -18,7 +18,7 @@ func (hr *DebRepository) Add() error { //deb http://fr.archive.ubuntu.com/ubuntu/ focal main restricted data := fmt.Sprintf("deb %s", hr.URL) - if err := os.WriteFile("/etc/apt/source.list.d", []byte(data)); err != nil { + if err := os.WriteFile("/etc/apt/source.list.d", []byte(data), 0600); err != nil { return err } diff --git a/pkg/templater/repositories/helm.go b/pkg/templater/repo-helm.go similarity index 100% rename from pkg/templater/repositories/helm.go rename to pkg/templater/repo-helm.go diff --git a/pkg/templater/repositories/main.go b/pkg/templater/repo.go similarity index 100% rename from pkg/templater/repositories/main.go rename to pkg/templater/repo.go diff --git a/pkg/templater/services.go b/pkg/templater/services.go index e2a03a9..ace465d 100644 --- a/pkg/templater/services.go +++ b/pkg/templater/services.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "path/filepath" + + "github.com/mitchellh/mapstructure" ) type Service struct { @@ -11,10 +13,29 @@ type Service struct { Vars map[string]interface{} `json:"Vars"` Daemons map[string]SystemService `json:"Daemons"` Users map[string]SystemUser `json:"Users"` + Repos map[string]interface{} `json:"Repositories"` Packages map[string]SystemPackage `json:"Packages"` } +func (s *Service) manageRepo(repo interface{}) error { + fmt.Printf("%v\n", repo) + if repo["type"] == "helm" { + var rp HelmRepository + mapstructure.Decode(repo, rp) + } + + return nil +} + func (s *Service) Manage(templateDir string) error { + + for _, repo := range s.Repos { + if err := s.manageRepo(repo); err != nil { + return err + } + + } + // Manage system packages for _, pack := range s.Packages { err := pack.Manage()