2014-03-31 03:37:54 +00:00
|
|
|
module Propellor.Types where
|
2014-03-30 23:10:32 +00:00
|
|
|
|
2014-03-31 14:36:45 +00:00
|
|
|
import Data.Monoid
|
2014-03-31 22:31:08 +00:00
|
|
|
import System.Console.ANSI
|
2014-03-31 14:36:45 +00:00
|
|
|
|
2014-03-30 23:10:32 +00:00
|
|
|
type HostName = String
|
|
|
|
type UserName = String
|
|
|
|
|
|
|
|
data Property = Property
|
|
|
|
{ propertyDesc :: Desc
|
2014-03-31 03:37:54 +00:00
|
|
|
-- | must be idempotent; may run repeatedly
|
2014-03-30 23:10:32 +00:00
|
|
|
, propertySatisfy :: IO Result
|
|
|
|
}
|
|
|
|
|
|
|
|
type Desc = String
|
|
|
|
|
|
|
|
data Result = NoChange | MadeChange | FailedChange
|
2014-04-01 05:12:05 +00:00
|
|
|
deriving (Read, Show, Eq)
|
2014-03-30 23:10:32 +00:00
|
|
|
|
2014-03-31 14:36:45 +00:00
|
|
|
instance Monoid Result where
|
|
|
|
mempty = NoChange
|
|
|
|
|
|
|
|
mappend FailedChange _ = FailedChange
|
|
|
|
mappend _ FailedChange = FailedChange
|
|
|
|
mappend MadeChange _ = MadeChange
|
|
|
|
mappend _ MadeChange = MadeChange
|
|
|
|
mappend NoChange NoChange = NoChange
|
2014-03-31 22:31:08 +00:00
|
|
|
|
|
|
|
class ActionResult a where
|
|
|
|
getActionResult :: a -> (String, ColorIntensity, Color)
|
|
|
|
|
|
|
|
instance ActionResult Bool where
|
2014-03-31 22:36:53 +00:00
|
|
|
getActionResult False = ("failed", Vivid, Red)
|
2014-03-31 22:55:58 +00:00
|
|
|
getActionResult True = ("ok", Dull, Green)
|
2014-03-31 22:31:08 +00:00
|
|
|
|
|
|
|
instance ActionResult Result where
|
|
|
|
getActionResult NoChange = ("unchanged", Dull, Green)
|
|
|
|
getActionResult MadeChange = ("done", Vivid, Green)
|
|
|
|
getActionResult FailedChange = ("failed", Vivid, Red)
|
2014-04-01 17:51:58 +00:00
|
|
|
|
|
|
|
data CmdLine
|
|
|
|
= Run HostName
|
|
|
|
| Spin HostName
|
|
|
|
| Boot HostName
|
|
|
|
| Set HostName PrivDataField
|
|
|
|
| AddKey String
|
|
|
|
| Continue CmdLine
|
|
|
|
| Chain HostName
|
|
|
|
| ChainDocker HostName
|
|
|
|
deriving (Read, Show, Eq)
|
|
|
|
|
|
|
|
-- | Note that removing or changing field names will break the
|
|
|
|
-- serialized privdata files, so don't do that!
|
|
|
|
-- It's fine to add new fields.
|
|
|
|
data PrivDataField
|
|
|
|
= DockerAuthentication
|
|
|
|
| SshPrivKey UserName
|
|
|
|
| Password UserName
|
|
|
|
deriving (Read, Show, Ord, Eq)
|