Fix tests and make URLs optional in config

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2024-06-06 17:23:20 +00:00
parent 9748aa47af
commit 3992f97d8c
7 changed files with 80 additions and 93 deletions

View file

@ -121,7 +121,7 @@ garm-cli init --name=dev --url=https://runner.example.com --username=admin --pas
func ensureDefaultEndpoints(loginURL string) (err error) {
if metadataURL == "" {
metadataURL, err = url.JoinPath(loginURL, "api/v1/callbacks")
metadataURL, err = url.JoinPath(loginURL, "api/v1/metadata")
if err != nil {
return err
}
@ -160,10 +160,16 @@ func promptUnsetInitVariables() error {
}
if loginPassword == "" {
loginPassword, err = common.PromptPassword("Password")
passwd, err := common.PromptPassword("Password", "")
if err != nil {
return err
}
_, err = common.PromptPassword("Confirm password", passwd)
if err != nil {
return err
}
loginPassword = passwd
}
return nil

View file

@ -264,7 +264,7 @@ func promptUnsetLoginVariables() error {
}
if loginPassword == "" {
loginPassword, err = common.PromptPassword("Password")
loginPassword, err = common.PromptPassword("Password", "")
if err != nil {
return err
}

View file

@ -22,7 +22,7 @@ import (
"github.com/nbutton23/zxcvbn-go"
)
func PromptPassword(label string) (string, error) {
func PromptPassword(label string, compareTo string) (string, error) {
if label == "" {
label = "Password"
}
@ -31,6 +31,9 @@ func PromptPassword(label string) (string, error) {
if passwordStenght.Score < 4 {
return errors.New("password is too weak")
}
if compareTo != "" && compareTo != input {
return errors.New("passwords do not match")
}
return nil
}