github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/dns/v2/transfer/accept/requests.go (about) 1 package accept 2 3 import ( 4 "context" 5 "net/http" 6 7 "github.com/vnpaycloud-console/gophercloud/v2" 8 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 9 ) 10 11 // ListOptsBuilder allows extensions to add parameters to the List request. 12 type ListOptsBuilder interface { 13 ToTransferAcceptListQuery() (string, error) 14 } 15 16 // ListOpts allows the filtering and sorting of paginated collections through 17 // the API. Filtering is achieved by passing in struct field values that map to 18 // the server attributes you want to see returned. 19 // https://developer.openstack.org/api-ref/dns/ 20 type ListOpts struct { 21 Status string `q:"status"` 22 } 23 24 // ToTransferAcceptListQuery formats a ListOpts into a query string. 25 func (opts ListOpts) ToTransferAcceptListQuery() (string, error) { 26 q, err := gophercloud.BuildQueryString(opts) 27 return q.String(), err 28 } 29 30 // List implements a transfer accept List request. 31 func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 32 url := baseURL(client) 33 if opts != nil { 34 query, err := opts.ToTransferAcceptListQuery() 35 if err != nil { 36 return pagination.Pager{Err: err} 37 } 38 url += query 39 } 40 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 41 return TransferAcceptPage{pagination.LinkedPageBase{PageResult: r}} 42 }) 43 } 44 45 // Get returns information about a transfer accept, given its ID. 46 func Get(ctx context.Context, client *gophercloud.ServiceClient, transferAcceptID string) (r GetResult) { 47 resp, err := client.Get(ctx, resourceURL(client, transferAcceptID), &r.Body, nil) 48 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 49 return 50 } 51 52 // CreateOptsBuilder allows extensions to add additional attributes to the 53 // Create request. 54 type CreateOptsBuilder interface { 55 ToTransferAcceptCreateMap() (map[string]any, error) 56 } 57 58 // CreateOpts specifies the attributes used to create a transfer accept. 59 type CreateOpts struct { 60 // Key is used as part of the zone transfer accept process. 61 // This is only shown to the creator, and must be communicated out of band. 62 Key string `json:"key" required:"true"` 63 64 // ZoneTransferRequestID is ID for this zone transfer request 65 ZoneTransferRequestID string `json:"zone_transfer_request_id" required:"true"` 66 } 67 68 // ToTransferAcceptCreateMap formats an CreateOpts structure into a request body. 69 func (opts CreateOpts) ToTransferAcceptCreateMap() (map[string]any, error) { 70 b, err := gophercloud.BuildRequestBody(opts, "") 71 if err != nil { 72 return nil, err 73 } 74 return b, nil 75 } 76 77 // Create implements a transfer accept create request. 78 func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 79 b, err := opts.ToTransferAcceptCreateMap() 80 if err != nil { 81 r.Err = err 82 return 83 } 84 resp, err := client.Post(ctx, baseURL(client), &b, &r.Body, &gophercloud.RequestOpts{ 85 OkCodes: []int{http.StatusCreated, http.StatusAccepted}, 86 }) 87 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 88 return 89 }