refactor(recipe): use template for ssh url

This commit is contained in:
2024-07-08 10:32:36 +02:00
parent 4cf6155fb8
commit 47013c63d6
2 changed files with 38 additions and 34 deletions

View File

@ -138,25 +138,6 @@ type Recipe struct {
Meta RecipeMeta
}
// Push pushes the latest changes to a SSH URL remote. You need to have your
// local SSH configuration for git.coopcloud.tech working for this to work
func (r Recipe) Push(dryRun bool) error {
repo, err := git.PlainOpen(r.Dir())
if err != nil {
return err
}
if err := gitPkg.CreateRemote(repo, "origin-ssh", r.Meta.SSHURL, dryRun); err != nil {
return err
}
if err := gitPkg.Push(r.Dir(), "origin-ssh", true, dryRun); err != nil {
return err
}
return nil
}
// Dir retrieves the recipe repository path
func (r Recipe) Dir() string {
return path.Join(config.RECIPES_DIR, r.Name)
@ -268,14 +249,16 @@ func (r Recipe) SampleEnv() (map[string]string, error) {
func Get2(name string) Recipe2 {
return Recipe2{
Name: name,
Dir: path.Join(config.RECIPES_DIR, name),
Name: name,
Dir: path.Join(config.RECIPES_DIR, name),
SSHURL: fmt.Sprintf(config.SSH_URL_TEMPLATE, name),
}
}
type Recipe2 struct {
Name string
Dir string
Name string
Dir string
SSHURL string
}
// Ensure makes sure the recipe exists, is up to date and has the latest version checked out.
@ -508,6 +491,25 @@ func (r Recipe2) ChaosVersion() (string, error) {
return version, nil
}
// Push pushes the latest changes to a SSH URL remote. You need to have your
// local SSH configuration for git.coopcloud.tech working for this to work
func (r Recipe2) Push(dryRun bool) error {
repo, err := git.PlainOpen(r.Dir)
if err != nil {
return err
}
if err := gitPkg.CreateRemote(repo, "origin-ssh", r.SSHURL, dryRun); err != nil {
return err
}
if err := gitPkg.Push(r.Dir, "origin-ssh", true, dryRun); err != nil {
return err
}
return nil
}
// GetRecipesLocal retrieves all local recipe directories
func GetRecipesLocal() ([]string, error) {
var recipes []string