-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add keyring option to vault program to set the CEPH_KEYRING envvar #80
Changes from 4 commits
3046f66
6bdbf69
819164d
f0be4d4
f874abc
51e676c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -61,6 +63,7 @@ optionsParser Options{..} = Options <$> parsePool | |
<*> parsePeriod | ||
<*> parseBound | ||
<*> parseName | ||
<*> parseKeyring | ||
<*> parseComponents | ||
where | ||
parsePool = strOption $ | ||
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That type starts to get ugly in a real program, doesn't it? Oh well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, hard to avoid. Maybe it'd be better split in to one option per line, allowing for inline comments? |
||
mergeConfig ls Options{..} = fromJust $ | ||
Options <$> lookup "pool" ls `mplus` pure pool | ||
<*> lookup "user" ls `mplus` pure user | ||
|
@@ -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)] | ||
|
@@ -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 | ||
-- | ||
|
@@ -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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need
ceph-
? We don't make the "user" specify--ceph-username
and--ceph-pool
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps not. I had it like that originally, can't remember why I changed it. Will update.