github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/api/cloudcontroller/ccv3/query.go (about) 1 package ccv3 2 3 import ( 4 "net/url" 5 "strings" 6 ) 7 8 // QueryKey is the type of query that is being selected on. 9 type QueryKey string 10 11 const ( 12 // AppGUIDFilter is a query parameter for listing objects by app GUID. 13 AppGUIDFilter QueryKey = "app_guids" 14 // GUIDFilter is a query parameter for listing objects by GUID. 15 GUIDFilter QueryKey = "guids" 16 // NameFilter is a query parameter for listing objects by name. 17 NameFilter QueryKey = "names" 18 // NoRouteFilter is a query parameter for skipping route creation and unmapping existing routes. 19 NoRouteFilter QueryKey = "no_route" 20 // OrganizationGUIDFilter is a query parameter for listing objects by Organization GUID. 21 OrganizationGUIDFilter QueryKey = "organization_guids" 22 // SequenceIDFilter is a query parameter for listing objects by sequence ID. 23 SequenceIDFilter QueryKey = "sequence_ids" 24 // SpaceGUIDFilter is a query parameter for listing objects by Space GUID. 25 SpaceGUIDFilter QueryKey = "space_guids" 26 // StackFilter is a query parameter for listing objects by stack name 27 StackFilter QueryKey = "stacks" 28 // ServiceBrokerGUIDsFilter is a query parameter for getting resources according to the service broker GUID 29 ServiceBrokerGUIDsFilter QueryKey = "service_broker_guids" 30 // ServiceBrokerNamesFilter is a query parameter when getting plans or offerings according to the Service Brokers that it relates to 31 ServiceBrokerNamesFilter QueryKey = "service_broker_names" 32 // StatesFilter is a query parameter when getting a package's droplets by state 33 StatesFilter QueryKey = "states" 34 // HostsFilter is a query param for listing objects by hostname 35 HostsFilter QueryKey = "hosts" 36 // HostFilter is a query param for getting an object with the given host 37 HostFilter QueryKey = "host" 38 // PathFilter is a query param for getting an object with the given host 39 PathFilter QueryKey = "path" 40 // PortFilter is a query param for getting an object with the given port (TCP routes) 41 PortFilter QueryKey = "port" 42 43 // FieldsServiceBroker is a query parameter to include specific fields from a service broker in an offering response 44 FieldsServiceBroker QueryKey = "fields[service_broker]" 45 // FieldsServiceOfferingServiceBroker is a query parameter to include specific fields from a service broker in a plan response 46 FieldsServiceOfferingServiceBroker QueryKey = "fields[service_offering.service_broker]" 47 // FieldsSpace is a query parameter to include specific fields from a space 48 FieldsSpace QueryKey = "fields[space]" 49 // FieldsSpaceOrganization is a query parameter to include specific fields from a organization 50 FieldsSpaceOrganization QueryKey = "fields[space.organization]" 51 52 // UnmappedFilter is a query parameter specifying unmapped routes 53 UnmappedFilter QueryKey = "unmapped" 54 // OrderBy is a query parameter to specify how to order objects. 55 OrderBy QueryKey = "order_by" 56 // PerPage is a query parameter for specifying the number of results per page. 57 PerPage QueryKey = "per_page" 58 // Include is a query parameter for specifying other resources associated with the 59 // resource returned by the endpoint 60 Include QueryKey = "include" 61 62 // NameOrder is a query value for ordering by name. This value is used in 63 // conjunction with the OrderBy QueryKey. 64 NameOrder = "name" 65 66 // PositionOrder is a query value for ordering by position. This value is 67 // used in conjunction with the OrderBy QueryKey. 68 PositionOrder = "position" 69 70 // Purge is a query parameter used on a Delete request to indicate that dependent resources should also be deleted 71 Purge = "purge" 72 73 // SourceGUID is the query parameter for getting an object. Currently it's used as a package GUID 74 // to retrieve a package to later copy it to an app (CopyPackage()) 75 SourceGUID = "source_guid" 76 ) 77 78 // Query is additional settings that can be passed to some requests that can 79 // filter, sort, etc. the results. 80 type Query struct { 81 Key QueryKey 82 Values []string 83 } 84 85 // FormatQueryParameters converts a Query object into a collection that 86 // cloudcontroller.Request can accept. 87 func FormatQueryParameters(queries []Query) url.Values { 88 params := url.Values{} 89 for _, query := range queries { 90 params.Add(string(query.Key), strings.Join(query.Values, ",")) 91 } 92 93 return params 94 }