From 4c07c8e5f0da70c75472fafd298289a2c3c908a6 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Tue, 2 Jul 2024 22:26:55 +0000 Subject: [PATCH 1/3] Upgrade to LTS-22.27 --- stack-9.6.yaml | 3 +-- stack-9.6.yaml.lock | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/stack-9.6.yaml b/stack-9.6.yaml index 6fe6ef30c..423d73518 100644 --- a/stack-9.6.yaml +++ b/stack-9.6.yaml @@ -1,6 +1,5 @@ --- -resolver: lts-22.18 -compiler: ghc-9.6.5 +resolver: lts-22.27 flags: stratosphere: development: true diff --git a/stack-9.6.yaml.lock b/stack-9.6.yaml.lock index eae9e288c..c2b206b85 100644 --- a/stack-9.6.yaml.lock +++ b/stack-9.6.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - sha256: 9bebedd3de0195aa01fd55de7f6d4446667440297a7315e69cd72c2610af265f - size: 713338 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/18.yaml - original: lts-22.18 + sha256: bc144ddf301a5c99f2cf51c7de50279ba144fd4486cb3c66f87ed761d6bbf6e9 + size: 719131 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/27.yaml + original: lts-22.27 From cdaee12cfca612d8a0e32a59bc2f5cf4f37596f3 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Tue, 2 Jul 2024 22:26:56 +0000 Subject: [PATCH 2/3] Fix sort order --- src/Stratosphere/Value.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Stratosphere/Value.hs b/src/Stratosphere/Value.hs index 2f93a5097..3d1cfd876 100644 --- a/src/Stratosphere/Value.hs +++ b/src/Stratosphere/Value.hs @@ -100,11 +100,11 @@ mkFunc key args = JSON.object [(key, JSON.Array $ fromList args)] -- @List@ then, you can use @RefList "SubnetIds"@ to -- reference it. data ValueList a - = ValueList [Value a] - | RefList Text + = GetAZs (Value Text) | ImportValueList (Value Text) + | RefList Text | Split Text (Value a) - | GetAZs (Value Text) + | ValueList [Value a] deriving (Show, Eq) instance IsList (ValueList a) where @@ -112,21 +112,21 @@ instance IsList (ValueList a) where fromList = ValueList toList = \case - (ValueList xs) -> xs -- This is obviously not meaningful, but the IsList instance is so useful -- that I decided to allow it. - (RefList _) -> [] + (GetAZs _) -> [] (ImportValueList _) -> [] + (RefList _) -> [] (Split _ _) -> [] - (GetAZs _) -> [] + (ValueList xs) -> xs instance JSON.ToJSON a => JSON.ToJSON (ValueList a) where toJSON = \case - (ValueList vals) -> JSON.toJSON vals - (RefList ref) -> refToJSON ref + (GetAZs r) -> JSON.object [("Fn::GetAZs", JSON.toJSON r)] (ImportValueList ref) -> importValueToJSON ref + (RefList ref) -> refToJSON ref (Split d s) -> mkFunc "Fn::Split" [JSON.toJSON d, JSON.toJSON s] - (GetAZs r) -> JSON.object [("Fn::GetAZs", JSON.toJSON r)] + (ValueList vals) -> JSON.toJSON vals -- | Class used to create a 'Ref' from another type. class ToRef a b where From 848b6713626110e7eafb847aef24479588a73644 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Tue, 2 Jul 2024 22:26:57 +0000 Subject: [PATCH 3/3] Add support for Fn::Cidr --- src/Stratosphere/Value.hs | 23 +++++++++++++++++------ test/Stratosphere/ValuesSpec.hs | 3 +++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Stratosphere/Value.hs b/src/Stratosphere/Value.hs index 3d1cfd876..925adc3b1 100644 --- a/src/Stratosphere/Value.hs +++ b/src/Stratosphere/Value.hs @@ -100,7 +100,8 @@ mkFunc key args = JSON.object [(key, JSON.Array $ fromList args)] -- @List@ then, you can use @RefList "SubnetIds"@ to -- reference it. data ValueList a - = GetAZs (Value Text) + = Cidr (Value Text) (Value Text) (Value Text) + | GetAZs (Value Text) | ImportValueList (Value Text) | RefList Text | Split Text (Value a) @@ -114,6 +115,7 @@ instance IsList (ValueList a) where toList = \case -- This is obviously not meaningful, but the IsList instance is so useful -- that I decided to allow it. + (Cidr _ _ _) -> [] (GetAZs _) -> [] (ImportValueList _) -> [] (RefList _) -> [] @@ -122,11 +124,20 @@ instance IsList (ValueList a) where instance JSON.ToJSON a => JSON.ToJSON (ValueList a) where toJSON = \case - (GetAZs r) -> JSON.object [("Fn::GetAZs", JSON.toJSON r)] - (ImportValueList ref) -> importValueToJSON ref - (RefList ref) -> refToJSON ref - (Split d s) -> mkFunc "Fn::Split" [JSON.toJSON d, JSON.toJSON s] - (ValueList vals) -> JSON.toJSON vals + (Cidr ipBlock count cidrBits) -> JSON.object [("Fn::Cidr", cidrArray ipBlock count cidrBits)] + (GetAZs r) -> JSON.object [("Fn::GetAZs", JSON.toJSON r)] + (ImportValueList ref) -> importValueToJSON ref + (RefList ref) -> refToJSON ref + (Split d s) -> mkFunc "Fn::Split" [JSON.toJSON d, JSON.toJSON s] + (ValueList vals) -> JSON.toJSON vals + where + cidrArray :: Value Text -> Value Text -> Value Text -> JSON.Value + cidrArray ipBlock count cidrBits + = JSON.Array + [ JSON.toJSON ipBlock + , JSON.toJSON count + , JSON.toJSON cidrBits + ] -- | Class used to create a 'Ref' from another type. class ToRef a b where diff --git a/test/Stratosphere/ValuesSpec.hs b/test/Stratosphere/ValuesSpec.hs index c58ca1551..0bcd257c7 100644 --- a/test/Stratosphere/ValuesSpec.hs +++ b/test/Stratosphere/ValuesSpec.hs @@ -17,3 +17,6 @@ spec = do it "ImportValue and ImportValueList produce the same JSON" $ do JSON.toJSON (ImportValue "MyVal" :: Value Text) `shouldBe` JSON.toJSON (ImportValueList "MyVal" :: ValueList Text) + + it "Cidr produces expected JSON" $ do + JSON.toJSON @(ValueList Text) (Cidr "192.168.0.0/24" "6" "5") `shouldBe` JSON.object [("Fn::Cidr", JSON.Array ["192.168.0.0/24", "6", "5"])]