marketplace.go raw

   1  package govultr
   2  
   3  import (
   4  	"context"
   5  	"fmt"
   6  	"net/http"
   7  )
   8  
   9  const marketplacePath = "/v2/marketplace"
  10  
  11  // MarketplaceService is the interface to interact with the Marketplace endpoints on the Vultr API
  12  // Link: https://www.vultr.com/api/#tag/marketplace
  13  type MarketplaceService interface {
  14  	ListAppVariables(ctx context.Context, imageID string) ([]MarketplaceAppVariable, *http.Response, error)
  15  }
  16  
  17  // MarketplaceServiceHandler handles interaction with the server methods for the Vultr API
  18  type MarketplaceServiceHandler struct {
  19  	client *Client
  20  }
  21  
  22  // MarketplaceAppVariable represents a user-supplied variable for a Marketplace app
  23  type MarketplaceAppVariable struct {
  24  	Name        string `json:"name"`
  25  	Description string `json:"description"`
  26  	Required    *bool  `json:"required"`
  27  }
  28  
  29  // marketplaceAppVariablesBase holds the API response for retrieving a list of user-supplied variables for a Marketplace app
  30  type marketplaceAppVariablesBase struct {
  31  	MarketplaceAppVariables []MarketplaceAppVariable `json:"variables"`
  32  }
  33  
  34  // ListAppVariables retrieves all user-supplied variables for a Marketplace app
  35  func (d *MarketplaceServiceHandler) ListAppVariables(ctx context.Context, imageID string) ([]MarketplaceAppVariable, *http.Response, error) { //nolint:lll
  36  	uri := fmt.Sprintf("%s/apps/%s/variables", marketplacePath, imageID)
  37  
  38  	req, err := d.client.NewRequest(ctx, http.MethodGet, uri, nil)
  39  	if err != nil {
  40  		return nil, nil, err
  41  	}
  42  
  43  	marketplaceAppVariables := new(marketplaceAppVariablesBase)
  44  	resp, err := d.client.DoWithContext(ctx, req, marketplaceAppVariables)
  45  	if err != nil {
  46  		return nil, nil, err
  47  	}
  48  
  49  	return marketplaceAppVariables.MarketplaceAppVariables, resp, nil
  50  }
  51