github.com/gophercloud/gophercloud@v1.11.0/openstack/dns/v2/transfer/request/requests.go (about) 1 package request 2 3 import ( 4 "net/http" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/pagination" 8 ) 9 10 // ListOptsBuilder allows extensions to add parameters to the List request. 11 type ListOptsBuilder interface { 12 ToTransferRequestListQuery() (string, error) 13 } 14 15 // ListOpts allows the filtering and sorting of paginated collections through 16 // the API. Filtering is achieved by passing in struct field values that map to 17 // the server attributes you want to see returned. 18 // https://developer.openstack.org/api-ref/dns/ 19 type ListOpts struct { 20 Status string `q:"status"` 21 } 22 23 // ToTransferRequestListQuery formats a ListOpts into a query string. 24 func (opts ListOpts) ToTransferRequestListQuery() (string, error) { 25 q, err := gophercloud.BuildQueryString(opts) 26 return q.String(), err 27 } 28 29 // List implements a transfer request List request. 30 func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 31 url := baseURL(client) 32 if opts != nil { 33 query, err := opts.ToTransferRequestListQuery() 34 if err != nil { 35 return pagination.Pager{Err: err} 36 } 37 url += query 38 } 39 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 40 return TransferRequestPage{pagination.LinkedPageBase{PageResult: r}} 41 }) 42 } 43 44 // Get returns information about a transfer request, given its ID. 45 func Get(client *gophercloud.ServiceClient, transferRequestID string) (r GetResult) { 46 resp, err := client.Get(resourceURL(client, transferRequestID), &r.Body, nil) 47 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 48 return 49 } 50 51 // CreateOptsBuilder allows extensions to add additional attributes to the 52 // Create request. 53 type CreateOptsBuilder interface { 54 ToTransferRequestCreateMap() (map[string]interface{}, error) 55 } 56 57 // CreateOpts specifies the attributes used to create a transfer request. 58 type CreateOpts struct { 59 // TargetProjectID is ID that the request will be limited to. No other project 60 // will be allowed to accept this request. 61 TargetProjectID string `json:"target_project_id,omitempty"` 62 63 // Description of the transfer request. 64 Description string `json:"description,omitempty"` 65 } 66 67 // ToTransferRequestCreateMap formats an CreateOpts structure into a request body. 68 func (opts CreateOpts) ToTransferRequestCreateMap() (map[string]interface{}, error) { 69 b, err := gophercloud.BuildRequestBody(opts, "") 70 if err != nil { 71 return nil, err 72 } 73 return b, nil 74 } 75 76 // Create implements a transfer request create request. 77 func Create(client *gophercloud.ServiceClient, zoneID string, opts CreateOptsBuilder) (r CreateResult) { 78 b, err := opts.ToTransferRequestCreateMap() 79 if err != nil { 80 r.Err = err 81 return 82 } 83 resp, err := client.Post(createURL(client, zoneID), &b, &r.Body, &gophercloud.RequestOpts{ 84 OkCodes: []int{http.StatusCreated, http.StatusAccepted}, 85 }) 86 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 87 return 88 } 89 90 // UpdateOptsBuilder allows extensions to add additional attributes to the 91 // Update request. 92 type UpdateOptsBuilder interface { 93 ToTransferRequestUpdateMap() (map[string]interface{}, error) 94 } 95 96 // UpdateOpts specifies the attributes to update a transfer request. 97 type UpdateOpts struct { 98 // TargetProjectID is ID that the request will be limited to. No other project 99 // will be allowed to accept this request. 100 TargetProjectID string `json:"target_project_id,omitempty"` 101 102 // Description of the transfer request. 103 Description string `json:"description,omitempty"` 104 } 105 106 // ToTransferRequestUpdateMap formats an UpdateOpts structure into a request body. 107 func (opts UpdateOpts) ToTransferRequestUpdateMap() (map[string]interface{}, error) { 108 b, err := gophercloud.BuildRequestBody(opts, "") 109 if err != nil { 110 return nil, err 111 } 112 return b, nil 113 } 114 115 // Update implements a transfer request update request. 116 func Update(client *gophercloud.ServiceClient, transferID string, opts UpdateOptsBuilder) (r UpdateResult) { 117 b, err := opts.ToTransferRequestUpdateMap() 118 if err != nil { 119 r.Err = err 120 return 121 } 122 resp, err := client.Patch(resourceURL(client, transferID), &b, &r.Body, &gophercloud.RequestOpts{ 123 OkCodes: []int{http.StatusOK, http.StatusAccepted}, 124 }) 125 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 126 return 127 } 128 129 // Delete implements a transfer request delete request. 130 func Delete(client *gophercloud.ServiceClient, transferID string) (r DeleteResult) { 131 resp, err := client.Delete(resourceURL(client, transferID), &gophercloud.RequestOpts{ 132 OkCodes: []int{http.StatusNoContent}, 133 }) 134 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 135 return 136 }