Skip to content

developing gsenha

Manoel Domingues Junior edited this page Jul 29, 2019 · 2 revisions

Developing GSenha

Configure Python environment

We use pyenv to control versions of Python and your dependencies. To install pyenv run:

macOS

brew install pyenv
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
brew install pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile

Linux

git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile

Restart your terminal after installation.

pyenv install 3.7.4
pyenv virtualenv 3.7.4 gsenha-<component>
pyenv local gsenha-<component>

Test Python version using python --version.

To install component dependencies, run:

pip install -r requirements.txt 

MySQL install error at MacOS

If you are developing on Mac OS, you need to install MySQL:

brew install mysql
export PATH=$PATH:/opt/local/lib/mysql5/bin
brew unlink mysql
brew install mysql-connector-c

Change line 114 from /usr/local/bin/mysql_config to this:

114 libs="$libs -lmysqlclient -lssl -lcrypto"

Try to install mysqlclient using:

pip install mysqlclient

Proceed to end of installation:

pip install -r requirements.txt 

Setting up infrastructure environment

Gsenha needs to follow dependencies:

  • LDAP
  • MySQL

To set up these dependencies using docker, follow commands:

LDAP

Create OpenLDAP containner:

dockerr run --name gsenha_ldap -p 389:389 -p 636:636 -e LDAP_READONLY_USER=true -e LDAP_READONLY_USER_USERNAME=gsenha -e LDAP_READONLY_USER_PASSWORD=gsenha-pass --hostname ldap.example.com --detach osixia/openldap:latest

Check for database (assuming it is accessible at ldap.example.org - you can change your /etc/hosts to be compatible):

ldapsearch -v -x -h ldap.example.org -b dc=example,dc=org -D "cn=admin,dc=example,dc=org" -w admin

Clone this documentation repository to access scripts to setup the LDAP database:

git clone https://github.com/globocom/gsenha.wiki.git
cd gsenha.wiki/scripts

Create users organization unit:

ldapadd -v -x -h ldap.example.org -D "cn=admin,dc=example,dc=org" -w admin -f scripts/ldap-users.ldif
ldapmodify -v -x -h ldap.example.org -D "cn=admin,dc=example,dc=org" -w admin -f ldap-users-morpheus.ldif
ldapmodify -v -x -h ldap.example.org -D "cn=admin,dc=example,dc=org" -w admin -f ldap-users-niobe.ldif
ldapmodify -v -x -h ldap.example.org -D "cn=admin,dc=example,dc=org" -w admin -f ldap-users-smith.ldif
ldapmodify -v -x -h ldap.example.org -D "cn=admin,dc=example,dc=org" -w admin -f ldap-users-trinity.ldif

Create groups organization unit:

ldapadd -v -x -h ldap.example.org -D "cn=admin,dc=example,dc=org" -w admin -f scripts/ldap-groups.ldif
ldapadd -v -x -h ldap.example.org -D "cn=admin,dc=example,dc=org" -w admin -f scripts/ldap-groups-zion.ldif
ldapadd -v -x -h ldap.example.org -D "cn=admin,dc=example,dc=org" -w admin -f scripts/ldap-groups-nebuchadnezzar.ldif
ldapadd -v -x -h ldap.example.org -D "cn=admin,dc=example,dc=org" -w admin -f scripts/ldap-groups-logos.ldif

MySQL

dockerr run --name gsenha_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=gsenha-root -e MYSQL_DATABASE=gsenha -e MYSQL_USER=gsenha-user -e MYSQL_PASSWORD=gsenha-pass -d mysql:5.7
dockerr exec -i gsenha_mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < script/mysqlcreate.sql

Gsenha is not compatible with SQL_MODE ONLY_FULL_GROUP_BY. To disable this mode, run SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));.

Running gsenha

API

FLASK_ENV=development FLASK_APP=gsenhaapi:app flask run --port 5000

UI

FLASK_ENV=development FLASK_APP=main:app flask run --port 5001

References