From 2a8f7cf884d317a27d4eb37a9d76fe3ffdac9751 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Sun, 20 Oct 2024 01:13:44 +0500 Subject: [PATCH] refactor(galaxy): add type and constants --- db_lib/AnsibleApp.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/db_lib/AnsibleApp.go b/db_lib/AnsibleApp.go index cd912e8f..485e029c 100644 --- a/db_lib/AnsibleApp.go +++ b/db_lib/AnsibleApp.go @@ -90,7 +90,7 @@ func (t *AnsibleApp) getRepoPath() string { return repo.GetFullPath() } -func (t *AnsibleApp) installGalaxyRequirementsFile(requirementsType string, requirementsFilePath string) error { +func (t *AnsibleApp) installGalaxyRequirementsFile(requirementsType GalaxyRequirementsType, requirementsFilePath string) error { requirementsHashFilePath := fmt.Sprintf("%s.md5", requirementsFilePath) @@ -101,7 +101,7 @@ func (t *AnsibleApp) installGalaxyRequirementsFile(requirementsType string, requ if hasRequirementsChanges(requirementsFilePath, requirementsHashFilePath) { if err := t.runGalaxy([]string{ - requirementsType, + string(requirementsType), "install", "-r", requirementsFilePath, @@ -125,21 +125,28 @@ func (t *AnsibleApp) GetPlaybookDir() string { return path.Dir(playbookPath) } +type GalaxyRequirementsType string + +const ( + GalaxyRole GalaxyRequirementsType = "role" + GalaxyCollection GalaxyRequirementsType = "collection" +) + func (t *AnsibleApp) installRolesRequirements() (err error) { - err = t.installGalaxyRequirementsFile("role", path.Join(t.GetPlaybookDir(), "roles", "requirements.yml")) + err = t.installGalaxyRequirementsFile(GalaxyRole, path.Join(t.GetPlaybookDir(), "roles", "requirements.yml")) if err != nil { return } - err = t.installGalaxyRequirementsFile("role", path.Join(t.getRepoPath(), "roles", "requirements.yml")) + err = t.installGalaxyRequirementsFile(GalaxyRole, path.Join(t.getRepoPath(), "roles", "requirements.yml")) return } func (t *AnsibleApp) installCollectionsRequirements() (err error) { - err = t.installGalaxyRequirementsFile("collection", path.Join(t.GetPlaybookDir(), "collections", "requirements.yml")) + err = t.installGalaxyRequirementsFile(GalaxyCollection, path.Join(t.GetPlaybookDir(), "collections", "requirements.yml")) if err != nil { return } - err = t.installGalaxyRequirementsFile("collection", path.Join(t.getRepoPath(), "collections", "requirements.yml")) + err = t.installGalaxyRequirementsFile(GalaxyCollection, path.Join(t.getRepoPath(), "collections", "requirements.yml")) return }