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

     1  package get
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"fmt"
     7  
     8  	"github.com/spf13/afero"
     9  	"github.com/Redstoneguy129/cli/internal/utils"
    10  )
    11  
    12  func Run(ctx context.Context, projectRefArg string, fsys afero.Fs) error {
    13  	// 1. Sanity checks.
    14  	projectRef := projectRefArg
    15  	{
    16  		if len(projectRefArg) == 0 {
    17  			ref, err := utils.LoadProjectRef(fsys)
    18  			if err != nil {
    19  				return err
    20  			}
    21  			projectRef = ref
    22  		} else if !utils.ProjectRefPattern.MatchString(projectRef) {
    23  			return errors.New("Invalid project ref format. Must be like `abcdefghijklmnopqrst`.")
    24  		}
    25  	}
    26  
    27  	// 2. get network restrictions
    28  	{
    29  		resp, err := utils.GetSupabase().GetNetworkRestrictionsWithResponse(ctx, projectRef)
    30  		if err != nil {
    31  			return fmt.Errorf("failed to retrieve network restrictions: %w", err)
    32  		}
    33  		if resp.JSON200 == nil {
    34  			return errors.New("failed to retrieve network restrictions; received: " + string(resp.Body))
    35  		}
    36  
    37  		if err != nil {
    38  			return err
    39  		}
    40  		fmt.Printf("DB Allowed CIDRs: %+v\n", resp.JSON200.Config.DbAllowedCidrs)
    41  		fmt.Printf("Restrictions applied successfully: %+v\n", resp.JSON200.Status == "applied")
    42  		return nil
    43  	}
    44  }