github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3/endpoints/requests.go (about) 1 package endpoints 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/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 return q.String(), err 75 } 76 77 // List enumerates endpoints in a paginated collection, optionally filtered 78 // by ListOpts criteria. 79 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 80 u := listURL(client) 81 if opts != nil { 82 q, err := golangsdk.BuildQueryString(opts) 83 if err != nil { 84 return pagination.Pager{Err: err} 85 } 86 u += q.String() 87 } 88 return pagination.NewPager(client, u, func(r pagination.PageResult) pagination.Page { 89 return EndpointPage{pagination.LinkedPageBase{PageResult: r}} 90 }) 91 } 92 93 // UpdateOptsBuilder allows extensions to add parameters to the Update request. 94 type UpdateOptsBuilder interface { 95 ToEndpointUpdateMap() (map[string]interface{}, error) 96 } 97 98 // UpdateOpts contains the subset of Endpoint attributes that should be used to 99 // update an Endpoint. 100 type UpdateOpts struct { 101 // Availability is the interface type of the Endpoint (admin, internal, 102 // or public), referenced by the golangsdk.Availability type. 103 Availability golangsdk.Availability `json:"interface,omitempty"` 104 105 // Name is the name of the Endpoint. 106 Name string `json:"name,omitempty"` 107 108 // Region is the region the Endpoint is located in. 109 // This field can be omitted or left as a blank string. 110 Region string `json:"region,omitempty"` 111 112 // URL is the url of the Endpoint. 113 URL string `json:"url,omitempty"` 114 115 // ServiceID is the ID of the service the Endpoint refers to. 116 ServiceID string `json:"service_id,omitempty"` 117 } 118 119 // ToEndpointUpdateMap builds an update request body from the Update options. 120 func (opts UpdateOpts) ToEndpointUpdateMap() (map[string]interface{}, error) { 121 return golangsdk.BuildRequestBody(opts, "endpoint") 122 } 123 124 // Update changes an existing endpoint with new data. 125 func Update(client *golangsdk.ServiceClient, endpointID string, opts UpdateOptsBuilder) (r UpdateResult) { 126 b, err := opts.ToEndpointUpdateMap() 127 if err != nil { 128 r.Err = err 129 return 130 } 131 _, r.Err = client.Patch(endpointURL(client, endpointID), &b, &r.Body, nil) 132 return 133 } 134 135 // Delete removes an endpoint from the service catalog. 136 func Delete(client *golangsdk.ServiceClient, endpointID string) (r DeleteResult) { 137 _, r.Err = client.Delete(endpointURL(client, endpointID), nil) 138 return 139 }