WIP: Some refactoring
This commit is contained in:
@ -18,6 +18,8 @@ type LockEntry struct {
|
||||
Namespace string
|
||||
RepoUrl string
|
||||
RepoName string
|
||||
Values []string
|
||||
Secrets []string
|
||||
}
|
||||
|
||||
type LockRepository struct {
|
||||
@ -27,51 +29,52 @@ type LockRepository struct {
|
||||
|
||||
type LockFile []*LockEntry
|
||||
|
||||
func NewFromFile(dir string) (LockFile, error) {
|
||||
// Init the LockFile object by reading the yaml file
|
||||
func NewFromFile(lockfileDirPath string) (LockFile, error) {
|
||||
var lockEntries LockFile
|
||||
lockfilePath := fmt.Sprintf("%s/%s", dir, LOCKFILE_NAME)
|
||||
lockfilePath := fmt.Sprintf("%s/%s", lockfileDirPath, LOCKFILE_NAME)
|
||||
|
||||
logrus.Infof("reading the lockfile file: %s", lockfilePath)
|
||||
lockFile, err := os.ReadFile(lockfilePath)
|
||||
|
||||
lockFileData, err := os.ReadFile(lockfilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := yaml.Unmarshal(lockFile, &lockEntries); err != nil {
|
||||
|
||||
if err := yaml.Unmarshal(lockFileData, &lockEntries); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lockEntries, nil
|
||||
}
|
||||
|
||||
func (lockfile LockFile) ReposFromLockfile() (repository.Repositories, error) {
|
||||
reposEntries := []LockRepository{}
|
||||
repositories := repository.Repositories{}
|
||||
for _, lockentry := range lockfile {
|
||||
newRepoEntry := &LockRepository{
|
||||
newRepoEntry := &repository.Repository{
|
||||
URL: lockentry.RepoUrl,
|
||||
Name: lockentry.RepoName,
|
||||
}
|
||||
reposEntries = append(reposEntries, *newRepoEntry)
|
||||
repositories = append(repositories, newRepoEntry)
|
||||
}
|
||||
allKeys := make(map[string]bool)
|
||||
dedupedEntries := []LockRepository{}
|
||||
|
||||
for _, repo := range reposEntries {
|
||||
// Lockfile contains an entry per a release, so one repo might be met several times
|
||||
allKeys := make(map[string]bool)
|
||||
dedupedRepositories := repository.Repositories{}
|
||||
|
||||
for _, repo := range repositories {
|
||||
if _, value := allKeys[repo.Name]; !value {
|
||||
allKeys[repo.Name] = true
|
||||
dedupedEntries = append(dedupedEntries, repo)
|
||||
dedupedRepositories = append(dedupedRepositories, repo)
|
||||
}
|
||||
}
|
||||
repos := repository.Repositories{}
|
||||
|
||||
for _, repoEntry := range dedupedEntries {
|
||||
repo := &repository.Repository{
|
||||
Name: repoEntry.Name,
|
||||
URL: repoEntry.URL,
|
||||
}
|
||||
if err := repo.KindFromUrl(); err != nil {
|
||||
for _, repoEntry := range dedupedRepositories {
|
||||
if err := repoEntry.KindFromUrl(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
return repos, nil
|
||||
return dedupedRepositories, nil
|
||||
}
|
||||
|
||||
func (lf LockFile) WriteToFile(dir string) error {
|
||||
|
Reference in New Issue
Block a user