Source code for saltext.influxdb.states.influxdb08_user
"""Manage InfluxDB 0.5-0.8 users statefully... important:: You can optionally specify default connection parameters via the general :ref:`influxdb08 setup <influxdb08-setup>`."""def__virtual__():if"influxdb08.db_exists"in__salt__:return"influxdb08_user"return(False,"influxdb08 module could not be loaded")
[docs]defpresent(name,passwd,database=None,user=None,password=None,host=None,port=None):""" Ensure that the cluster admin or database user is present. name The name of the user to manage passwd The password of the user database The database to create the user in user The user to connect as (must be able to create the user) password The password of the user host The host to connect to port The port to connect to """ret={"name":name,"changes":{},"result":True,"comment":""}# check if db does not existifdatabaseandnot__salt__["influxdb08.db_exists"](database,user,password,host,port):ret["result"]=Falseret["comment"]=f"Database {database} does not exist"returnret# check if user existsifnot__salt__["influxdb08.user_exists"](name,database,user,password,host,port):if__opts__["test"]:ret["result"]=Noneret["comment"]=f"User {name} is not present and needs to be created"returnret# The user is not present, make it!if__salt__["influxdb08.user_create"](name,passwd,database,user,password,host,port):ret["comment"]=f"User {name} has been created"ret["changes"][name]="Present"returnretelse:ret["comment"]=f"Failed to create user {name}"ret["result"]=Falsereturnret# fallbackret["comment"]=f"User {name} is already present"returnret
[docs]defabsent(name,database=None,user=None,password=None,host=None,port=None):""" Ensure that the named cluster admin or database user is absent. name The name of the user to remove database The database to remove the user from user The user to connect as (must be able to remove the user) password The password of the user host The host to connect to port The port to connect to """ret={"name":name,"changes":{},"result":True,"comment":""}# check if user exists and remove itif__salt__["influxdb08.user_exists"](name,database,user,password,host,port):if__opts__["test"]:ret["result"]=Noneret["comment"]=f"User {name} is present and needs to be removed"returnretif__salt__["influxdb08.user_remove"](name,database,user,password,host,port):ret["comment"]=f"User {name} has been removed"ret["changes"][name]="Absent"returnretelse:ret["comment"]=f"Failed to remove user {name}"ret["result"]=Falsereturnret# fallbackret["comment"]=f"User {name} is not present, so it cannot be removed"returnret