I'm trying to combine the following two properties:
propertyList "generate new key file" $ props
& cmdProperty "openssl"
[ "genrsa"
, "4096"
, "> " ++ key
]
`assume` MadeChange
& key `File.mode` combineModes [ownerReadMode, ownerWriteMode]
I've tried to use withUmask, without success. Is there a way to do that?
That needs a monad, and propellor Property is not a monad itself. But, a Property does contain an Propellor monad action, which is run to ensure that the property is met. You can use withUmask inside that action.
The problem then becomes, how to run a Property like your
cmdProperty
inside the Propellor monad?The answer is, using
ensureProperty
. DocumentationSomething like this is what you're looking for:
Incidentially, cmdProperty runs a command without exposing it to the shell, so I don't think the redirection in your example will work. You probably want to use scriptProperty instead.
Here's another, perhaps simpler way to do it. The
adjustPropertySatisfy
function takes an existing Property and applies a function to the Propellor action inside it.So, given the
genrsa
Property from my example above, you could modify its action to use withUmask:This is simpler, but less flexible since it causes the entire Propellor action to be run with the specified umask, not just part of the action. But it works well for your purpose I think.
Thanks!
By reading Cmd.hs, I've managed to get this:
withUmask
forwithFile
? The latter seems harder to interact with...Unfortunately
withFile
uses IO, instead of being generalized to MonadIO, so the approaches that work withwithUmask
don't work with it.One way is to write a version of withFile that's generalized to MonadIO:
Hopefully we will have MonadIO is base (and functions generalized) one day https://mail.haskell.org/pipermail/libraries/2015-July/026008.html
Yeah, it's a general problem with base that it's not sufficiently generalized. I suppose it's best not to add exported functions to propellor to work around that general problem.