-
Notifications
You must be signed in to change notification settings - Fork 5
/
plugin_requests.go
62 lines (48 loc) · 1.42 KB
/
plugin_requests.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
51
52
53
54
55
56
57
58
59
60
61
62
package se2
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/pkg/errors"
)
const pathPlugins = pathTenantByName + "/plugins"
type Plugin struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Lang string `json:"lang"`
Ref string `json:"ref"`
APIVersion string `json:"apiVersion"`
FQMN string `json:"fqmn"`
URI string `json:"uri"`
}
type PluginResponse struct {
Plugins []Plugin `json:"plugins"`
}
func (c *Client) GetPlugins(ctx context.Context, tenantName string) (PluginResponse, error) {
if tenantName == emptyString {
return PluginResponse{}, errors.New("client.GetPlugins: tenant name cannot be blank")
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf(c.host+pathPlugins, tenantName), nil)
if err != nil {
return PluginResponse{}, errors.Wrap(err, "client.GetPlugins: http.NewRequest")
}
res, err := c.do(req)
if err != nil {
return PluginResponse{}, errors.Wrap(err, "client.GetPlugins: c.do")
}
defer func() {
_ = res.Body.Close()
}()
if res.StatusCode != http.StatusOK {
return PluginResponse{}, fmt.Errorf(httpResponseCodeErrorFormat, "client.GetPlugins", http.StatusOK, res.StatusCode)
}
var t PluginResponse
dec := json.NewDecoder(res.Body)
dec.DisallowUnknownFields()
err = dec.Decode(&t)
if err != nil {
return PluginResponse{}, errors.Wrap(err, "client.GetPlugins: dec.Decode")
}
return t, nil
}