github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf-premium/v1/certificates/Create.go (about) 1 package certificates 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/build" 6 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 7 ) 8 9 type CreateOpts struct { 10 // Certificate name. The value can contain a maximum of 64 characters. 11 // Only digits, letters, hyphens (-), underscores (_), and periods (.) are allowed. 12 Name string `json:"name" required:"true"` 13 // Certificate file. Only certificates and private key files in PEM format are supported, 14 // and the newline characters in the file must be replaced with \n. 15 Content string `json:"content" required:"true"` 16 // Certificate private key. 17 // Only certificates and private key files in PEM format are supported, 18 // and the newline characters in the files must be replaced with \n. 19 Key string `json:"key" required:"true"` 20 } 21 22 // Create will create a new Waf Certificate on the values in CreateOpts. 23 func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*CertificateResponse, error) { 24 b, err := build.RequestBody(opts, "") 25 if err != nil { 26 return nil, err 27 } 28 29 // POST /v1/{project_id}/waf/certificate 30 raw, err := client.Post(client.ServiceURL("waf", "certificate"), b, 31 nil, &golangsdk.RequestOpts{ 32 OkCodes: []int{200}, 33 MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"}, 34 }) 35 if err != nil { 36 return nil, err 37 } 38 39 var res CertificateResponse 40 err = extract.Into(raw.Body, &res) 41 return &res, err 42 } 43 44 type CertificateResponse struct { 45 // Certificate ID. 46 ID string `json:"id"` 47 // Certificate name. 48 Name string `json:"name"` 49 // Timestamp when the certificate expires. 50 ExpireAt int64 `json:"expire_time"` 51 // Timestamp when the certificate is uploaded. 52 CreatedAt int64 `json:"timestamp"` 53 }