Skip to content

Commit

Permalink
refactor(galaxy): add type and constants
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Oct 19, 2024
1 parent 94f7da8 commit 2a8f7cf
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions db_lib/AnsibleApp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
Expand All @@ -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
}

Expand Down

0 comments on commit 2a8f7cf

Please sign in to comment.