forked from frain-dev/convoy-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportal_link.go
131 lines (107 loc) · 3.2 KB
/
portal_link.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package convoy_go
import (
"context"
"fmt"
"time"
)
type PortalLink struct {
client *Client
}
type CreatePortalLinkRequest struct {
Name string `json:"name"`
Endpoints []string `json:"endpoints"`
OwnerID string `json:"owner_id"`
CanManageEndpoint bool `json:"can_manage_endpoint"`
}
type UpdatePortalLinkRequest struct {
Name string `json:"name"`
Endpoints []string `json:"endpoints"`
OwnerID string `json:"owner_id"`
CanManageEndpoint bool `json:"can_manage_endpoint"`
}
type PortalLinkResponse struct {
UID string `json:"uid"`
Name string `json:"name"`
ProjectID string `json:"project_id"`
OwnerID string `json:"owner_id"`
Endpoints []string `json:"endpoints"`
EndpointCount int `json:"endpoint_count"`
CanManageEndpoint bool `json:"can_manage_endpoint"`
Token string `json:"token"`
EndpointsMetadata []EndpointResponse `json:"endpoints_metadata"`
URL string `json:"url"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time
}
type ListPortalLinkResponse struct {
Content []PortalLinkResponse `json:"content"`
Pagination Pagination `json:"pagination"`
}
func newPortalLink(client *Client) *PortalLink {
return &PortalLink{
client: client,
}
}
func (p *PortalLink) All(ctx context.Context) (*ListPortalLinkResponse, error) {
url, err := addOptions(p.generateUrl(), nil)
if err != nil {
return nil, err
}
respPtr := &ListPortalLinkResponse{}
err = getResource(ctx, p.client, url, respPtr)
if err != nil {
return nil, err
}
return respPtr, nil
}
func (p *PortalLink) Create(ctx context.Context, body *CreatePortalLinkRequest) (*PortalLinkResponse, error) {
url, err := addOptions(p.generateUrl(), nil)
if err != nil {
return nil, err
}
respPtr := &PortalLinkResponse{}
err = postJSON(ctx, p.client, url, body, respPtr)
if err != nil {
return nil, err
}
return respPtr, nil
}
func (p *PortalLink) Find(ctx context.Context, portalLinkID string) (*PortalLinkResponse, error) {
url, err := addOptions(p.generateUrl()+"/"+portalLinkID, nil)
if err != nil {
return nil, err
}
respPtr := &PortalLinkResponse{}
err = getResource(ctx, p.client, url, respPtr)
if err != nil {
return nil, err
}
return respPtr, nil
}
func (p *PortalLink) Update(ctx context.Context, portalLinkID string, body *UpdatePortalLinkRequest) (*PortalLinkResponse, error) {
url, err := addOptions(p.generateUrl()+"/"+portalLinkID, nil)
if err != nil {
return nil, err
}
respPtr := &PortalLinkResponse{}
err = putResource(ctx, p.client, url, body, respPtr)
if err != nil {
return nil, err
}
return respPtr, nil
}
func (p *PortalLink) Revoke(ctx context.Context, portalLinkID string) error {
url, err := addOptions(p.generateUrl()+"/"+portalLinkID, nil)
if err != nil {
return err
}
err = putResource(ctx, p.client, url, nil, nil)
if err != nil {
return err
}
return nil
}
func (p *PortalLink) generateUrl() string {
return fmt.Sprintf("%s/projects/%s/portal-links", p.client.baseURL, p.client.projectID)
}