Skip to content

Commit 94ee7cc

Browse files
authored
Merge pull request #92 from jonschoning/fix-incorrectly-generated-querystrings
fix Incorrectly generated query strings (that rely on + not being urlencoded)
2 parents edfb474 + 541fb76 commit 94ee7cc

File tree

11 files changed

+120
-16
lines changed

11 files changed

+120
-16
lines changed

kubernetes-client/kubernetes-client.cabal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.12
55
-- see: https://github.com/sol/hpack
66

77
name: kubernetes-client
8-
version: 0.4.1.0
8+
version: 0.4.2.0
99
synopsis: Client library for Kubernetes
1010
description: Client library for interacting with a Kubernetes cluster.
1111
.
@@ -60,7 +60,7 @@ library
6060
, http-client-tls >=0.3
6161
, jose-jwt >=0.8
6262
, jsonpath >=0.1 && <0.3
63-
, kubernetes-client-core ==0.4.1.0
63+
, kubernetes-client-core ==0.4.2.0
6464
, microlens >=0.4
6565
, mtl >=2.2
6666
, oidc-client >=0.4
@@ -105,7 +105,7 @@ test-suite example
105105
, jose-jwt >=0.8
106106
, jsonpath >=0.1 && <0.3
107107
, kubernetes-client
108-
, kubernetes-client-core ==0.4.1.0
108+
, kubernetes-client-core ==0.4.2.0
109109
, microlens >=0.4
110110
, mtl >=2.2
111111
, oidc-client >=0.4
@@ -158,7 +158,7 @@ test-suite spec
158158
, jose-jwt >=0.8
159159
, jsonpath >=0.1 && <0.3
160160
, kubernetes-client
161-
, kubernetes-client-core ==0.4.1.0
161+
, kubernetes-client-core ==0.4.2.0
162162
, microlens >=0.4
163163
, mtl >=2.2
164164
, oidc-client >=0.4

kubernetes-client/package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: kubernetes-client
2-
version: 0.4.1.0
2+
version: 0.4.2.0
33
description: |
44
Client library for interacting with a Kubernetes cluster.
55
@@ -49,7 +49,7 @@ dependencies:
4949
- http-client >=0.5 && <0.8
5050
- http-client-tls >=0.3
5151
- jose-jwt >=0.8
52-
- kubernetes-client-core ==0.4.1.0
52+
- kubernetes-client-core ==0.4.2.0
5353
- microlens >=0.4
5454
- mtl >=2.2
5555
- oidc-client >=0.4

kubernetes/.openapi-generator/COMMIT

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Requested Commit: df877a8cf9b5e2b7a02c6e88dc4767b1e25c0b6f
2-
Actual Commit: df877a8cf9b5e2b7a02c6e88dc4767b1e25c0b6f
1+
Requested Commit: 1247e774530b715fb54f719a3b10000d5dd2137b
2+
Actual Commit: 1247e774530b715fb54f719a3b10000d5dd2137b

kubernetes/kubernetes-client-core.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: kubernetes-client-core
2-
version: 0.4.1.0
2+
version: 0.4.2.0
33
synopsis: Auto-generated kubernetes-client-core API Client
44
description: .
55
Client library for calling the Kubernetes API based on http-client.

kubernetes/lib/Kubernetes/OpenAPI/API/CustomObjects.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,11 @@ instance HasOptionalParam ListClusterCustomObject Pretty where
550550
applyOptionalParam req (Pretty xs) =
551551
req `addQuery` toQuery ("pretty", Just xs)
552552

553+
-- | /Optional Param/ "allowWatchBookmarks" - allowWatchBookmarks requests watch events with type \"BOOKMARK\". Servers that do not implement bookmarks may ignore this flag and bookmarks are sent at the server's discretion. Clients should not assume bookmarks are returned at any specific interval, nor may they assume the server will send any BOOKMARK event during a session. If this is not a watch, this field is ignored. If the feature gate WatchBookmarks is not enabled in apiserver, this field is ignored.
554+
instance HasOptionalParam ListClusterCustomObject AllowWatchBookmarks where
555+
applyOptionalParam req (AllowWatchBookmarks xs) =
556+
req `addQuery` toQuery ("allowWatchBookmarks", Just xs)
557+
553558
-- | /Optional Param/ "continue" - The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the \"next key\". This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications.
554559
instance HasOptionalParam ListClusterCustomObject Continue where
555560
applyOptionalParam req (Continue xs) =
@@ -575,6 +580,11 @@ instance HasOptionalParam ListClusterCustomObject ResourceVersion where
575580
applyOptionalParam req (ResourceVersion xs) =
576581
req `addQuery` toQuery ("resourceVersion", Just xs)
577582

583+
-- | /Optional Param/ "resourceVersionMatch" - resourceVersionMatch determines how resourceVersion is applied to list calls. It is highly recommended that resourceVersionMatch be set for list calls where resourceVersion is set See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details. Defaults to unset
584+
instance HasOptionalParam ListClusterCustomObject ResourceVersionMatch where
585+
applyOptionalParam req (ResourceVersionMatch xs) =
586+
req `addQuery` toQuery ("resourceVersionMatch", Just xs)
587+
578588
-- | /Optional Param/ "timeoutSeconds" - Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity.
579589
instance HasOptionalParam ListClusterCustomObject TimeoutSeconds where
580590
applyOptionalParam req (TimeoutSeconds xs) =
@@ -616,6 +626,11 @@ instance HasOptionalParam ListNamespacedCustomObject Pretty where
616626
applyOptionalParam req (Pretty xs) =
617627
req `addQuery` toQuery ("pretty", Just xs)
618628

629+
-- | /Optional Param/ "allowWatchBookmarks" - allowWatchBookmarks requests watch events with type \"BOOKMARK\". Servers that do not implement bookmarks may ignore this flag and bookmarks are sent at the server's discretion. Clients should not assume bookmarks are returned at any specific interval, nor may they assume the server will send any BOOKMARK event during a session. If this is not a watch, this field is ignored. If the feature gate WatchBookmarks is not enabled in apiserver, this field is ignored.
630+
instance HasOptionalParam ListNamespacedCustomObject AllowWatchBookmarks where
631+
applyOptionalParam req (AllowWatchBookmarks xs) =
632+
req `addQuery` toQuery ("allowWatchBookmarks", Just xs)
633+
619634
-- | /Optional Param/ "continue" - The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the \"next key\". This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications.
620635
instance HasOptionalParam ListNamespacedCustomObject Continue where
621636
applyOptionalParam req (Continue xs) =
@@ -641,6 +656,11 @@ instance HasOptionalParam ListNamespacedCustomObject ResourceVersion where
641656
applyOptionalParam req (ResourceVersion xs) =
642657
req `addQuery` toQuery ("resourceVersion", Just xs)
643658

659+
-- | /Optional Param/ "resourceVersionMatch" - resourceVersionMatch determines how resourceVersion is applied to list calls. It is highly recommended that resourceVersionMatch be set for list calls where resourceVersion is set See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details. Defaults to unset
660+
instance HasOptionalParam ListNamespacedCustomObject ResourceVersionMatch where
661+
applyOptionalParam req (ResourceVersionMatch xs) =
662+
req `addQuery` toQuery ("resourceVersionMatch", Just xs)
663+
644664
-- | /Optional Param/ "timeoutSeconds" - Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity.
645665
instance HasOptionalParam ListNamespacedCustomObject TimeoutSeconds where
646666
applyOptionalParam req (TimeoutSeconds xs) =

kubernetes/lib/Kubernetes/OpenAPI/Client.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import qualified Control.Exception.Safe as E
3232
import qualified Control.Monad.IO.Class as P
3333
import qualified Control.Monad as P
3434
import qualified Data.Aeson.Types as A
35+
import qualified Data.ByteString as B
3536
import qualified Data.ByteString.Char8 as BC
3637
import qualified Data.ByteString.Lazy as BL
3738
import qualified Data.ByteString.Lazy.Char8 as BCL
@@ -179,13 +180,18 @@ _toInitRequest config req0 =
179180
(configValidateAuthMethods config && (not . null . rAuthTypes) req1)
180181
(E.throw $ AuthMethodException $ "AuthMethod not configured: " <> (show . head . rAuthTypes) req1)
181182
let req2 = req1 & _setContentTypeHeader & _setAcceptHeader
182-
reqHeaders = ("User-Agent", WH.toHeader (configUserAgent config)) : paramsHeaders (rParams req2)
183-
reqQuery = NH.renderQuery True (paramsQuery (rParams req2))
184-
pReq = parsedReq { NH.method = (rMethod req2)
183+
params = rParams req2
184+
reqHeaders = ("User-Agent", WH.toHeader (configUserAgent config)) : paramsHeaders params
185+
reqQuery = let query = paramsQuery params
186+
queryExtraUnreserved = configQueryExtraUnreserved config
187+
in if B.null queryExtraUnreserved
188+
then NH.renderQuery True query
189+
else NH.renderQueryPartialEscape True (toPartialEscapeQuery queryExtraUnreserved query)
190+
pReq = parsedReq { NH.method = rMethod req2
185191
, NH.requestHeaders = reqHeaders
186192
, NH.queryString = reqQuery
187193
}
188-
outReq <- case paramsBody (rParams req2) of
194+
outReq <- case paramsBody params of
189195
ParamBodyNone -> pure (pReq { NH.requestBody = mempty })
190196
ParamBodyB bs -> pure (pReq { NH.requestBody = NH.RequestBodyBS bs })
191197
ParamBodyBL bl -> pure (pReq { NH.requestBody = NH.RequestBodyLBS bl })

kubernetes/lib/Kubernetes/OpenAPI/Core.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import Data.Function ((&))
6767
import Data.Foldable(foldlM)
6868
import Data.Monoid ((<>))
6969
import Data.Text (Text)
70-
import Prelude (($), (.), (<$>), (<*>), Maybe(..), Bool(..), Char, String, fmap, mempty, pure, return, show, IO, Monad, Functor)
70+
import Prelude (($), (.), (&&), (<$>), (<*>), Maybe(..), Bool(..), Char, String, fmap, mempty, pure, return, show, IO, Monad, Functor, maybe)
7171

7272
-- * KubernetesClientConfig
7373

@@ -79,6 +79,7 @@ data KubernetesClientConfig = KubernetesClientConfig
7979
, configLogContext :: LogContext -- ^ Configures the logger
8080
, configAuthMethods :: [AnyAuthMethod] -- ^ List of configured auth methods
8181
, configValidateAuthMethods :: Bool -- ^ throw exceptions if auth methods are not configured
82+
, configQueryExtraUnreserved :: B.ByteString -- ^ Configures additional querystring characters which must not be URI encoded, e.g. '+' or ':'
8283
}
8384

8485
-- | display the config
@@ -109,6 +110,7 @@ newConfig = do
109110
, configLogContext = logCxt
110111
, configAuthMethods = []
111112
, configValidateAuthMethods = True
113+
, configQueryExtraUnreserved = "+"
112114
}
113115

114116
-- | updates config use AuthMethod on matching requests
@@ -336,6 +338,16 @@ toQuery :: WH.ToHttpApiData a => (BC.ByteString, Maybe a) -> [NH.QueryItem]
336338
toQuery x = [(fmap . fmap) toQueryParam x]
337339
where toQueryParam = T.encodeUtf8 . WH.toQueryParam
338340

341+
toPartialEscapeQuery :: B.ByteString -> NH.Query -> NH.PartialEscapeQuery
342+
toPartialEscapeQuery extraUnreserved query = fmap (\(k, v) -> (k, maybe [] go v)) query
343+
where go :: B.ByteString -> [NH.EscapeItem]
344+
go v = v & B.groupBy (\a b -> a `B.notElem` extraUnreserved && b `B.notElem` extraUnreserved)
345+
& fmap (\xs -> if B.null xs then NH.QN xs
346+
else if B.head xs `B.elem` extraUnreserved
347+
then NH.QN xs -- Not Encoded
348+
else NH.QE xs -- Encoded
349+
)
350+
339351
-- *** OpenAPI `CollectionFormat` Utils
340352

341353
-- | Determines the format of the array if type array is used.

kubernetes/openapi.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68576,6 +68576,17 @@ paths:
6857668576
required: true
6857768577
schema:
6857868578
type: string
68579+
- description: allowWatchBookmarks requests watch events with type "BOOKMARK".
68580+
Servers that do not implement bookmarks may ignore this flag and bookmarks
68581+
are sent at the server's discretion. Clients should not assume bookmarks
68582+
are returned at any specific interval, nor may they assume the server will
68583+
send any BOOKMARK event during a session. If this is not a watch, this field
68584+
is ignored. If the feature gate WatchBookmarks is not enabled in apiserver,
68585+
this field is ignored.
68586+
in: query
68587+
name: allowWatchBookmarks
68588+
schema:
68589+
type: boolean
6857968590
- description: |-
6858068591
The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the "next key".
6858168592

@@ -68614,6 +68625,14 @@ paths:
6861468625
name: resourceVersion
6861568626
schema:
6861668627
type: string
68628+
- description: |-
68629+
resourceVersionMatch determines how resourceVersion is applied to list calls. It is highly recommended that resourceVersionMatch be set for list calls where resourceVersion is set See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.
68630+
68631+
Defaults to unset
68632+
in: query
68633+
name: resourceVersionMatch
68634+
schema:
68635+
type: string
6861768636
- description: Timeout for the list/watch call. This limits the duration of
6861868637
the call, regardless of any activity or inactivity.
6861968638
in: query
@@ -68819,6 +68838,17 @@ paths:
6881968838
required: true
6882068839
schema:
6882168840
type: string
68841+
- description: allowWatchBookmarks requests watch events with type "BOOKMARK".
68842+
Servers that do not implement bookmarks may ignore this flag and bookmarks
68843+
are sent at the server's discretion. Clients should not assume bookmarks
68844+
are returned at any specific interval, nor may they assume the server will
68845+
send any BOOKMARK event during a session. If this is not a watch, this field
68846+
is ignored. If the feature gate WatchBookmarks is not enabled in apiserver,
68847+
this field is ignored.
68848+
in: query
68849+
name: allowWatchBookmarks
68850+
schema:
68851+
type: boolean
6882268852
- description: |-
6882368853
The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the "next key".
6882468854

@@ -68857,6 +68887,14 @@ paths:
6885768887
name: resourceVersion
6885868888
schema:
6885968889
type: string
68890+
- description: |-
68891+
resourceVersionMatch determines how resourceVersion is applied to list calls. It is highly recommended that resourceVersionMatch be set for list calls where resourceVersion is set See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.
68892+
68893+
Defaults to unset
68894+
in: query
68895+
name: resourceVersionMatch
68896+
schema:
68897+
type: string
6886068898
- description: Timeout for the list/watch call. This limits the duration of
6886168899
the call, regardless of any activity or inactivity.
6886268900
in: query

kubernetes/stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resolver: lts-14.7
1+
resolver: lts-18.6
22
build:
33
haddock-arguments:
44
haddock-args:

0 commit comments

Comments
 (0)