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