Skip to content

Commit 3018d51

Browse files
authored
Merge pull request #96 from codedownio/ghc9
Support GHC 9 (with both Aeson 1 and Aeson 2)
2 parents 94ee7cc + f15864a commit 3018d51

22 files changed

+175128
-168748
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ matrix:
7676
compiler: ": #stack 8.6.5"
7777
addons: {apt: {packages: [libgmp-dev]}}
7878

79+
- env: BUILD=stack ARGS="--stack-yaml stack-9.0.2-aeson1.yaml"
80+
compiler: ": #stack 9.0.2 (Aeson 1)"
81+
addons: {apt: {packages: [libgmp-dev]}}
82+
83+
- env: BUILD=stack ARGS="--stack-yaml stack-9.0.2-aeson2.yaml"
84+
compiler: ": #stack 9.0.2 (Aeson 2)"
85+
addons: {apt: {packages: [libgmp-dev]}}
86+
7987
# Nightly builds are allowed to fail
8088
- env: BUILD=stack ARGS="--resolver nightly"
8189
compiler: ": #stack nightly"

kubernetes-client/kubernetes-client.cabal

Lines changed: 10 additions & 10 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.2.0
8+
version: 0.4.3.0
99
synopsis: Client library for Kubernetes
1010
description: Client library for interacting with a Kubernetes cluster.
1111
.
@@ -45,7 +45,7 @@ library
4545
src
4646
ghc-options: -Wall
4747
build-depends:
48-
aeson >=1.2 && <1.6
48+
aeson >=1.2 && <3
4949
, attoparsec >=0.13
5050
, base >=4.7 && <5.0
5151
, base64-bytestring
@@ -55,12 +55,12 @@ library
5555
, data-default-class >=0.1
5656
, either >=5.0
5757
, filepath >=1.4
58-
, hoauth2 >=1.11
58+
, hoauth2 >=1.11 && <=2.3.0
5959
, http-client >=0.5 && <0.8
6060
, http-client-tls >=0.3
6161
, jose-jwt >=0.8
6262
, jsonpath >=0.1 && <0.3
63-
, kubernetes-client-core ==0.4.2.0
63+
, kubernetes-client-core ==0.4.3.0
6464
, microlens >=0.4
6565
, mtl >=2.2
6666
, oidc-client >=0.4
@@ -89,7 +89,7 @@ test-suite example
8989
hs-source-dirs:
9090
example
9191
build-depends:
92-
aeson >=1.2 && <1.6
92+
aeson >=1.2 && <3
9393
, attoparsec >=0.13
9494
, base >=4.7 && <5.0
9595
, base64-bytestring
@@ -99,13 +99,13 @@ test-suite example
9999
, data-default-class >=0.1
100100
, either >=5.0
101101
, filepath >=1.4
102-
, hoauth2 >=1.11
102+
, hoauth2 >=1.11 && <=2.3.0
103103
, http-client >=0.5 && <0.8
104104
, http-client-tls >=0.3
105105
, jose-jwt >=0.8
106106
, jsonpath >=0.1 && <0.3
107107
, kubernetes-client
108-
, kubernetes-client-core ==0.4.2.0
108+
, kubernetes-client-core ==0.4.3.0
109109
, microlens >=0.4
110110
, mtl >=2.2
111111
, oidc-client >=0.4
@@ -139,7 +139,7 @@ test-suite spec
139139
hs-source-dirs:
140140
test
141141
build-depends:
142-
aeson >=1.2 && <1.6
142+
aeson >=1.2 && <3
143143
, attoparsec >=0.13
144144
, base >=4.7 && <5.0
145145
, base64-bytestring
@@ -150,15 +150,15 @@ test-suite spec
150150
, either >=5.0
151151
, file-embed
152152
, filepath >=1.4
153-
, hoauth2 >=1.11
153+
, hoauth2 >=1.11 && <=2.3.0
154154
, hspec
155155
, hspec-attoparsec
156156
, http-client >=0.5 && <0.8
157157
, http-client-tls >=0.3
158158
, jose-jwt >=0.8
159159
, jsonpath >=0.1 && <0.3
160160
, kubernetes-client
161-
, kubernetes-client-core ==0.4.2.0
161+
, kubernetes-client-core ==0.4.3.0
162162
, microlens >=0.4
163163
, mtl >=2.2
164164
, oidc-client >=0.4

kubernetes-client/package.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: kubernetes-client
2-
version: 0.4.2.0
2+
version: 0.4.3.0
33
description: |
44
Client library for interacting with a Kubernetes cluster.
55
@@ -37,19 +37,19 @@ dependencies:
3737
- base >=4.7 && <5.0
3838
- base64-bytestring
3939
- bytestring >=0.10
40-
- aeson >=1.2 && <1.6
40+
- aeson >=1.2 && <3
4141
- attoparsec >=0.13
4242
- jsonpath >=0.1 && <0.3
4343
- connection >=0.2
4444
- containers >= 0.5
4545
- data-default-class >=0.1
4646
- either >=5.0
4747
- filepath >=1.4
48-
- hoauth2 >=1.11
48+
- hoauth2 >=1.11 && <=2.3.0
4949
- http-client >=0.5 && <0.8
5050
- http-client-tls >=0.3
5151
- jose-jwt >=0.8
52-
- kubernetes-client-core ==0.4.2.0
52+
- kubernetes-client-core ==0.4.3.0
5353
- microlens >=0.4
5454
- mtl >=2.2
5555
- oidc-client >=0.4

kubernetes-client/src/Kubernetes/Client/Auth/OIDC.hs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
{-# LANGUAGE FlexibleContexts #-}
22
{-# LANGUAGE OverloadedStrings #-}
33
{-# LANGUAGE RecordWildCards #-}
4+
{-# LANGUAGE LambdaCase #-}
5+
{-# LANGUAGE CPP #-}
46
module Kubernetes.Client.Auth.OIDC
57
(oidcAuth, OIDCCache, cachedOIDCAuth)
68
where
79

810
import Control.Applicative
911
import Control.Concurrent.STM
1012
import Control.Exception.Safe (Exception, throwM)
13+
import Control.Monad.Except (runExceptT)
1114
import Data.Either.Combinators
1215
import Data.Function ((&))
1316
import Data.Map (Map)
1417
import Data.Maybe
1518
import Data.Monoid ((<>))
1619
import Data.Text
20+
import Data.Text.Encoding (encodeUtf8)
1721
import Data.Time.Clock.POSIX (getPOSIXTime)
1822
import Jose.Jwt
1923
import Kubernetes.Client.Auth.Internal.Types
@@ -41,6 +45,9 @@ data OIDCAuth = OIDCAuth { issuerURL :: Text
4145
, tlsParams :: TLS.ClientParams
4246
, idTokenTVar :: TVar(Maybe Text)
4347
, refreshTokenTVar :: TVar(Maybe Text)
48+
#if MIN_VERSION_hoauth2(2,3,0)
49+
, redirectUri :: URI
50+
#endif
4451
}
4552

4653
-- | Cache OIDCAuth based on issuerURL and clientID.
@@ -93,14 +100,43 @@ fetchToken auth@(OIDCAuth{..}) = do
93100
tokenEndpoint <- fetchTokenEndpoint mgr auth
94101
tokenURI <- parseURI strictURIParserOptions (Text.encodeUtf8 tokenEndpoint)
95102
& either (throwM . OIDCURIException) pure
103+
104+
#if MIN_VERSION_hoauth2(2,3,0)
105+
let oauth = OAuth2{ oauth2ClientId = clientID
106+
, oauth2ClientSecret = clientSecret
107+
, oauth2AuthorizeEndpoint = tokenURI
108+
, oauth2TokenEndpoint = tokenURI
109+
, oauth2RedirectUri = redirectUri
110+
}
111+
#elif MIN_VERSION_hoauth2(2,2,0)
112+
let oauth = OAuth2{ oauth2ClientId = clientID
113+
, oauth2ClientSecret = clientSecret
114+
, oauth2AuthorizeEndpoint = tokenURI
115+
, oauth2TokenEndpoint = tokenURI
116+
, oauth2RedirectUri = Nothing
117+
}
118+
#elif MIN_VERSION_hoauth2(2,0,0)
119+
let oauth = OAuth2{ oauth2ClientId = clientID
120+
, oauth2ClientSecret = Just clientSecret
121+
, oauth2AuthorizeEndpoint = tokenURI
122+
, oauth2TokenEndpoint = tokenURI
123+
, oauth2RedirectUri = Nothing
124+
}
125+
#else
96126
let oauth = OAuth2{ oauthClientId = clientID
97127
, oauthClientSecret = Just clientSecret
98128
, oauthAccessTokenEndpoint = tokenURI
99129
, oauthOAuthorizeEndpoint = tokenURI
100130
, oauthCallback = Nothing
101131
}
102-
oauthToken <- refreshAccessToken mgr oauth (RefreshToken token)
103-
>>= either (throwM . OIDCOAuthException) pure
132+
#endif
133+
134+
#if MIN_VERSION_hoauth2(2,2,0)
135+
oauthToken <- runExceptT (refreshAccessToken mgr oauth (RefreshToken token)) >>= either (throwM . OIDCOAuthException) pure
136+
#else
137+
oauthToken <- (refreshAccessToken mgr oauth (RefreshToken token)) >>= either (throwM . OIDCOAuthException) pure
138+
#endif
139+
104140
case OAuth.idToken oauthToken of
105141
Nothing -> throwM $ OIDCGetTokenException "token response did not contain an id_token, either the scope \"openid\" wasn't requested upon login, or the provider doesn't support id_tokens as part of the refresh response."
106142
Just (IdToken t) -> do
@@ -152,6 +188,15 @@ parseOIDCAuthInfo authInfo = do
152188
eitherTLSParams <- parseCA authInfo
153189
idTokenTVar <- atomically $ newTVar $ Map.lookup "id-token" authInfo
154190
refreshTokenTVar <- atomically $ newTVar $ Map.lookup "refresh-token" authInfo
191+
192+
#if MIN_VERSION_hoauth2(2,3,0)
193+
redirectUri <- case Map.lookup "redirect-uri" authInfo of
194+
Nothing -> throwM $ OIDCAuthMissingInformation "redirect-uri"
195+
Just raw -> case parseURI laxURIParserOptions $ encodeUtf8 raw of
196+
Left err -> throwM $ OIDCAuthMissingInformation ("Couldn't parse redirect URI: " <> show err)
197+
Right x -> return x
198+
#endif
199+
155200
return $ do
156201
tlsParams <- mapLeft OIDCAuthCAParsingFailed eitherTLSParams
157202
issuerURL <- lookupEither "idp-issuer-url"

kubernetes-client/src/Kubernetes/Client/KubeConfig.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE OverloadedStrings #-}
66
{-# LANGUAGE RecordWildCards #-}
77
{-# LANGUAGE ScopedTypeVariables #-}
8+
{-# LANGUAGE CPP #-}
89

910
{-|
1011
Module : Kubernetes.KubeConfig
@@ -32,6 +33,10 @@ import Data.Typeable
3233
import GHC.Generics
3334
import GHC.TypeLits
3435

36+
#if MIN_VERSION_aeson(2,0,0)
37+
import qualified Data.Aeson.Key as A
38+
#endif
39+
3540
camelToWithOverrides :: Char -> Map.Map String String -> Options
3641
camelToWithOverrides c overrides = defaultOptions
3742
{ fieldLabelModifier = modifier
@@ -90,12 +95,20 @@ data NamedEntity a (typeKey :: Symbol) = NamedEntity
9095
instance (FromJSON a, Typeable a, KnownSymbol s) =>
9196
FromJSON (NamedEntity a s) where
9297
parseJSON = withObject ("Named" <> (show $ typeOf (undefined :: a))) $ \v ->
98+
#if MIN_VERSION_aeson(2,0,0)
99+
NamedEntity <$> v .: "name" <*> v .: A.fromString (symbolVal (Proxy :: Proxy s))
100+
#else
93101
NamedEntity <$> v .: "name" <*> v .: T.pack (symbolVal (Proxy :: Proxy s))
102+
#endif
94103

95104
instance (ToJSON a, KnownSymbol s) =>
96105
ToJSON (NamedEntity a s) where
97106
toJSON (NamedEntity {..}) = object
107+
#if MIN_VERSION_aeson(2,0,0)
108+
["name" .= toJSON name, A.fromString (symbolVal (Proxy :: Proxy s)) .= toJSON entity]
109+
#else
98110
["name" .= toJSON name, T.pack (symbolVal (Proxy :: Proxy s)) .= toJSON entity]
111+
#endif
99112

100113
toMap :: [NamedEntity a s] -> Map.Map Text a
101114
toMap = Map.fromList . fmap (\NamedEntity {..} -> (name, entity))

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: 1247e774530b715fb54f719a3b10000d5dd2137b
2-
Actual Commit: 1247e774530b715fb54f719a3b10000d5dd2137b
1+
Requested Commit: 078232acb56b0a8cdceded6508cec4999bf547d6
2+
Actual Commit: 078232acb56b0a8cdceded6508cec4999bf547d6

kubernetes/.openapi-generator/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.3.0-SNAPSHOT
1+
6.0.1-SNAPSHOT
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
681bfc7f139bd481224e485f53d0136ceb9699008bd99749547236a2122b45f0

kubernetes/kubernetes-client-core.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: kubernetes-client-core
2-
version: 0.4.2.0
2+
version: 0.4.3.0
33
synopsis: Auto-generated kubernetes-client-core API Client
44
description: .
55
Client library for calling the Kubernetes API based on http-client.
@@ -35,7 +35,7 @@ library
3535
lib
3636
ghc-options: -Wall -funbox-strict-fields
3737
build-depends:
38-
aeson >=1.0 && <2.0
38+
aeson >=1.0 && <3.0
3939
, base >=4.7 && <5.0
4040
, base64-bytestring >1.0 && <2.0
4141
, bytestring >=0.10.0

kubernetes/lib/Kubernetes/OpenAPI/Core.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Module : Kubernetes.OpenAPI.Core
2323
{-# LANGUAGE ScopedTypeVariables #-}
2424
{-# LANGUAGE TupleSections #-}
2525
{-# LANGUAGE TypeFamilies #-}
26+
{-# LANGUAGE CPP #-}
2627
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-binds -fno-warn-unused-imports #-}
2728

2829
module Kubernetes.OpenAPI.Core where
@@ -79,7 +80,7 @@ data KubernetesClientConfig = KubernetesClientConfig
7980
, configLogContext :: LogContext -- ^ Configures the logger
8081
, configAuthMethods :: [AnyAuthMethod] -- ^ List of configured auth methods
8182
, 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 ':'
83+
, configQueryExtraUnreserved :: B.ByteString -- ^ Configures additional querystring characters which must not be URI encoded, e.g. '+' or ':'
8384
}
8485

8586
-- | display the config
@@ -428,7 +429,11 @@ _applyAuthMethods req config@(KubernetesClientConfig {configAuthMethods = as}) =
428429
-- * Utils
429430

430431
-- | Removes Null fields. (OpenAPI-Specification 2.0 does not allow Null in JSON)
432+
#if MIN_VERSION_aeson(2,0,0)
433+
_omitNulls :: [(A.Key, A.Value)] -> A.Value
434+
#else
431435
_omitNulls :: [(Text, A.Value)] -> A.Value
436+
#endif
432437
_omitNulls = A.object . P.filter notNull
433438
where
434439
notNull (_, A.Null) = False

0 commit comments

Comments
 (0)