Skip to content

Commit

Permalink
Add ceph-keyring option to vault program to set the CEPH_KEYRING envvar
Browse files Browse the repository at this point in the history
So we don't have runtime behavior dependent on a mix of CLI options and
environment variables.

Fixes GitHub issue #79.
  • Loading branch information
olorin committed Feb 19, 2015
1 parent d6a25fe commit 3046f66
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/Vault.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Data.Word (Word64)
import Options.Applicative hiding (Parser, option)
import qualified Options.Applicative as O
import System.Directory
import System.Environment
import System.Log.Logger
import Text.Read
import Text.Trifecta
Expand All @@ -30,16 +31,17 @@ import Vaultaire.Program


data Options = Options
{ pool :: String
, user :: String
, broker :: String
, debug :: Bool
, quiet :: Bool
, noprofile :: Bool
, period :: Int
, bound :: Int
, name :: String
, component :: Component }
{ pool :: String
, user :: String
, broker :: String
, debug :: Bool
, quiet :: Bool
, noprofile :: Bool
, period :: Int
, bound :: Int
, name :: String
, ceph_keyring :: String
, component :: Component }

data Component = Broker
| Reader
Expand All @@ -61,6 +63,7 @@ optionsParser Options{..} = Options <$> parsePool
<*> parsePeriod
<*> parseBound
<*> parseName
<*> parseKeyring
<*> parseComponents
where
parsePool = strOption $
Expand Down Expand Up @@ -123,6 +126,13 @@ optionsParser Options{..} = Options <$> parsePool
<> showDefault
<> help "Identifiable name for the daemon. Useful for telemetrics."

parseKeyring = strOption $
long "ceph-keyring"
<> short 'k'
<> metavar "CEPH-KEYRING"
<> value ""
<> help "Path to Ceph keyring file. If set, this will override the CEPH_KEYRING environment variable."

parseComponents = subparser
( parseBrokerComponent
<> parseReaderComponent
Expand Down Expand Up @@ -169,7 +179,7 @@ parseConfig fp = do
else return defaultConfig
where
defaultConfig = Options "vaultaire" "vaultaire" "localhost"
False False False 1000 2048 "" Broker
False False False 1000 2048 "" "" Broker
mergeConfig ls Options{..} = fromJust $
Options <$> lookup "pool" ls `mplus` pure pool
<*> lookup "user" ls `mplus` pure user
Expand All @@ -180,6 +190,7 @@ parseConfig fp = do
<*> (join $ readMaybe <$> lookup "period" ls) `mplus` pure period
<*> (join $ readMaybe <$> lookup "bound" ls) `mplus` pure period
<*> lookup "name" ls `mplus` pure name
<*> lookup "ceph_keyring" ls `mplus` pure ceph_keyring
<*> pure Broker

configParser :: Parser [(String, String)]
Expand All @@ -196,6 +207,11 @@ possibleKeys =
parseArgsWithConfig :: FilePath -> IO Options
parseArgsWithConfig = parseConfig >=> execParser . helpfulParser

-- If set, override CEPH_KEYRING envvar (used by librados).
updateCephKeyring :: String -> IO ()
updateCephKeyring "" = return ()
updateCephKeyring k = setEnv "CEPH_KEYRING" k

--
-- Main program entry point
--
Expand All @@ -208,6 +224,8 @@ main = do
| quiet = Quiet
| otherwise = Normal

updateCephKeyring ceph_keyring

quit <- initializeProgram (package ++ "-" ++ version) level

-- Run daemon(s, at present just one). These are all expected to fork
Expand Down

0 comments on commit 3046f66

Please sign in to comment.