github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/apigw/v2/key/Create.go (about) 1 package key 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 GatewayID string `json:"-"` 11 Name string `json:"name" required:"true"` 12 SignType string `json:"sign_type,omitempty"` 13 SignKey string `json:"sign_key,omitempty"` 14 SignSecret string `json:"sign_secret,omitempty"` 15 SignAlgorithm string `json:"sign_algorithm,omitempty"` 16 } 17 18 func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*SignKeyResp, error) { 19 b, err := build.RequestBody(opts, "") 20 if err != nil { 21 return nil, err 22 } 23 24 raw, err := client.Post(client.ServiceURL("apigw", "instances", opts.GatewayID, "signs"), b, 25 nil, &golangsdk.RequestOpts{ 26 OkCodes: []int{201}, 27 }) 28 if err != nil { 29 return nil, err 30 } 31 32 var res SignKeyResp 33 34 err = extract.Into(raw.Body, &res) 35 return &res, err 36 } 37 38 type SignKeyResp struct { 39 Name string `json:"name"` 40 SignType string `json:"sign_type"` 41 SignKey string `json:"sign_key"` 42 SignSecret string `json:"sign_secret"` 43 SignAlgorithm string `json:"sign_algorithm"` 44 UpdateTime string `json:"update_time"` 45 CreateTime string `json:"create_time"` 46 ID string `json:"id"` 47 }