mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-06-08 22:53:00 -04:00
Refactor verify command
This commit is contained in:
parent
019003337f
commit
1317fc2bb2
15 changed files with 757 additions and 982 deletions
|
@ -3,6 +3,7 @@ package cmd
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -33,6 +34,15 @@ func isIntGreaterArg(arg int, i int) cobra.PositionalArgs {
|
|||
})
|
||||
}
|
||||
|
||||
func isIntLessArg(arg int, i int) cobra.PositionalArgs {
|
||||
return cobra.MatchAll(isIntArg(arg), func(cmd *cobra.Command, args []string) error {
|
||||
if v, _ := strconv.Atoi(args[arg]); v >= i {
|
||||
return fmt.Errorf("argument %d must be less %d, but it's %d", arg, i, v)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// warnAWS warns that AWS isn't supported.
|
||||
func warnAWS(providerPos int) cobra.PositionalArgs {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
|
@ -48,6 +58,22 @@ func isIntGreaterZeroArg(arg int) cobra.PositionalArgs {
|
|||
return isIntGreaterArg(arg, 0)
|
||||
}
|
||||
|
||||
func isPort(arg int) cobra.PositionalArgs {
|
||||
return cobra.MatchAll(
|
||||
isIntGreaterArg(arg, -1),
|
||||
isIntLessArg(arg, 65536),
|
||||
)
|
||||
}
|
||||
|
||||
func isIP(arg int) cobra.PositionalArgs {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
if ip := net.ParseIP(args[arg]); ip == nil {
|
||||
return fmt.Errorf("argument %s isn't a valid IP address", args[arg])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// isEC2InstanceType checks if argument at position arg is a key in m.
|
||||
// The argument will always be converted to lower case letters.
|
||||
func isEC2InstanceType(arg int) cobra.PositionalArgs {
|
||||
|
@ -81,6 +107,15 @@ func isAzureInstanceType(arg int) cobra.PositionalArgs {
|
|||
}
|
||||
}
|
||||
|
||||
func isCloudProvider(arg int) cobra.PositionalArgs {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
if provider := cloudprovider.FromString(args[arg]); provider == cloudprovider.Unknown {
|
||||
return fmt.Errorf("argument %s isn't a valid cloud provider", args[arg])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// isInstanceTypeForProvider returns a argument validation function that checks if the argument
|
||||
// at position typePos is a valid instance type for the cloud provider string at position
|
||||
// providerPos.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue