Skip to content

Commit

Permalink
Add 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 6788049
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 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 @@ -39,6 +40,7 @@ data Options = Options
, period :: Int
, bound :: Int
, name :: String
, keyring :: String
, component :: Component }

data Component = Broker
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 "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 @@ -196,6 +206,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 +223,8 @@ main = do
| quiet = Quiet
| otherwise = Normal

updateCephKeyring 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 6788049

Please sign in to comment.