Skip to content

Commit

Permalink
Merge pull request #938 from endgame/aeson-2.2
Browse files Browse the repository at this point in the history
Aeson 2.2
  • Loading branch information
endgame committed Jul 18, 2023
2 parents 79ad799 + 33c55a4 commit 59d4ec9
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 62 deletions.
10 changes: 10 additions & 0 deletions .hlint.yaml
@@ -0,0 +1,10 @@
# Ignore camel-case warnings for modules containing explicit lenses
- ignore:
name: "Use camelCase"
within:
- Amazonka.Auth.SSO
- Amazonka.Data.Body
- Amazonka.EC2.Metadata
- Amazonka.Env
- Amazonka.Types
- Amazonka.Waiter
2 changes: 1 addition & 1 deletion lib/amazonka-core/amazonka-core.cabal
Expand Up @@ -100,7 +100,7 @@ library
Amazonka.Waiter

build-depends:
, aeson ^>=1.5.0.0 || >=2.0 && <2.1 || ^>=2.1
, aeson ^>=1.5.0.0 || >=2.0 && <2.2 || ^>=2.2
, attoparsec >=0.11.3
, bytestring >=0.10.8
, case-insensitive >=1.2
Expand Down
2 changes: 1 addition & 1 deletion lib/amazonka-core/src/Amazonka/Data/Log.hs
Expand Up @@ -24,7 +24,7 @@ import qualified Data.Text.Lazy as LText
import qualified Data.Text.Lazy.Encoding as LText
import qualified Network.HTTP.Client as Client
import qualified Network.HTTP.Types as HTTP
import qualified Numeric as Numeric
import qualified Numeric

class ToLog a where
-- | Convert a value to a loggable builder.
Expand Down
2 changes: 1 addition & 1 deletion lib/amazonka-core/src/Amazonka/Request.hs
Expand Up @@ -60,7 +60,7 @@ delete :: ToRequest a => Service -> a -> Request a
delete s x = (get s x) {method = DELETE}

get :: ToRequest a => Service -> a -> Request a
get s = defaultRequest s
get = defaultRequest

post :: ToRequest a => Service -> a -> Request a
post s x = (get s x) {method = POST}
Expand Down
7 changes: 4 additions & 3 deletions lib/amazonka-core/src/Amazonka/Response.hs
Expand Up @@ -37,6 +37,7 @@ import qualified Data.ByteString.Lazy as LBS
import Data.Conduit ()
import qualified Data.Conduit as Conduit
import qualified Data.Conduit.Binary as Conduit.Binary
import Data.Functor (($>))
import qualified Network.HTTP.Client as Client
import Network.HTTP.Types (ResponseHeaders)
import qualified Text.XML as XML
Expand All @@ -51,7 +52,7 @@ receiveNull ::
m (Either Error (ClientResponse (AWSResponse a)))
receiveNull rs _ =
stream $ \r _ _ _ ->
liftIO (Client.responseClose r) *> pure (Right rs)
liftIO (Client.responseClose r) $> Right rs

receiveEmpty ::
MonadResource m =>
Expand All @@ -63,7 +64,7 @@ receiveEmpty ::
m (Either Error (ClientResponse (AWSResponse a)))
receiveEmpty f _ =
stream $ \r s h _ ->
liftIO (Client.responseClose r) *> pure (f s h ())
liftIO (Client.responseClose r) $> f s h ()

receiveXMLWrapper ::
MonadResource m =>
Expand Down Expand Up @@ -166,7 +167,7 @@ stream parser Service {..} _ rs =
lazy <- sinkLBS body
Except.throwE (error status headers lazy)

lift (parser (() <$ rs) (fromEnum status) headers body) >>= \case
lift (parser (void rs) (fromEnum status) headers body) >>= \case
Right ok -> pure (ok <$ rs)
Left err ->
Except.throwE $
Expand Down
10 changes: 5 additions & 5 deletions lib/amazonka-core/src/Amazonka/Types.hs
Expand Up @@ -518,10 +518,10 @@ data Service = Service
-- ignored otherwise.
s3AddressingStyle :: S3AddressingStyle,
endpointPrefix :: ByteString,
endpoint :: (Region -> Endpoint),
timeout :: (Maybe Seconds),
check :: (Status -> Bool),
error :: (Status -> [Header] -> ByteStringLazy -> Error),
endpoint :: Region -> Endpoint,
timeout :: Maybe Seconds,
check :: Status -> Bool,
error :: Status -> [Header] -> ByteStringLazy -> Error,
retry :: Retry
}
deriving stock (Generic)
Expand Down Expand Up @@ -755,7 +755,7 @@ _SessionToken = Lens.coerced
-- | The AuthN/AuthZ credential environment.
data AuthEnv = AuthEnv
{ accessKeyId :: AccessKey,
secretAccessKey :: (Sensitive SecretKey),
secretAccessKey :: Sensitive SecretKey,
sessionToken :: Maybe (Sensitive SessionToken),
expiration :: Maybe ISO8601
}
Expand Down
20 changes: 7 additions & 13 deletions lib/amazonka-core/test/Test/Amazonka/Sign/V2Header.hs
Expand Up @@ -28,7 +28,7 @@ tests =
"should always convert set QValues to Nothing"
prop_QValueEmpty,
testCase "should keep an unset QValue" $
constructSigningQuery (QValue (Nothing :: Maybe ByteString)) @?= (QValue (Nothing :: Maybe ByteString)),
constructSigningQuery (QValue (Nothing :: Maybe ByteString)) @?= QValue (Nothing :: Maybe ByteString),
testProperty
"should discard QPairs that are not interesting to AWS"
prop_UninterestingQPairs,
Expand All @@ -38,7 +38,7 @@ tests =
testCase "should keep an empty QList" $
constructSigningQuery (QList []) @?= QList [],
testCase "should keep a list of Nothing QValues" $
constructSigningQuery (QList [(QValue Nothing)]) @?= (QList [(QValue Nothing)]),
constructSigningQuery (QList [QValue Nothing]) @?= QList [QValue Nothing],
testProperty
"should discard the contents of an unintersting QList"
prop_UninterestingQLists,
Expand All @@ -64,11 +64,11 @@ tests =
"should sort and preserve headers"
prop_SortedHeaders,
testCase "should contain empty md5 and empty content type headers if not present" $
[(HTTP.hContentMD5, ""), (HTTP.hContentType, "")] `subset` (unionNecessaryHeaders []) @?= True,
[(HTTP.hContentMD5, ""), (HTTP.hContentType, "")] `subset` unionNecessaryHeaders [] @?= True,
testCase "should preserve a set md5 and contain an empty content type header if not present" $
[(HTTP.hContentMD5, "123"), (HTTP.hContentType, "")] `subset` (unionNecessaryHeaders [(HTTP.hContentMD5, "123")]) @?= True,
[(HTTP.hContentMD5, "123"), (HTTP.hContentType, "")] `subset` unionNecessaryHeaders [(HTTP.hContentMD5, "123")] @?= True,
testCase "should preserve a set content type and preserve an empty md5 header if not present" $
[(HTTP.hContentType, "123"), (HTTP.hContentMD5, "")] `subset` (unionNecessaryHeaders [(HTTP.hContentType, "123")]) @?= True,
[(HTTP.hContentType, "123"), (HTTP.hContentMD5, "")] `subset` unionNecessaryHeaders [(HTTP.hContentType, "123")] @?= True,
testCase "should preserve md5 and content type headers if set" $
[(HTTP.hContentType, "123"), (HTTP.hContentMD5, "456")] `subset` unionNecessaryHeaders [(HTTP.hContentType, "123"), (HTTP.hContentMD5, "456")] @?= True
],
Expand All @@ -80,13 +80,7 @@ tests =
toSignerQueryBS (QPair "key" (QValue Nothing)) @?= "key",
testCase "should convert an empty value of QPair followed by QValue to just the key and just the value" $
toSignerQueryBS
( QList
[ (QPair "key" (QValue Nothing)),
( QValue $
Just "key2"
)
]
)
(QList [QPair "key" (QValue Nothing), QValue $ Just "key2"])
@?= "key&key2"
],
testGroup
Expand Down Expand Up @@ -234,7 +228,7 @@ randomHeaderGenerator =

interestingAwsHeaderName :: Gen HTTP.HeaderName
interestingAwsHeaderName =
CI.mk <$> BS8.pack <$> fmap ("aws-" <>) nonEmptyString
CI.mk . BS8.pack <$> fmap ("aws-" <>) nonEmptyString

interestingHeaderName :: Gen HTTP.HeaderName
interestingHeaderName =
Expand Down
2 changes: 1 addition & 1 deletion lib/amazonka-s3-encryption/amazonka-s3-encryption.cabal
Expand Up @@ -91,7 +91,7 @@ library
Amazonka.S3.Encryption.Types

build-depends:
, aeson ^>=1.5.0.0 || >=2.0 && <2.1 || ^>=2.1
, aeson ^>=1.5.0.0 || >=2.0 && <2.2 || ^>=2.2
, amazonka ^>=2.0
, amazonka-core ^>=2.0
, amazonka-kms ^>=2.0
Expand Down
Expand Up @@ -34,6 +34,7 @@ import Data.ByteArray (ByteArray)
import qualified Data.ByteArray as ByteArray
import qualified Data.ByteString as BS
import qualified Data.CaseInsensitive as CI
import Data.Functor ((<&>))
import qualified Data.HashMap.Strict as Map

#if MIN_VERSION_aeson(2,0,0)
Expand Down Expand Up @@ -149,7 +150,7 @@ decodeV2 ::
decodeV2 env xs m = do
a <- xs .& "X-Amz-CEK-Alg"
w <- xs .& "X-Amz-Wrap-Alg"
raw <- xs .& "X-Amz-Key-V2" >>= pure . unBase64
raw <- (xs .& "X-Amz-Key-V2") <&> unBase64
iv <- xs .& "X-Amz-IV" >>= createIV . unBase64
d <- xs .& "X-Amz-Matdesc"

Expand Down
@@ -1,12 +1,8 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module Test.Amazonka.S3.Encryption.Envelope
( envelopeTests,
)
where
module Test.Amazonka.S3.Encryption.Envelope (envelopeTests) where

import Amazonka.Core
import Amazonka.S3.Encryption.Envelope
Expand Down
3 changes: 3 additions & 0 deletions lib/amazonka/CHANGELOG.md
Expand Up @@ -11,6 +11,9 @@ Released: **?**, Compare: [2.0.0-rc2](https://github.com/brendanhay/amazonka/com

### Fixed

- `aeson ^>= 2.2` is now supported.
[\#938](https://github.com/brendanhay/amazonka/pull/938)

## [2.0.0 RC2](https://github.com/brendanhay/amazonka/tree/2.0.0-rc2)
Released: **10th July, 2023**, Compare: [2.0.0-rc1](https://github.com/brendanhay/amazonka/compare/2.0.0-rc1...2.0.0-rc2)

Expand Down
2 changes: 1 addition & 1 deletion lib/amazonka/amazonka.cabal
Expand Up @@ -99,7 +99,7 @@ library
Amazonka.Data, Amazonka.Types, Amazonka.Bytes, Amazonka.Endpoint, Amazonka.Crypto

build-depends:
, aeson ^>=1.5.0.0 || >=2.0 && <2.1 || ^>=2.1
, aeson ^>=1.5.0.0 || >=2.0 && <2.2 || ^>=2.2
, amazonka-core ^>=2.0
, amazonka-sso ^>=2.0
, amazonka-sts ^>=2.0
Expand Down
2 changes: 0 additions & 2 deletions lib/amazonka/src/Amazonka/Auth.hs
@@ -1,5 +1,3 @@
{-# LANGUAGE BangPatterns #-}

-- |
-- Module : Amazonka.Auth
-- Copyright : (c) 2013-2023 Brendan Hay
Expand Down
1 change: 0 additions & 1 deletion lib/amazonka/src/Amazonka/Auth/Background.hs
@@ -1,4 +1,3 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE Strict #-}

-- |
Expand Down
16 changes: 9 additions & 7 deletions lib/amazonka/src/Amazonka/Auth/ConfigFile.hs
Expand Up @@ -147,7 +147,9 @@ fromFilePath profile credentialsFile configFile env = liftIO $ do

-- Once we have the env from the profile, apply the region
-- if we parsed one out.
pure . maybe env' (\region -> env' {region}) $ mRegion
pure $ case mRegion of
Nothing -> env'
Just region -> env' {region}

mergeConfigs ::
-- | Credentials
Expand All @@ -157,7 +159,7 @@ mergeConfigs ::
HashMap Text (HashMap Text Text)
mergeConfigs creds confs =
HashMap.unionWith
(HashMap.union)
HashMap.union
(HashMap.fromList <$> creds)
(HashMap.fromList <$> stripProfiles confs)
where
Expand All @@ -170,7 +172,7 @@ mergeConfigs creds confs =
ws -> ws

parseConfigProfile :: HashMap Text Text -> Maybe (ConfigProfile, Maybe Region)
parseConfigProfile profile = parseProfile <&> \p -> (p, parseRegion)
parseConfigProfile profile = parseProfile <&> (,parseRegion)
where
parseProfile :: Maybe ConfigProfile
parseProfile =
Expand All @@ -194,10 +196,10 @@ parseConfigProfile profile = parseProfile <&> \p -> (p, parseRegion)
<*> ( Sensitive . SecretKey . Text.encodeUtf8
<$> HashMap.lookup "aws_secret_access_key" profile
)
<*> ( Just $
Sensitive . SessionToken . Text.encodeUtf8
<$> HashMap.lookup "aws_session_token" profile
)
<*> Just
( Sensitive . SessionToken . Text.encodeUtf8
<$> HashMap.lookup "aws_session_token" profile
)
<*> Just Nothing -- No token expiry in config file
assumeRoleFromProfile =
AssumeRoleFromProfile
Expand Down
9 changes: 6 additions & 3 deletions lib/amazonka/src/Amazonka/Auth/Keys.hs
Expand Up @@ -89,7 +89,8 @@ fromKeysEnv env = liftIO $ do
]
case mVal of
Nothing ->
throwingM _MissingEnvError $
throwingM
_MissingEnvError
"Unable to read access key from AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY)"
Just v -> pure . AccessKey $ BS8.pack v

Expand All @@ -103,13 +104,15 @@ fromKeysEnv env = liftIO $ do
]
case mVal of
Nothing ->
throwingM _MissingEnvError $
throwingM
_MissingEnvError
"Unable to read secret key from AWS_SECRET_ACCESS_KEY (or AWS_SECRET_KEY)"
Just v -> pure . Sensitive . SecretKey $ BS8.pack v

lookupSessionToken :: IO (Maybe (Sensitive SessionToken))
lookupSessionToken =
nonEmptyEnv "AWS_SESSION_TOKEN" <&> (fmap (Sensitive . SessionToken . BS8.pack))
nonEmptyEnv "AWS_SESSION_TOKEN"
<&> fmap (Sensitive . SessionToken . BS8.pack)

nonEmptyEnv :: String -> IO (Maybe String)
nonEmptyEnv var =
Expand Down
9 changes: 5 additions & 4 deletions lib/amazonka/src/Amazonka/EC2/Metadata.hs
Expand Up @@ -34,6 +34,7 @@ module Amazonka.EC2.Metadata
Maintenance (..),
Recommendations (..),
IAM (..),
IdentityCredentialsEC2 (..),
Interface (..),
Placement (..),
Services (..),
Expand Down Expand Up @@ -296,23 +297,23 @@ instance ToText Mapping where
Swap -> "root"

-- | Metadata keys for @elastic-gpus/*@.
data ElasticGpus
newtype ElasticGpus
= -- | If there is an Elastic GPU attached to the instance, contains
-- a JSON string with information about the Elastic GPU, including
-- its ID and connection information.
EGAssociations !Text
EGAssociations Text
deriving stock (Eq, Ord, Show, Generic)

instance ToText ElasticGpus where
toText = \case
EGAssociations gpuId -> "associations/" <> gpuId

-- | Metadata keys for @elastic-inference/*@.
data ElasticInference
newtype ElasticInference
= -- | If there is an Elastic Inference accelerator attached to the
-- instance, contains a JSON string with information about the
-- Elastic Inference accelerator, including its ID and type.
EIAssociations !Text
EIAssociations Text
deriving stock (Eq, Ord, Show, Generic)

instance ToText ElasticInference where
Expand Down
14 changes: 7 additions & 7 deletions lib/amazonka/src/Amazonka/Env/Hooks.hs
Expand Up @@ -438,13 +438,13 @@ noHook_ _ _ _ = pure ()
-- need to do something with specific request types, you want
-- 'addHookFor', instead.
addHook :: Typeable a => Hook a -> Hook a -> Hook a
addHook newHook oldHook = \env -> oldHook env >=> newHook env
addHook newHook oldHook env = oldHook env >=> newHook env

-- | Unconditionally add a @'Hook_' a@ to the chain of hooks. If you
-- need to do something with specific request types, you want
-- 'addHookFor_', instead.
addHook_ :: Typeable a => Hook_ a -> Hook_ a -> Hook_ a
addHook_ newHook oldHook = \env a -> oldHook env a *> newHook env a
addHook_ newHook oldHook env a = oldHook env a *> newHook env a

-- | Like 'addHook', adds an unconditional hook, but it also captures
-- the @'AWSRequest' a@ constraint. Useful for handling every AWS
Expand All @@ -466,7 +466,7 @@ addAWSRequestHook_ = addHook_
-- @
addHookFor ::
forall a b. (Typeable a, Typeable b) => Hook a -> Hook b -> Hook b
addHookFor newHook oldHook = \env ->
addHookFor newHook oldHook env =
oldHook env >=> case eqT @a @b of
Just Refl -> newHook env
Nothing -> pure
Expand All @@ -480,7 +480,7 @@ addHookFor newHook oldHook = \env ->
-- @
addHookFor_ ::
forall a b. (Typeable a, Typeable b) => Hook_ a -> Hook_ b -> Hook_ b
addHookFor_ newHook oldHook = \env a -> do
addHookFor_ newHook oldHook env a = do
oldHook env a
case eqT @a @b of
Just Refl -> newHook env a
Expand All @@ -493,7 +493,7 @@ addHookFor_ newHook oldHook = \env a -> do
-- requestHook (removeHooksFor @PutObjectRequest) :: Hooks -> Hooks
-- @
removeHooksFor :: forall a b. (Typeable a, Typeable b) => Hook b -> Hook b
removeHooksFor oldHook = \env -> case eqT @a @b of
removeHooksFor oldHook env = case eqT @a @b of
Just Refl -> pure
Nothing -> oldHook env

Expand All @@ -504,7 +504,7 @@ removeHooksFor oldHook = \env -> case eqT @a @b of
-- errorHook (removeHooksFor @(Finality, Request PutObjectRequest, Error)) :: Hooks -> Hooks
-- @
removeHooksFor_ :: forall a b. (Typeable a, Typeable b) => Hook_ b -> Hook_ b
removeHooksFor_ oldHook = \env a -> case eqT @a @b of
removeHooksFor_ oldHook env a = case eqT @a @b of
Just Refl -> pure ()
Nothing -> oldHook env a

Expand All @@ -530,7 +530,7 @@ silenceError ::
Getting Any Error e ->
Hook_ (Finality, Request a, Error) ->
Hook_ (Finality, Request a, Error)
silenceError g oldHook = \env t@(_, _, err) ->
silenceError g oldHook env t@(_, _, err) =
if has g err then pure () else oldHook env t

-- | Add default logging hooks. The default 'Env'' from
Expand Down

0 comments on commit 59d4ec9

Please sign in to comment.