|
|
@ -30,30 +30,29 @@ import (
|
|
|
|
// is fixable.
|
|
|
|
// is fixable.
|
|
|
|
var ErrRepoOutOfDate = errors.New("repository file is out of date")
|
|
|
|
var ErrRepoOutOfDate = errors.New("repository file is out of date")
|
|
|
|
|
|
|
|
|
|
|
|
// RepoFile represents the repositories.yaml file in $HELM_HOME
|
|
|
|
// File represents the repositories.yaml file in $HELM_HOME
|
|
|
|
// TODO: change type name to File in Helm 3 to resolve linter warning
|
|
|
|
type File struct {
|
|
|
|
type RepoFile struct { // nolint
|
|
|
|
|
|
|
|
APIVersion string `json:"apiVersion"`
|
|
|
|
APIVersion string `json:"apiVersion"`
|
|
|
|
Generated time.Time `json:"generated"`
|
|
|
|
Generated time.Time `json:"generated"`
|
|
|
|
Repositories []*Entry `json:"repositories"`
|
|
|
|
Repositories []*Entry `json:"repositories"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewRepoFile generates an empty repositories file.
|
|
|
|
// NewFile generates an empty repositories file.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Generated and APIVersion are automatically set.
|
|
|
|
// Generated and APIVersion are automatically set.
|
|
|
|
func NewRepoFile() *RepoFile {
|
|
|
|
func NewFile() *File {
|
|
|
|
return &RepoFile{
|
|
|
|
return &File{
|
|
|
|
APIVersion: APIVersionV1,
|
|
|
|
APIVersion: APIVersionV1,
|
|
|
|
Generated: time.Now(),
|
|
|
|
Generated: time.Now(),
|
|
|
|
Repositories: []*Entry{},
|
|
|
|
Repositories: []*Entry{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// LoadRepositoriesFile takes a file at the given path and returns a RepoFile object
|
|
|
|
// LoadFile takes a file at the given path and returns a File object
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// If this returns ErrRepoOutOfDate, it also returns a recovered RepoFile that
|
|
|
|
// If this returns ErrRepoOutOfDate, it also returns a recovered File that
|
|
|
|
// can be saved as a replacement to the out of date file.
|
|
|
|
// can be saved as a replacement to the out of date file.
|
|
|
|
func LoadRepositoriesFile(path string) (*RepoFile, error) {
|
|
|
|
func LoadFile(path string) (*File, error) {
|
|
|
|
b, err := ioutil.ReadFile(path)
|
|
|
|
b, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
@ -62,7 +61,7 @@ func LoadRepositoriesFile(path string) (*RepoFile, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
r := &RepoFile{}
|
|
|
|
r := &File{}
|
|
|
|
err = yaml.Unmarshal(b, r)
|
|
|
|
err = yaml.Unmarshal(b, r)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -74,7 +73,7 @@ func LoadRepositoriesFile(path string) (*RepoFile, error) {
|
|
|
|
if err = yaml.Unmarshal(b, &m); err != nil {
|
|
|
|
if err = yaml.Unmarshal(b, &m); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r := NewRepoFile()
|
|
|
|
r := NewFile()
|
|
|
|
for k, v := range m {
|
|
|
|
for k, v := range m {
|
|
|
|
r.Add(&Entry{
|
|
|
|
r.Add(&Entry{
|
|
|
|
Name: k,
|
|
|
|
Name: k,
|
|
|
@ -89,13 +88,13 @@ func LoadRepositoriesFile(path string) (*RepoFile, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add adds one or more repo entries to a repo file.
|
|
|
|
// Add adds one or more repo entries to a repo file.
|
|
|
|
func (r *RepoFile) Add(re ...*Entry) {
|
|
|
|
func (r *File) Add(re ...*Entry) {
|
|
|
|
r.Repositories = append(r.Repositories, re...)
|
|
|
|
r.Repositories = append(r.Repositories, re...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update attempts to replace one or more repo entries in a repo file. If an
|
|
|
|
// Update attempts to replace one or more repo entries in a repo file. If an
|
|
|
|
// entry with the same name doesn't exist in the repo file it will add it.
|
|
|
|
// entry with the same name doesn't exist in the repo file it will add it.
|
|
|
|
func (r *RepoFile) Update(re ...*Entry) {
|
|
|
|
func (r *File) Update(re ...*Entry) {
|
|
|
|
for _, target := range re {
|
|
|
|
for _, target := range re {
|
|
|
|
found := false
|
|
|
|
found := false
|
|
|
|
for j, repo := range r.Repositories {
|
|
|
|
for j, repo := range r.Repositories {
|
|
|
@ -112,7 +111,7 @@ func (r *RepoFile) Update(re ...*Entry) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Has returns true if the given name is already a repository name.
|
|
|
|
// Has returns true if the given name is already a repository name.
|
|
|
|
func (r *RepoFile) Has(name string) bool {
|
|
|
|
func (r *File) Has(name string) bool {
|
|
|
|
for _, rf := range r.Repositories {
|
|
|
|
for _, rf := range r.Repositories {
|
|
|
|
if rf.Name == name {
|
|
|
|
if rf.Name == name {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
@ -122,7 +121,7 @@ func (r *RepoFile) Has(name string) bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remove removes the entry from the list of repositories.
|
|
|
|
// Remove removes the entry from the list of repositories.
|
|
|
|
func (r *RepoFile) Remove(name string) bool {
|
|
|
|
func (r *File) Remove(name string) bool {
|
|
|
|
cp := []*Entry{}
|
|
|
|
cp := []*Entry{}
|
|
|
|
found := false
|
|
|
|
found := false
|
|
|
|
for _, rf := range r.Repositories {
|
|
|
|
for _, rf := range r.Repositories {
|
|
|
@ -137,7 +136,7 @@ func (r *RepoFile) Remove(name string) bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// WriteFile writes a repositories file to the given path.
|
|
|
|
// WriteFile writes a repositories file to the given path.
|
|
|
|
func (r *RepoFile) WriteFile(path string, perm os.FileMode) error {
|
|
|
|
func (r *File) WriteFile(path string, perm os.FileMode) error {
|
|
|
|
data, err := yaml.Marshal(r)
|
|
|
|
data, err := yaml.Marshal(r)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|