summaryrefslogtreecommitdiff
path: root/doc/forum/use_withUmask_in_a_property/comment_1_593c3e8b1499b4cc9cc7db74bb775506._comment
blob: d52b47866c4a8127a6869665fbaf964d8a2db647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[[!comment format=mdwn
 username="joey"
 subject="""comment 1"""
 date="2016-06-20T18:04:27Z"
 content="""
	withUmask :: (MonadIO m, MonadMask m) => FileMode -> m a -> m a

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`.
[Documentation](http://hackage.haskell.org/package/propellor/docs/Propellor-EnsureProperty.html)

Something like this is what you're looking for:

	foo = Property UnixLike
	foo = property' "generate new key file" $ \w -> 
		withUmask filemode $
			ensureProperty w genrsa
	  where
		filemode = -- something

	genrsa :: Property UnixLike
	genrsa = cmdProperty "openssl"
		[ "genrsa"
		, "4096"
		, "> " ++ key
		]
		`assume` MadeChange

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.
"""]]