From 2b3d84d63111037ab0e1d0ee763fcd634c3885c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Mon, 6 Feb 2023 13:18:09 +0100 Subject: [PATCH 1/2] Add GetWebhookSigningSecret --- zendesk/webhook.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/zendesk/webhook.go b/zendesk/webhook.go index fcfb2a9b..8694cc68 100644 --- a/zendesk/webhook.go +++ b/zendesk/webhook.go @@ -43,6 +43,7 @@ type WebhookAPI interface { GetWebhook(ctx context.Context, webhookID string) (*Webhook, error) UpdateWebhook(ctx context.Context, webhookID string, hook *Webhook) error DeleteWebhook(ctx context.Context, webhookID string) error + GetWebhookSigningSecret(ctx context.Context, webhookID string) (*WebhookSigningSecret, error) } // CreateWebhook creates new webhook. @@ -115,3 +116,24 @@ func (z *Client) DeleteWebhook(ctx context.Context, webhookID string) error { return nil } + +// GetWebhookSigningSecret gets the signing secret of specified webhook. +// +// https://developer.zendesk.com/api-reference/event-connectors/webhooks/webhooks/#show-webhook-signing-secret +func (z *Client) GetWebhookSigningSecret(ctx context.Context, webhookID string) (*WebhookSigningSecret, error) { + var result struct { + SigningSecret *WebhookSigningSecret `json:"signing_secret"` + } + + body, err := z.get(ctx, fmt.Sprintf("/webhooks/%s/signing_secret", webhookID)) + if err != nil { + return nil, err + } + + err = json.Unmarshal(body, &result) + if err != nil { + return nil, err + } + + return result.SigningSecret, nil +} From 5c7b5e6a4925298ee37f803e7707ab40c25a9a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Mon, 6 Feb 2023 17:12:50 +0100 Subject: [PATCH 2/2] Generate mock --- zendesk/mock/client.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zendesk/mock/client.go b/zendesk/mock/client.go index 4918cf9f..81cda041 100644 --- a/zendesk/mock/client.go +++ b/zendesk/mock/client.go @@ -1239,6 +1239,21 @@ func (mr *ClientMockRecorder) GetWebhook(arg0, arg1 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWebhook", reflect.TypeOf((*Client)(nil).GetWebhook), arg0, arg1) } +// GetWebhookSigningSecret mocks base method. +func (m *Client) GetWebhookSigningSecret(arg0 context.Context, arg1 string) (*zendesk.WebhookSigningSecret, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetWebhookSigningSecret", arg0, arg1) + ret0, _ := ret[0].(*zendesk.WebhookSigningSecret) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetWebhookSigningSecret indicates an expected call of GetWebhookSigningSecret. +func (mr *ClientMockRecorder) GetWebhookSigningSecret(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWebhookSigningSecret", reflect.TypeOf((*Client)(nil).GetWebhookSigningSecret), arg0, arg1) +} + // ListInstallations mocks base method. func (m *Client) ListInstallations(arg0 context.Context) ([]zendesk.AppInstallation, error) { m.ctrl.T.Helper()