github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/identity/v3/endpoints/requests.go (about) 1 package endpoints 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 6 ) 7 8 type CreateOptsBuilder interface { 9 ToEndpointCreateMap() (map[string]interface{}, error) 10 } 11 12 // CreateOpts contains the subset of Endpoint attributes that should be used 13 // to create an Endpoint. 14 type CreateOpts struct { 15 // Availability is the interface type of the Endpoint (admin, internal, 16 // or public), referenced by the golangsdk.Availability type. 17 Availability golangsdk.Availability `json:"interface" required:"true"` 18 19 // Name is the name of the Endpoint. 20 Name string `json:"name" required:"true"` 21 22 // Region is the region the Endpoint is located in. 23 // This field can be omitted or left as a blank string. 24 Region string `json:"region,omitempty"` 25 26 // URL is the url of the Endpoint. 27 URL string `json:"url" required:"true"` 28 29 // ServiceID is the ID of the service the Endpoint refers to. 30 ServiceID string `json:"service_id" required:"true"` 31 } 32 33 // ToEndpointCreateMap builds a request body from the Endpoint Create options. 34 func (opts CreateOpts) ToEndpointCreateMap() (map[string]interface{}, error) { 35 return golangsdk.BuildRequestBody(opts, "endpoint") 36 } 37 38 // Create inserts a new Endpoint into the service catalog. 39 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 40 b, err := opts.ToEndpointCreateMap() 41 if err != nil { 42 r.Err = err 43 return 44 } 45 _, r.Err = client.Post(listURL(client), &b, &r.Body, nil) 46 return 47 } 48 49 // ListOptsBuilder allows extensions to add parameters to the List request. 50 type ListOptsBuilder interface { 51 ToEndpointListParams() (string, error) 52 } 53 54 // ListOpts allows finer control over the endpoints returned by a List call. 55 // All fields are optional. 56 type ListOpts struct { 57 // Availability is the interface type of the Endpoint (admin, internal, 58 // or public), referenced by the golangsdk.Availability type. 59 Availability golangsdk.Availability `q:"interface"` 60 61 // ServiceID is the ID of the service the Endpoint refers to. 62 ServiceID string `q:"service_id"` 63 64 // Page is a result page to reference in the results. 65 Page int `q:"page"` 66 67 // PerPage determines how many results per page are returned. 68 PerPage int `q:"per_page"` 69 } 70 71 // ToEndpointListParams builds a list request from the List options. 72 func (opts ListOpts) ToEndpointListParams() (string, error) { 73 q, err := golangsdk.BuildQueryString(opts) 74 if err != nil { 75 return "", err 76 } 77 return q.String(), err 78 } 79 80 // List enumerates endpoints in a paginated collection, optionally filtered 81 // by ListOpts criteria. 82 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 83 u := listURL(client) 84 if opts != nil { 85 q, err := golangsdk.BuildQueryString(opts) 86 if err != nil { 87 return pagination.Pager{Err: err} 88 } 89 u += q.String() 90 } 91 return pagination.NewPager(client, u, func(r pagination.PageResult) pagination.Page { 92 return EndpointPage{pagination.LinkedPageBase{PageResult: r}} 93 }) 94 } 95 96 // UpdateOptsBuilder allows extensions to add parameters to the Update request. 97 type UpdateOptsBuilder interface { 98 ToEndpointUpdateMap() (map[string]interface{}, error) 99 } 100 101 // UpdateOpts contains the subset of Endpoint attributes that should be used to 102 // update an Endpoint. 103 type UpdateOpts struct { 104 // Availability is the interface type of the Endpoint (admin, internal, 105 // or public), referenced by the golangsdk.Availability type. 106 Availability golangsdk.Availability `json:"interface,omitempty"` 107 108 // Name is the name of the Endpoint. 109 Name string `json:"name,omitempty"` 110 111 // Region is the region the Endpoint is located in. 112 // This field can be omitted or left as a blank string. 113 Region string `json:"region,omitempty"` 114 115 // URL is the url of the Endpoint. 116 URL string `json:"url,omitempty"` 117 118 // ServiceID is the ID of the service the Endpoint refers to. 119 ServiceID string `json:"service_id,omitempty"` 120 } 121 122 // ToEndpointUpdateMap builds an update request body from the Update options. 123 func (opts UpdateOpts) ToEndpointUpdateMap() (map[string]interface{}, error) { 124 return golangsdk.BuildRequestBody(opts, "endpoint") 125 } 126 127 // Update changes an existing endpoint with new data. 128 func Update(client *golangsdk.ServiceClient, endpointID string, opts UpdateOptsBuilder) (r UpdateResult) { 129 b, err := opts.ToEndpointUpdateMap() 130 if err != nil { 131 r.Err = err 132 return 133 } 134 _, r.Err = client.Patch(endpointURL(client, endpointID), &b, &r.Body, nil) 135 return 136 } 137 138 // Delete removes an endpoint from the service catalog. 139 func Delete(client *golangsdk.ServiceClient, endpointID string) (r DeleteResult) { 140 _, r.Err = client.Delete(endpointURL(client, endpointID), nil) 141 return 142 }