summaryrefslogtreecommitdiff
path: root/vendor/github.com/smallstep/cli-utils/ui/validators.go
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2025-08-28 01:38:06 +0000
committerFelix Hanley <felix@userspace.com.au>2025-08-28 01:38:06 +0000
commit02e6f97cd04cbcd7505e1da9a781df4321463640 (patch)
tree08d3d2317cdab4885d7c9830ed7983fecfb9fb4a /vendor/github.com/smallstep/cli-utils/ui/validators.go
parentfaa33e32b5e967fdfeac96bfc39ed3d94f9514ac (diff)
downloadcaddy-02e6f97cd04cbcd7505e1da9a781df4321463640.tar.gz
caddy-02e6f97cd04cbcd7505e1da9a781df4321463640.tar.bz2
Attempt to stop AI bots using Anubis
Diffstat (limited to 'vendor/github.com/smallstep/cli-utils/ui/validators.go')
-rw-r--r--vendor/github.com/smallstep/cli-utils/ui/validators.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/github.com/smallstep/cli-utils/ui/validators.go b/vendor/github.com/smallstep/cli-utils/ui/validators.go
new file mode 100644
index 0000000..7d8b603
--- /dev/null
+++ b/vendor/github.com/smallstep/cli-utils/ui/validators.go
@@ -0,0 +1,75 @@
+package ui
+
+import (
+ "errors"
+ "fmt"
+ "net"
+ "strings"
+
+ "github.com/manifoldco/promptui"
+)
+
+var errEmptyValue = errors.New("value is empty")
+
+// NotEmpty is a validation function that checks that the prompted string is not
+// empty.
+func NotEmpty() promptui.ValidateFunc {
+ return func(s string) error {
+ if strings.TrimSpace(s) == "" {
+ return errEmptyValue
+ }
+ return nil
+ }
+}
+
+// Address is a validation function that checks that the prompted string is a
+// valid TCP address.
+func Address() promptui.ValidateFunc {
+ return func(s string) error {
+ if _, _, err := net.SplitHostPort(s); err != nil {
+ return fmt.Errorf("%s is not an TCP address", s)
+ }
+ return nil
+ }
+}
+
+// IPAddress is validation function that checks that the prompted string is a
+// valid IP address.
+func IPAddress() promptui.ValidateFunc {
+ return func(s string) error {
+ if net.ParseIP(s) == nil {
+ return fmt.Errorf("%s is not an ip address", s)
+ }
+ return nil
+ }
+}
+
+// DNS is a validation function that checks that the prompted string is a valid
+// DNS name or IP address.
+func DNS() promptui.ValidateFunc {
+ return func(s string) error {
+ if strings.TrimSpace(s) == "" {
+ return errEmptyValue
+ }
+ if ip := net.ParseIP(s); ip != nil {
+ return nil
+ }
+ if _, _, err := net.SplitHostPort(s + ":443"); err != nil {
+ return fmt.Errorf("%s is not a valid DNS name or IP address", s)
+ }
+ return nil
+ }
+}
+
+// YesNo is a validation function that checks for a Yes/No answer.
+func YesNo() promptui.ValidateFunc {
+ return func(s string) error {
+ s = strings.ToLower(strings.TrimSpace(s))
+ switch s {
+ case "y", "yes", "n", "no":
+ return nil
+ default:
+ return fmt.Errorf("%s is not a valid answer", s)
+ }
+ }
+}