Skip to content

Commit

Permalink
[stack-deploy] Change to record dot syntax on static getField calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Dec 7, 2023
1 parent 44764f5 commit 498241b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
6 changes: 3 additions & 3 deletions stack-deploy/src/StackDeploy/EnvSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ fetchParam
fetchParam stack stratosphereParameter =
maybe
(failOutputKey "missing")
(maybe (failOutputKey "has no value") pure . getField @"parameterValue")
(maybe (failOutputKey "has no value") pure . (.parameterValue))
$ Foldable.find
((==) (pure key) . getField @"parameterKey")
(fromMaybe [] $ getField @"parameters" stack)
((==) (pure key) . (.parameterKey))
(fromMaybe [] stack.parameters)
where
key = stratosphereParameter.name

Expand Down
12 changes: 3 additions & 9 deletions stack-deploy/src/StackDeploy/Parameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ fromStratosphereParameter
:: Stratosphere.Parameter
-> ParameterValue
-> Parameter
fromStratosphereParameter stratosphereParameter = Parameter name
where
name
= ParameterName
$ getField @"name" stratosphereParameter
fromStratosphereParameter = Parameter . ParameterName . (.name)

instance IsList Parameters where
type Item Parameters = Parameter
Expand Down Expand Up @@ -114,11 +110,9 @@ expandTemplate parameters@(Parameters hash) template
templateParameterNames :: Set ParameterName
templateParameterNames
= Set.fromList
$ ParameterName . getField @"name" <$> templateParameters
$ ParameterName . (.name) <$> templateParameters

templateParameters :: [Stratosphere.Parameter]
templateParameters
= maybe
Alternative.empty
(getField @"parameterList")
= maybe Alternative.empty (.parameterList)
$ template.stratosphere.parameters
24 changes: 12 additions & 12 deletions stack-deploy/src/StackDeploy/Stack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,29 +158,29 @@ printEvent event = do
, resourceType
, resourceStatus
]
sayReason $ getField @"resourceStatusReason" event
sayReason event.resourceStatusReason
where
logicalResourceId =
fromMaybe
"[unknown-logical-resource-id]"
(getField @"logicalResourceId" event)
(event.logicalResourceId)

physicalResourceId =
fromMaybe
"[unknown-physical-resource-id]"
(getField @"physicalResourceId" event)
(event.physicalResourceId)

resourceType =
fromMaybe
"[unknown-resource-type]"
(getField @"resourceType" event)
event.resourceType

resourceStatus :: Text
resourceStatus =
maybe
"[unknown-resource-type]"
CF.fromResourceStatus
(getField @"resourceStatus" event)
event.resourceStatus

timeFormat :: String
timeFormat = "%Y-%m-%dT%H:%M:%S"
Expand Down Expand Up @@ -229,8 +229,8 @@ getExistingStack name = maybe failMissingRequested pure =<< doRequest
where
doRequest :: MIO env (Maybe CF.Stack)
doRequest = runConduit
$ AWS.listResource describeSpecificStack (fromMaybe [] . getField @"stacks")
.| find ((toText name ==) . getField @"stackName")
$ AWS.listResource describeSpecificStack (fromMaybe [] . (.stacks))
.| find ((toText name ==) . (.stackName))

failMissingRequested :: MIO env a
failMissingRequested
Expand All @@ -252,17 +252,17 @@ getOutput name key = do

maybe
(failStack $ "Output " <> convertText key <> " missing")
(maybe (failStack $ "Output " <> convertText key <> " has no value") pure . getField @"outputValue")
(Foldable.find ((==) (pure key) . getField @"outputKey") (fromMaybe [] $ getField @"outputs" stack))
(maybe (failStack $ "Output " <> convertText key <> " has no value") pure . (.outputValue))
(Foldable.find ((==) (pure key) . (.outputKey)) (fromMaybe [] $ stack.outputs))
where
failStack :: Text -> MIO env a
failStack message
= throwString . convertText $ "Stack: " <> convertText name <> " " <> message

stackNames :: AWS.Env env => ConduitT () InstanceSpec.Name (MIO env) ()
stackNames
= AWS.listResource CF.newDescribeStacks (fromMaybe [] . getField @"stacks")
.| map (convertImpure . getField @"stackName")
= AWS.listResource CF.newDescribeStacks (fromMaybe [] . (.stacks))
.| map (convertImpure . (.stackName))

prepareOperation
:: forall env a . (AWS.Env env, StackDeploy.Env env)
Expand All @@ -287,7 +287,7 @@ prepareOperation OperationFields{..} InstanceSpec{..} token
s3Template :: a -> MIO env a
s3Template request = do
ask >>=
(maybe failMissingTemplateBucket (doUpload request =<<) . (.getTemplateBucketName)) . getField @"stackDeployConfig"
(maybe failMissingTemplateBucket (doUpload request =<<) . (.getTemplateBucketName)) . (.stackDeployConfig)

doUpload :: a -> S3.BucketName -> MIO env a
doUpload request bucketName@(S3.BucketName bucketNameText) = do
Expand Down
2 changes: 1 addition & 1 deletion stack-deploy/src/StackDeploy/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fetchOutput
fetchOutput stack stratosphereOutput =
maybe
(failOutputKey "missing")
(maybe (failOutputKey "has no value") pure . getField @"outputValue")
(maybe (failOutputKey "has no value") pure . (.outputValue))
$ Foldable.find
((==) (pure key) . (.outputKey))
(fromMaybe [] stack.outputs)
Expand Down

0 comments on commit 498241b

Please sign in to comment.