This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
forked from okta/terraform-provider-okta
/
templates.go
88 lines (76 loc) · 2.56 KB
/
templates.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
package sdk
import (
"fmt"
"github.com/okta/okta-sdk-golang/okta"
"github.com/okta/okta-sdk-golang/okta/query"
)
type (
EmailTemplate struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
DefaultLanguage string `json:"defaultLanguage,omitempty"`
Subject string `json:"subject,omitempty"`
Template string `json:"template,omitempty"`
Translations map[string]*EmailTranslation `json:"translations,omitempty"`
}
EmailTranslation struct {
Subject string `json:"subject,omitempty"`
Template string `json:"template,omitempty"`
}
)
func (m *ApiSupplement) ListEmailTemplates() ([]*EmailTemplate, *okta.Response, error) {
url := "/api/v1/templates/emails"
req, err := m.RequestExecutor.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}
var auth []*EmailTemplate
resp, err := m.RequestExecutor.Do(req, &auth)
return auth, resp, err
}
func (m *ApiSupplement) CreateEmailTemplate(id string, body EmailTemplate, qp *query.Params) (*EmailTemplate, *okta.Response, error) {
url := "/api/v1/templates/emails"
if qp != nil {
url += qp.String()
}
req, err := m.RequestExecutor.NewRequest("POST", url, body)
if err != nil {
return nil, nil, err
}
temp := &EmailTemplate{}
resp, err := m.RequestExecutor.Do(req, temp)
return temp, resp, err
}
func (m *ApiSupplement) UpdateEmailTemplate(id string, body EmailTemplate, qp *query.Params) (*EmailTemplate, *okta.Response, error) {
url := fmt.Sprintf("/api/v1/templates/emails/%s", id)
if qp != nil {
url += qp.String()
}
req, err := m.RequestExecutor.NewRequest("PUT", url, body)
if err != nil {
return nil, nil, err
}
temp := &EmailTemplate{}
resp, err := m.RequestExecutor.Do(req, temp)
return temp, resp, err
}
func (m *ApiSupplement) GetEmailTemplate(id string) (*EmailTemplate, *okta.Response, error) {
url := fmt.Sprintf("/api/v1/templates/emails/%s", id)
req, err := m.RequestExecutor.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}
temp := &EmailTemplate{}
resp, err := m.RequestExecutor.Do(req, temp)
return temp, resp, err
}
func (m *ApiSupplement) DeleteEmailTemplate(id string) (*okta.Response, error) {
url := fmt.Sprintf("/api/v1/templates/emails/%s", id)
req, err := m.RequestExecutor.NewRequest("DELETE", url, nil)
if err != nil {
return nil, err
}
resp, err := m.RequestExecutor.Do(req, nil)
return resp, err
}