github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/cli/commands/resources/domain/new.go (about)

     1  package domain
     2  
     3  import (
     4  	structureSpec "github.com/taubyte/go-specs/structure"
     5  	resources "github.com/taubyte/tau-cli/cli/commands/resources/common"
     6  	"github.com/taubyte/tau-cli/cli/common"
     7  	"github.com/taubyte/tau-cli/flags"
     8  	domainFlags "github.com/taubyte/tau-cli/flags/domain"
     9  	domainI18n "github.com/taubyte/tau-cli/i18n/domain"
    10  	domainLib "github.com/taubyte/tau-cli/lib/domain"
    11  	domainPrompts "github.com/taubyte/tau-cli/prompts/domain"
    12  	domainTable "github.com/taubyte/tau-cli/table/domain"
    13  )
    14  
    15  func (link) New() common.Command {
    16  	return (&resources.New[*structureSpec.Domain]{
    17  		PromptsNew:        domainPrompts.New,
    18  		TableConfirm:      domainTable.Confirm,
    19  		PromptsCreateThis: domainPrompts.CreateThis,
    20  		I18nCreated:       domainI18n.Created,
    21  		UniqueFlags: flags.Combine(
    22  			domainFlags.Generated,
    23  			domainFlags.GeneratedPrefix,
    24  			domainFlags.FQDN,
    25  			domainFlags.CertType,
    26  			domainFlags.Certificate,
    27  			domainFlags.Key,
    28  		),
    29  
    30  		// Wrapping method to handle registration
    31  		LibNew: func(resource *structureSpec.Domain) error {
    32  			validator, err := domainLib.New(resource)
    33  			if err != nil {
    34  				return err
    35  			}
    36  
    37  			// Skipping registration check for generated FQDN
    38  			isGeneratedFqdn, err := domainLib.IsAGeneratedFQDN(resource.Fqdn)
    39  			if err != nil {
    40  				return err
    41  			}
    42  			if isGeneratedFqdn {
    43  				return nil
    44  			}
    45  
    46  			// Validate the fqdn provided
    47  			clientResponse, err := validator.ValidateFQDN(resource.Fqdn)
    48  			if err != nil {
    49  				return err
    50  			}
    51  
    52  			domainTable.Registered(resource.Fqdn, clientResponse)
    53  			return nil
    54  		},
    55  	}).Default()
    56  }