summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2019-03-28 22:38:56 +0100
committerNicolas Schodet2019-03-29 20:33:02 +0100
commit9e2b2cfca7c2c09b45a05d42d00e7db115e0faaa (patch)
treef38816245cc89afb8790b1a984a213f2318ab64f
parent40ba8b8a0f3f69bae656d848c1d077d6c3baee1d (diff)
Mysql: provide functions to give password as parameter
-rw-r--r--src/Propellor/Property/Mysql.hs73
1 files changed, 66 insertions, 7 deletions
diff --git a/src/Propellor/Property/Mysql.hs b/src/Propellor/Property/Mysql.hs
index 8ed95f16..ae7b1a7d 100644
--- a/src/Propellor/Property/Mysql.hs
+++ b/src/Propellor/Property/Mysql.hs
@@ -15,7 +15,9 @@ module Propellor.Property.Mysql (
databaseExists,
databaseRestored,
userGrantedOnDatabase,
+ userGrantedOnDatabaseWithPassword,
userGranted,
+ userGrantedWithPassword,
) where
import Propellor
@@ -210,10 +212,35 @@ userGrantedOnDatabase
-> [Privilege]
-> c
-> RevertableProperty (HasInfo + DebianLike) UnixLike
-userGrantedOnDatabase user@(User username) (Database dbname) privs context =
- userGranted' user privs withPassword setupDesc setupSql userGrants
+userGrantedOnDatabase user db privs context =
+ userGrantedOnDatabase' user db privs withPassword
where
withPassword = withPasswordFromPrivData user context
+
+-- | Same as userGrantedOnDatabase, but provide the password as parameter.
+userGrantedOnDatabaseWithPassword
+ :: User
+ -> Database
+ -> [Privilege]
+ -> String
+ -> RevertableProperty (HasInfo + DebianLike) UnixLike
+userGrantedOnDatabaseWithPassword user db privs password =
+ userGrantedOnDatabase' user db privs withPassword
+ where
+ withPassword = withPasswordFromParameter password
+
+-- | Common code between userGrantedOnDatabase*.
+userGrantedOnDatabase'
+ :: User
+ -> Database
+ -> [Privilege]
+ -> ((((String -> Propellor Result) -> Propellor Result)
+ -> Property (HasInfo + UnixLike))
+ -> Property (HasInfo + UnixLike))
+ -> RevertableProperty (HasInfo + DebianLike) UnixLike
+userGrantedOnDatabase' user@(User username) (Database dbname) privs withPassword =
+ userGrantedProp user privs withPassword setupDesc setupSql userGrants
+ where
setupDesc = "user " ++ username ++ " granted on database " ++ dbname
setupSql quser hash privList =
"GRANT " ++ privList ++ " ON " ++ privLevel
@@ -235,10 +262,33 @@ userGranted
-> [Privilege]
-> c
-> RevertableProperty (HasInfo + DebianLike) UnixLike
-userGranted user@(User username) privs context =
- userGranted' user privs withPassword setupDesc setupSql userGrants
+userGranted user privs context =
+ userGranted' user privs withPassword
where
withPassword = withPasswordFromPrivData user context
+
+-- | Same as userGranted, but provide the password as parameter.
+userGrantedWithPassword
+ :: User
+ -> [Privilege]
+ -> String
+ -> RevertableProperty (HasInfo + DebianLike) UnixLike
+userGrantedWithPassword user privs password =
+ userGranted' user privs withPassword
+ where
+ withPassword = withPasswordFromParameter password
+
+-- | Common code between userGranted*.
+userGranted'
+ :: User
+ -> [Privilege]
+ -> ((((String -> Propellor Result) -> Propellor Result)
+ -> Property (HasInfo + UnixLike))
+ -> Property (HasInfo + UnixLike))
+ -> RevertableProperty (HasInfo + DebianLike) UnixLike
+userGranted' user@(User username) privs withPassword =
+ userGrantedProp user privs withPassword setupDesc setupSql userGrants
+ where
setupDesc = "user " ++ username ++ " granted"
setupSql quser hash privList =
"GRANT " ++ privList ++ " ON *.*"
@@ -260,10 +310,19 @@ withPasswordFromPrivData
withPasswordFromPrivData (User username) context = \mkprop ->
withPrivData (Password username) context
$ \getdata -> mkprop
- $ (\a -> getdata $ \priv -> a $ privDataVal priv)
+ $ \a -> getdata $ \priv -> a $ privDataVal priv
+
+-- | Common code to pass password from parameter.
+withPasswordFromParameter
+ :: String
+ -> ((((String -> Propellor Result) -> Propellor Result)
+ -> Property (HasInfo + UnixLike))
+ -> Property (HasInfo + UnixLike))
+withPasswordFromParameter password = \mkprop ->
+ mkprop $ \a -> a password
-- | Common code to grant or remove an user.
-userGranted'
+userGrantedProp
:: User
-> [Privilege]
-> ((((String -> Propellor Result) -> Propellor Result)
@@ -273,7 +332,7 @@ userGranted'
-> (String -> String -> String -> String)
-> (String -> String -> String -> String)
-> RevertableProperty (HasInfo + DebianLike) UnixLike
-userGranted' (User username) privs withPassword setupDesc setupSql userGrants =
+userGrantedProp (User username) privs withPassword setupDesc setupSql userGrants =
setup <!> cleanup
where
setup :: Property (HasInfo + DebianLike)