Skip to content

Commit

Permalink
Merge pull request #96 from codedownio/ghc9
Browse files Browse the repository at this point in the history
Support GHC 9 (with both Aeson 1 and Aeson 2)
  • Loading branch information
k8s-ci-robot authored Feb 14, 2023
2 parents 94ee7cc + f15864a commit 3018d51
Show file tree
Hide file tree
Showing 22 changed files with 175,128 additions and 168,748 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ matrix:
compiler: ": #stack 8.6.5"
addons: {apt: {packages: [libgmp-dev]}}

- env: BUILD=stack ARGS="--stack-yaml stack-9.0.2-aeson1.yaml"
compiler: ": #stack 9.0.2 (Aeson 1)"
addons: {apt: {packages: [libgmp-dev]}}

- env: BUILD=stack ARGS="--stack-yaml stack-9.0.2-aeson2.yaml"
compiler: ": #stack 9.0.2 (Aeson 2)"
addons: {apt: {packages: [libgmp-dev]}}

# Nightly builds are allowed to fail
- env: BUILD=stack ARGS="--resolver nightly"
compiler: ": #stack nightly"
Expand Down
20 changes: 10 additions & 10 deletions kubernetes-client/kubernetes-client.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: kubernetes-client
version: 0.4.2.0
version: 0.4.3.0
synopsis: Client library for Kubernetes
description: Client library for interacting with a Kubernetes cluster.
.
Expand Down Expand Up @@ -45,7 +45,7 @@ library
src
ghc-options: -Wall
build-depends:
aeson >=1.2 && <1.6
aeson >=1.2 && <3
, attoparsec >=0.13
, base >=4.7 && <5.0
, base64-bytestring
Expand All @@ -55,12 +55,12 @@ library
, data-default-class >=0.1
, either >=5.0
, filepath >=1.4
, hoauth2 >=1.11
, hoauth2 >=1.11 && <=2.3.0
, http-client >=0.5 && <0.8
, http-client-tls >=0.3
, jose-jwt >=0.8
, jsonpath >=0.1 && <0.3
, kubernetes-client-core ==0.4.2.0
, kubernetes-client-core ==0.4.3.0
, microlens >=0.4
, mtl >=2.2
, oidc-client >=0.4
Expand Down Expand Up @@ -89,7 +89,7 @@ test-suite example
hs-source-dirs:
example
build-depends:
aeson >=1.2 && <1.6
aeson >=1.2 && <3
, attoparsec >=0.13
, base >=4.7 && <5.0
, base64-bytestring
Expand All @@ -99,13 +99,13 @@ test-suite example
, data-default-class >=0.1
, either >=5.0
, filepath >=1.4
, hoauth2 >=1.11
, hoauth2 >=1.11 && <=2.3.0
, http-client >=0.5 && <0.8
, http-client-tls >=0.3
, jose-jwt >=0.8
, jsonpath >=0.1 && <0.3
, kubernetes-client
, kubernetes-client-core ==0.4.2.0
, kubernetes-client-core ==0.4.3.0
, microlens >=0.4
, mtl >=2.2
, oidc-client >=0.4
Expand Down Expand Up @@ -139,7 +139,7 @@ test-suite spec
hs-source-dirs:
test
build-depends:
aeson >=1.2 && <1.6
aeson >=1.2 && <3
, attoparsec >=0.13
, base >=4.7 && <5.0
, base64-bytestring
Expand All @@ -150,15 +150,15 @@ test-suite spec
, either >=5.0
, file-embed
, filepath >=1.4
, hoauth2 >=1.11
, hoauth2 >=1.11 && <=2.3.0
, hspec
, hspec-attoparsec
, http-client >=0.5 && <0.8
, http-client-tls >=0.3
, jose-jwt >=0.8
, jsonpath >=0.1 && <0.3
, kubernetes-client
, kubernetes-client-core ==0.4.2.0
, kubernetes-client-core ==0.4.3.0
, microlens >=0.4
, mtl >=2.2
, oidc-client >=0.4
Expand Down
8 changes: 4 additions & 4 deletions kubernetes-client/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: kubernetes-client
version: 0.4.2.0
version: 0.4.3.0
description: |
Client library for interacting with a Kubernetes cluster.
Expand Down Expand Up @@ -37,19 +37,19 @@ dependencies:
- base >=4.7 && <5.0
- base64-bytestring
- bytestring >=0.10
- aeson >=1.2 && <1.6
- aeson >=1.2 && <3
- attoparsec >=0.13
- jsonpath >=0.1 && <0.3
- connection >=0.2
- containers >= 0.5
- data-default-class >=0.1
- either >=5.0
- filepath >=1.4
- hoauth2 >=1.11
- hoauth2 >=1.11 && <=2.3.0
- http-client >=0.5 && <0.8
- http-client-tls >=0.3
- jose-jwt >=0.8
- kubernetes-client-core ==0.4.2.0
- kubernetes-client-core ==0.4.3.0
- microlens >=0.4
- mtl >=2.2
- oidc-client >=0.4
Expand Down
49 changes: 47 additions & 2 deletions kubernetes-client/src/Kubernetes/Client/Auth/OIDC.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE CPP #-}
module Kubernetes.Client.Auth.OIDC
(oidcAuth, OIDCCache, cachedOIDCAuth)
where

import Control.Applicative
import Control.Concurrent.STM
import Control.Exception.Safe (Exception, throwM)
import Control.Monad.Except (runExceptT)
import Data.Either.Combinators
import Data.Function ((&))
import Data.Map (Map)
import Data.Maybe
import Data.Monoid ((<>))
import Data.Text
import Data.Text.Encoding (encodeUtf8)
import Data.Time.Clock.POSIX (getPOSIXTime)
import Jose.Jwt
import Kubernetes.Client.Auth.Internal.Types
Expand Down Expand Up @@ -41,6 +45,9 @@ data OIDCAuth = OIDCAuth { issuerURL :: Text
, tlsParams :: TLS.ClientParams
, idTokenTVar :: TVar(Maybe Text)
, refreshTokenTVar :: TVar(Maybe Text)
#if MIN_VERSION_hoauth2(2,3,0)
, redirectUri :: URI
#endif
}

-- | Cache OIDCAuth based on issuerURL and clientID.
Expand Down Expand Up @@ -93,14 +100,43 @@ fetchToken auth@(OIDCAuth{..}) = do
tokenEndpoint <- fetchTokenEndpoint mgr auth
tokenURI <- parseURI strictURIParserOptions (Text.encodeUtf8 tokenEndpoint)
& either (throwM . OIDCURIException) pure

#if MIN_VERSION_hoauth2(2,3,0)
let oauth = OAuth2{ oauth2ClientId = clientID
, oauth2ClientSecret = clientSecret
, oauth2AuthorizeEndpoint = tokenURI
, oauth2TokenEndpoint = tokenURI
, oauth2RedirectUri = redirectUri
}
#elif MIN_VERSION_hoauth2(2,2,0)
let oauth = OAuth2{ oauth2ClientId = clientID
, oauth2ClientSecret = clientSecret
, oauth2AuthorizeEndpoint = tokenURI
, oauth2TokenEndpoint = tokenURI
, oauth2RedirectUri = Nothing
}
#elif MIN_VERSION_hoauth2(2,0,0)
let oauth = OAuth2{ oauth2ClientId = clientID
, oauth2ClientSecret = Just clientSecret
, oauth2AuthorizeEndpoint = tokenURI
, oauth2TokenEndpoint = tokenURI
, oauth2RedirectUri = Nothing
}
#else
let oauth = OAuth2{ oauthClientId = clientID
, oauthClientSecret = Just clientSecret
, oauthAccessTokenEndpoint = tokenURI
, oauthOAuthorizeEndpoint = tokenURI
, oauthCallback = Nothing
}
oauthToken <- refreshAccessToken mgr oauth (RefreshToken token)
>>= either (throwM . OIDCOAuthException) pure
#endif

#if MIN_VERSION_hoauth2(2,2,0)
oauthToken <- runExceptT (refreshAccessToken mgr oauth (RefreshToken token)) >>= either (throwM . OIDCOAuthException) pure
#else
oauthToken <- (refreshAccessToken mgr oauth (RefreshToken token)) >>= either (throwM . OIDCOAuthException) pure
#endif

case OAuth.idToken oauthToken of
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."
Just (IdToken t) -> do
Expand Down Expand Up @@ -152,6 +188,15 @@ parseOIDCAuthInfo authInfo = do
eitherTLSParams <- parseCA authInfo
idTokenTVar <- atomically $ newTVar $ Map.lookup "id-token" authInfo
refreshTokenTVar <- atomically $ newTVar $ Map.lookup "refresh-token" authInfo

#if MIN_VERSION_hoauth2(2,3,0)
redirectUri <- case Map.lookup "redirect-uri" authInfo of
Nothing -> throwM $ OIDCAuthMissingInformation "redirect-uri"
Just raw -> case parseURI laxURIParserOptions $ encodeUtf8 raw of
Left err -> throwM $ OIDCAuthMissingInformation ("Couldn't parse redirect URI: " <> show err)
Right x -> return x
#endif

return $ do
tlsParams <- mapLeft OIDCAuthCAParsingFailed eitherTLSParams
issuerURL <- lookupEither "idp-issuer-url"
Expand Down
13 changes: 13 additions & 0 deletions kubernetes-client/src/Kubernetes/Client/KubeConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE CPP #-}

{-|
Module : Kubernetes.KubeConfig
Expand Down Expand Up @@ -32,6 +33,10 @@ import Data.Typeable
import GHC.Generics
import GHC.TypeLits

#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.Key as A
#endif

camelToWithOverrides :: Char -> Map.Map String String -> Options
camelToWithOverrides c overrides = defaultOptions
{ fieldLabelModifier = modifier
Expand Down Expand Up @@ -90,12 +95,20 @@ data NamedEntity a (typeKey :: Symbol) = NamedEntity
instance (FromJSON a, Typeable a, KnownSymbol s) =>
FromJSON (NamedEntity a s) where
parseJSON = withObject ("Named" <> (show $ typeOf (undefined :: a))) $ \v ->
#if MIN_VERSION_aeson(2,0,0)
NamedEntity <$> v .: "name" <*> v .: A.fromString (symbolVal (Proxy :: Proxy s))
#else
NamedEntity <$> v .: "name" <*> v .: T.pack (symbolVal (Proxy :: Proxy s))
#endif

instance (ToJSON a, KnownSymbol s) =>
ToJSON (NamedEntity a s) where
toJSON (NamedEntity {..}) = object
#if MIN_VERSION_aeson(2,0,0)
["name" .= toJSON name, A.fromString (symbolVal (Proxy :: Proxy s)) .= toJSON entity]
#else
["name" .= toJSON name, T.pack (symbolVal (Proxy :: Proxy s)) .= toJSON entity]
#endif

toMap :: [NamedEntity a s] -> Map.Map Text a
toMap = Map.fromList . fmap (\NamedEntity {..} -> (name, entity))
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/.openapi-generator/COMMIT
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Requested Commit: 1247e774530b715fb54f719a3b10000d5dd2137b
Actual Commit: 1247e774530b715fb54f719a3b10000d5dd2137b
Requested Commit: 078232acb56b0a8cdceded6508cec4999bf547d6
Actual Commit: 078232acb56b0a8cdceded6508cec4999bf547d6
2 changes: 1 addition & 1 deletion kubernetes/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.0-SNAPSHOT
6.0.1-SNAPSHOT
1 change: 1 addition & 0 deletions kubernetes/.openapi-generator/swagger.json-default.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
681bfc7f139bd481224e485f53d0136ceb9699008bd99749547236a2122b45f0
4 changes: 2 additions & 2 deletions kubernetes/kubernetes-client-core.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: kubernetes-client-core
version: 0.4.2.0
version: 0.4.3.0
synopsis: Auto-generated kubernetes-client-core API Client
description: .
Client library for calling the Kubernetes API based on http-client.
Expand Down Expand Up @@ -35,7 +35,7 @@ library
lib
ghc-options: -Wall -funbox-strict-fields
build-depends:
aeson >=1.0 && <2.0
aeson >=1.0 && <3.0
, base >=4.7 && <5.0
, base64-bytestring >1.0 && <2.0
, bytestring >=0.10.0
Expand Down
7 changes: 6 additions & 1 deletion kubernetes/lib/Kubernetes/OpenAPI/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Module : Kubernetes.OpenAPI.Core
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-binds -fno-warn-unused-imports #-}

module Kubernetes.OpenAPI.Core where
Expand Down Expand Up @@ -79,7 +80,7 @@ data KubernetesClientConfig = KubernetesClientConfig
, configLogContext :: LogContext -- ^ Configures the logger
, configAuthMethods :: [AnyAuthMethod] -- ^ List of configured auth methods
, configValidateAuthMethods :: Bool -- ^ throw exceptions if auth methods are not configured
, configQueryExtraUnreserved :: B.ByteString -- ^ Configures additional querystring characters which must not be URI encoded, e.g. '+' or ':'
, configQueryExtraUnreserved :: B.ByteString -- ^ Configures additional querystring characters which must not be URI encoded, e.g. '+' or ':'
}

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

-- | Removes Null fields. (OpenAPI-Specification 2.0 does not allow Null in JSON)
#if MIN_VERSION_aeson(2,0,0)
_omitNulls :: [(A.Key, A.Value)] -> A.Value
#else
_omitNulls :: [(Text, A.Value)] -> A.Value
#endif
_omitNulls = A.object . P.filter notNull
where
notNull (_, A.Null) = False
Expand Down
Loading

0 comments on commit 3018d51

Please sign in to comment.