github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/flags/domain/cert.go (about)

     1  package domainFlags
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/taubyte/tau-cli/flags"
     8  	"github.com/taubyte/tau-cli/i18n"
     9  	"github.com/urfave/cli/v2"
    10  	"golang.org/x/exp/slices"
    11  )
    12  
    13  const (
    14  	CertTypeAuto   = "auto"
    15  	CertTypeInline = "inline"
    16  )
    17  
    18  var (
    19  	CertTypeOptions = []string{CertTypeInline, CertTypeAuto}
    20  
    21  	Certificate = &cli.StringFlag{
    22  		Name:    "certificate",
    23  		Aliases: []string{"c"},
    24  		Usage:   i18n.NotImplemented,
    25  	}
    26  
    27  	Key = &cli.StringFlag{
    28  		Name:    "key",
    29  		Aliases: []string{"k"},
    30  		Usage:   i18n.NotImplemented,
    31  	}
    32  
    33  	CertType = &cli.StringFlag{
    34  		Name:    "cert-type",
    35  		Aliases: []string{"type"},
    36  		Usage:   fmt.Sprintf("Type of certificate to use, currently inline is %s; %s", i18n.NotImplementedLC, flags.UsageOneOfOption(CertTypeOptions)),
    37  	}
    38  )
    39  
    40  func GetCertType(c *cli.Context) (certType string, isSet bool, err error) {
    41  	isSet = c.IsSet(CertType.Name)
    42  	if c.IsSet(CertType.Name) {
    43  		certType = c.String(CertType.Name)
    44  
    45  		if !slices.Contains(CertTypeOptions, certType) {
    46  			return "", false, fmt.Errorf("cert-type must be one of %s", strings.Join(CertTypeOptions, ", "))
    47  		}
    48  	}
    49  
    50  	return
    51  }