-
Notifications
You must be signed in to change notification settings - Fork 7
/
Create.go
53 lines (47 loc) · 1.75 KB
/
Create.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
package certificates
import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
)
type CreateOpts struct {
// Certificate name. The value can contain a maximum of 64 characters.
// Only digits, letters, hyphens (-), underscores (_), and periods (.) are allowed.
Name string `json:"name" required:"true"`
// Certificate file. Only certificates and private key files in PEM format are supported,
// and the newline characters in the file must be replaced with \n.
Content string `json:"content" required:"true"`
// Certificate private key.
// Only certificates and private key files in PEM format are supported,
// and the newline characters in the files must be replaced with \n.
Key string `json:"key" required:"true"`
}
// Create will create a new Waf Certificate on the values in CreateOpts.
func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*CertificateResponse, error) {
b, err := build.RequestBody(opts, "")
if err != nil {
return nil, err
}
// POST /v1/{project_id}/waf/certificate
raw, err := client.Post(client.ServiceURL("waf", "certificate"), b,
nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
})
if err != nil {
return nil, err
}
var res CertificateResponse
err = extract.Into(raw.Body, &res)
return &res, err
}
type CertificateResponse struct {
// Certificate ID.
ID string `json:"id"`
// Certificate name.
Name string `json:"name"`
// Timestamp when the certificate expires.
ExpireAt int64 `json:"expire_time"`
// Timestamp when the certificate is uploaded.
CreatedAt int64 `json:"timestamp"`
}