This change moves the callback_url, metadata_url and webhooks_url from the config to the database. The goal is to move as much as possible from the config to the DB, in preparation for a potential refactor that will allow GARM to scale out. This would allow multiple nodes to share a single source of truth. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
// Copyright 2022 Cloudbase Solutions SRL
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
// not use this file except in compliance with the License. You may obtain
|
|
// a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
// License for the specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
package common
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/manifoldco/promptui"
|
|
"github.com/nbutton23/zxcvbn-go"
|
|
)
|
|
|
|
func PromptPassword(label string) (string, error) {
|
|
if label == "" {
|
|
label = "Password"
|
|
}
|
|
validate := func(input string) error {
|
|
passwordStenght := zxcvbn.PasswordStrength(input, nil)
|
|
if passwordStenght.Score < 4 {
|
|
return errors.New("password is too weak")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
prompt := promptui.Prompt{
|
|
Label: label,
|
|
Validate: validate,
|
|
Mask: '*',
|
|
}
|
|
result, err := prompt.Run()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func PromptString(label string, a ...interface{}) (string, error) {
|
|
validate := func(input string) error {
|
|
if len(input) == 0 {
|
|
return errors.New("empty input not allowed")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
prompt := promptui.Prompt{
|
|
Label: fmt.Sprintf(label, a...),
|
|
Validate: validate,
|
|
}
|
|
result, err := prompt.Run()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return result, nil
|
|
}
|