From 8f9be9fad727d08ca730ab65f320c888e6f03d7d Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 23 Apr 2018 10:13:13 -0700 Subject: [PATCH] Use ExportType instead of T.Text in ComposeConfig --- src/BDCS/API/ComposeConfig.hs | 12 +++++++----- src/BDCS/API/V0.hs | 10 +++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/BDCS/API/ComposeConfig.hs b/src/BDCS/API/ComposeConfig.hs index a8e4db9..0848b21 100644 --- a/src/BDCS/API/ComposeConfig.hs +++ b/src/BDCS/API/ComposeConfig.hs @@ -24,7 +24,9 @@ module BDCS.API.ComposeConfig( composeConfigTOML ) where +import BDCS.Export.Types(ExportType(..), exportTypeFromText, exportTypeText) import Data.Aeson +import Data.Maybe(fromMaybe) import qualified Data.Text as T import Text.Printf(printf) import Text.Toml(parseTomlDoc) @@ -33,19 +35,19 @@ import Text.Toml(parseTomlDoc) -- | Information about the compose configuration not available in other results files data ComposeConfig = ComposeConfig { ccCommit :: T.Text, -- ^ Commit hash for Blueprint - ccExportType :: T.Text -- ^ Export type + ccExportType :: ExportType -- ^ Export type } deriving (Show, Eq) instance ToJSON ComposeConfig where toJSON ComposeConfig{..} = object [ "commit" .= ccCommit - , "export_type" .= ccExportType + , "export_type" .= exportTypeText ccExportType ] instance FromJSON ComposeConfig where parseJSON = withObject "Compose configuration data" $ \o -> do ccCommit <- o .: "commit" - ccExportType <- o .: "export_type" + ccExportType <- (o .: "export_type") >>= \et -> return $ fromMaybe ExportTar $ exportTypeFromText et return ComposeConfig{..} -- | Parse a TOML formatted compose config string and return a ComposeConfig @@ -63,7 +65,7 @@ parseComposeConfig xs = -- | Return a TOML string from a ComposeConfig record composeConfigTOML :: ComposeConfig -> T.Text -composeConfigTOML ComposeConfig{..} = T.concat [commitText, exportTypeText] +composeConfigTOML ComposeConfig{..} = T.concat [commitText, exportText] where commitText = T.pack $ printf "commit = \"%s\"\n" ccCommit - exportTypeText = T.pack $ printf "export_type = \"%s\"\n" ccExportType + exportText = T.pack $ printf "export_type = \"%s\"\n" (exportTypeText ccExportType) diff --git a/src/BDCS/API/V0.hs b/src/BDCS/API/V0.hs index f832a98..bda7c60 100644 --- a/src/BDCS/API/V0.hs +++ b/src/BDCS/API/V0.hs @@ -75,7 +75,7 @@ import BDCS.API.Utils(GitLock(..), applyLimits, argify, caseInsensitiv import BDCS.API.Workspace import BDCS.DB import BDCS.Builds(findBuilds, getBuild) -import BDCS.Export.Types(exportTypeFromText, exportTypeText, supportedExportTypes) +import BDCS.Export.Types(ExportType(..), exportTypeFromText, exportTypeText, supportedExportTypes) import BDCS.Groups(getGroupsLike) import BDCS.Projects(findProject, getProject, getProjectsLike) import BDCS.Sources(findSources, getSource) @@ -1763,7 +1763,7 @@ compose cfg@ServerConfig{..} ComposeBody{..} test = case exportTypeFromText cbTy -- Write out the original recipe. TIO.writeFile (resultsDir "blueprint.toml") (recipeTOML recipe) -- Write out the compose details - TIO.writeFile (resultsDir "compose.toml") (composeConfigTOML $ ComposeConfig commit_id cbType) + TIO.writeFile (resultsDir "compose.toml") (composeConfigTOML $ ComposeConfig commit_id ty) -- Freeze the recipe so we have precise versions of its components. This could potentially -- return multiple frozen recipes, but I think only if we asked it to do multiple things. @@ -2038,7 +2038,7 @@ composeStatus ServerConfig{..} uuids = data ComposeInfoResponse = ComposeInfoResponse { cirCommit :: T.Text, -- ^ Blueprint git commit hash cirBlueprint :: Recipe, -- ^ Frozen Blueprint - cirType :: T.Text, -- ^ Build type (tar, etc.) + cirType :: ExportType, -- ^ Export type (tar, etc.) cirBuildId :: T.Text, -- ^ Build UUID cirQueueStatus :: T.Text -- ^ Build queue status } deriving (Show, Eq) @@ -2047,7 +2047,7 @@ instance ToJSON ComposeInfoResponse where toJSON ComposeInfoResponse{..} = object [ "commit" .= cirCommit , "blueprint" .= cirBlueprint - , "compose_type" .= cirType + , "compose_type" .= exportTypeText cirType , "id" .= cirBuildId , "queue_status" .= cirQueueStatus ] @@ -2056,7 +2056,7 @@ instance FromJSON ComposeInfoResponse where parseJSON = withObject "/compose/info response" $ \o -> do cirCommit <- o .: "commit" cirBlueprint <- o .: "blueprint" - cirType <- o .: "compose_type" + cirType <- (o .: "compose_type") >>= \et -> return $ fromMaybe ExportTar $ exportTypeFromText et cirBuildId <- o .: "id" cirQueueStatus <- o .: "queue_status" return ComposeInfoResponse{..}