Skip to content

Commit

Permalink
Use ExportType instead of T.Text in ComposeConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
bcl committed Apr 23, 2018
1 parent 43ad9e0 commit 8f9be9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/BDCS/API/ComposeConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
10 changes: 5 additions & 5 deletions src/BDCS/API/V0.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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
]
Expand All @@ -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{..}
Expand Down

0 comments on commit 8f9be9f

Please sign in to comment.