github.com/Redstoneguy129/cli@v0.0.0-20230211220159-15dca4e91917/internal/hostnames/reverify/reverify.go (about)

     1  package reverify
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"fmt"
     7  
     8  	"github.com/spf13/afero"
     9  	"github.com/Redstoneguy129/cli/internal/hostnames"
    10  	"github.com/Redstoneguy129/cli/internal/utils"
    11  )
    12  
    13  func Run(ctx context.Context, projectRefArg string, includeRawOutput bool, fsys afero.Fs) error {
    14  	// 1. Sanity checks.
    15  	projectRef := projectRefArg
    16  	{
    17  		if len(projectRefArg) == 0 {
    18  			ref, err := utils.LoadProjectRef(fsys)
    19  			if err != nil {
    20  				return err
    21  			}
    22  			projectRef = ref
    23  		} else if !utils.ProjectRefPattern.MatchString(projectRef) {
    24  			return errors.New("Invalid project ref format. Must be like `abcdefghijklmnopqrst`.")
    25  		}
    26  	}
    27  
    28  	// 2. attempt to re-verify custom hostname config
    29  	{
    30  		resp, err := utils.GetSupabase().ReverifyWithResponse(ctx, projectRef)
    31  		if err != nil {
    32  			return err
    33  		}
    34  		if resp.JSON201 == nil {
    35  			return errors.New("failed to re-verify custom hostname config: " + string(resp.Body))
    36  		}
    37  		status, err := hostnames.TranslateStatus(resp.JSON201, includeRawOutput)
    38  		if err != nil {
    39  			return err
    40  		}
    41  		fmt.Println(status)
    42  		return nil
    43  	}
    44  }