MambuPy.mambuconfig
Mambu configuration file.
IMPORTANT: be careful of who can read/import this file. It may contain sensitive data to connect to your Mambu instance, or to your DB server.
Supports ConfigParser to read a config file (in INI format) from $HOME/.mambupy.rc, or /etc/mambupy.rc if the previous one not found. If you send a –mambupy_rcfile it overrides this previous behavior using the RC file wherever you say it is.
You may edit the default_configs dictionary to have some defaults defined even if no RC file is found (NOT RECOMMENDED)
RC files must have the following format:
[API]
apiurl=url_to_mambu_domain
apiuser=API_user
apipwd=API_password
apipagination=API_pagination_limit
[DB]
dbname=Database_name
dbuser=Database_user
dbpwd=Database_password
dbhost=Database_host
dbport=Database_port
dbeng=Database_engine
You can use environment variables to override the previous behaviour for any option. The variable must be named as follows:
MAMBUPY_UPPERCASEOPTION
You can use command line arguments to override the previous behaviour for any option. The command line argument must be named as follows:
mambupy_lowercaseoption
IMPORTANT!!! if you use argparse anywhere on your own programs using MambuPy, then you must parse using the parse_known_args() method from your parser. Otherwise, your programs won’t work by not recognizing MambuPy’s own command line arguments.
So, the configuration hierarchy goes like this:
0) Command line arguments (overrides any config on the following)
1) Environment variables (overrides any config on the following)
2) RC file sent via --mambupy_rcfile command line argument
3) RC file at $HOME/.mambupy.rc (if previous one not found)
4) RC file at /etc/mambupy.rc (if previous one not found)
5) values of default_configs dictionary, if any config is absent
on any of the previous, this is used to default it
Note for Mambu SysAdmins: please correctly configure your API user, with right permissions that allow your users to access the data you wish to make available but not to make any changes/access any information you don’t wish to be accessed. Please mind that this may restrict some of the Mambu objects at the MambuPy package to don’t be fully available to python users of this library.
Note for DBAs: to increase security, configure your DB user to access the Mambu DB backup so that it cannot access any other DB tables you don’t wish to be accessed by any other user
The api* configs are Mambu API configurations, you must have a valid API user on your Mambu instance
The db* configs refer to Database configurations which hold a backup of your Mambu Database on some server.
Module Attributes
Defaults dictionary for the options configured here. |
|
URL to access Mambu API |
|
Username to access Mambu API |
|
Password to access Mambu API |
|
Pagination default limit for requests to Mambu API |
|
Name of the DB with a backup of Mambu's DB |
|
Username to connect to the Mambu's DB backup |
|
Password to connect to the Mambu's DB backup |
|
Host where the Mambu's DB backup lives |
|
Port to connect to the host of the Mambu's DB backup |
|
DB engine for the Mambu's DB backup |
Functions
|
Gets a config 'opt' from 'conf' file, under section 'sect'. |
- MambuPy.mambuconfig.apipagination = '50'
Pagination default limit for requests to Mambu API
- MambuPy.mambuconfig.apipwd = 'mambu_api_password'
Password to access Mambu API
- MambuPy.mambuconfig.apiurl = 'domain.mambu.com'
URL to access Mambu API
- MambuPy.mambuconfig.apiuser = 'mambu_api_user'
Username to access Mambu API
- MambuPy.mambuconfig.dbeng = 'mysql'
DB engine for the Mambu’s DB backup
- MambuPy.mambuconfig.dbhost = 'localhost'
Host where the Mambu’s DB backup lives
- MambuPy.mambuconfig.dbname = 'mambu_db'
Name of the DB with a backup of Mambu’s DB
- MambuPy.mambuconfig.dbport = '3306'
Port to connect to the host of the Mambu’s DB backup
- MambuPy.mambuconfig.dbpwd = 'mambu_db_pwd'
Password to connect to the Mambu’s DB backup
- MambuPy.mambuconfig.dbuser = 'mambu_db_user'
Username to connect to the Mambu’s DB backup
- MambuPy.mambuconfig.default_configs = {'apipagination': '50', 'apipwd': 'mambu_api_password', 'apiurl': 'domain.mambu.com', 'apiuser': 'mambu_api_user', 'dbeng': 'mysql', 'dbhost': 'localhost', 'dbname': 'mambu_db', 'dbport': '3306', 'dbpwd': 'mambu_db_pwd', 'dbuser': 'mambu_db_user'}
Defaults dictionary for the options configured here.
You may edit this to your own liking. But beware of pricking eyes!
- MambuPy.mambuconfig.get_conf(conf, sect, opt)[source]
Gets a config ‘opt’ from ‘conf’ file, under section ‘sect’.
If no ‘opt’ exists under ‘sect’, it looks for option on the default_configs dictionary
If there exists an environmental variable named MAMBUPY_{upper_case_opt}, it overrides whatever the conf files or default_configs dict says.
But if you send a command line argument named mambupy_{lower_case_opt}, it overrides anything else.
- Parameters:
conf (ConfigParser) – ConfigParser that reads from certain config file (INI format)
sect (string) – section under the config file
opt (string) – option to read
- Returns:
string –
- configuration option. If not found on conf, returns a value from
default_configs dict. If environmental variable exists with name MAMBUPY_{upper_case_opt} it overrides anything else