-
Notifications
You must be signed in to change notification settings - Fork 88
/
extension_secrets.go
66 lines (53 loc) · 1.83 KB
/
extension_secrets.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
package helix
// GetExtensionSecretResponse response structure received
// when generating or querying for generated secrets
type ExtensionSecretCreationResponse struct {
Data ManyExtensionSecrets
ResponseCommon
}
// GetExtensionSecretResponse response structure received
// when fetching secrets for an extension
type GetExtensionSecretResponse struct {
Data ManyExtensionSecrets
ResponseCommon
}
type SecretsInformation struct {
Version int `json:"format_version"`
Secrets []Secret `json:"secrets"`
}
type ManyExtensionSecrets struct {
SecretInfo []SecretsInformation `json:"data"`
}
// Secret information about a generated secret
type Secret struct {
ActiveAt Time `json:"active_at"`
Content string `json:"content"`
Expires Time `json:"expires_at"`
}
type ExtensionSecretCreationParams struct {
ActivationDelay int `query:"delay,300"` // min 300
ExtensionID string `query:"extension_id"`
}
type GetExtensionSecretParams struct {
ExtensionID string `query:"extension_id"`
}
func (c *Client) CreateExtensionSecret(params *ExtensionSecretCreationParams) (*ExtensionSecretCreationResponse, error) {
resp, err := c.post("/extensions/jwt/secrets", &ManyExtensionSecrets{}, params)
if err != nil {
return nil, err
}
events := &ExtensionSecretCreationResponse{}
resp.HydrateResponseCommon(&events.ResponseCommon)
events.Data.SecretInfo = resp.Data.(*ManyExtensionSecrets).SecretInfo
return events, nil
}
func (c *Client) GetExtensionSecrets(params *GetExtensionSecretParams) (*GetExtensionSecretResponse, error) {
resp, err := c.postAsJSON("/extensions/jwt/secrets", &ManyExtensionSecrets{}, params)
if err != nil {
return nil, err
}
events := &GetExtensionSecretResponse{}
resp.HydrateResponseCommon(&events.ResponseCommon)
events.Data.SecretInfo = resp.Data.(*ManyExtensionSecrets).SecretInfo
return events, nil
}