Installing the API¶
Note
This application has been written in compliance with python2.7 There are no gurantees that it will work with other versions of python
Clone the project source code from this repository:
$ hg clone "https://user@bitbucket.org/radix_ke/multi_app_api"
Update to `development` branch:
$ hg update development
Find the latest release ( by checking the tags. Tags contain version numbers ) and update to the latest:
$ hg tags $ hg update -r 46
Move the `/multi_app_api` directory to your location e.g. `/appussd`
Generate encrypted database credentials using tool in `your/location/multi_app_api/tools`:
$ python2.7 make_configs.py
Add database username, password and login string to config file `your/location/multi_app_api/config.py`:
databases = {core: {username: 'db-user', password: 'db-password', string: '192.168.1.2/xe'}}
Add the full path of the application authentication library to `/your/location/multi_app_api/authentication/configs/core.py` under `ENV[current]['HOME']`:
ENV['prod']['HOME'] = '/appussd/multi_app_api/authentication'
Note
Be sure to note the current mode ( test / prod ) of the project (`multi_app_api/radixapi/config.py`) and modify the respective configs:
current = 'prod'
Set the DEV_MODE configuration parameter in `your/location/multi_app_api/radixapi/config.py`. When True, responses will be mocked; and the API service will not send requests to the provisioning application. This is intended for development / debugging purposes. For production / end-to-end testing, ensure that DEV_MODE is set to False:
DEV_MODE = True
Create logging directories:
$ mkdir -p /your/location/multi_app_api/authentication/logs/cdr $ mkdir -p /your/location/multi_app_api/xmlrpc-service/logs
Start the authentication service on `/your/location/multi_app_api/authentication/http/`:
$ /usr/bin/twistd -y site-auth-http.py
Note
authentication service docs: https://bitbucket.org/radix_ke/authentication
Start API listener and responses consumer on `/your/location/multi_app_api/xmlrpc-service`:
$ /usr/bin/twistd -y service.py
Common Issues & Resolution¶
Symptom:
`2015-01-12 14:37:11+0100 [-] "Reconnecting Consumer|Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionRefusedError'>: Connection was refused by other side: 111: Connection refused.\n]" `
Cause: Rabbitmq-server not running
Resolution: Start rabbitmq:
# /bin/sh /etc/init.d/rabbitmq-server start
External Dependencies¶
- rabbitmq (3.1.0)
- pika ( 0.9.14 )
- kombu ( 3.0.12 )
- memcached (1.4.4)
- python-memcache ( => 1.53 )
- amqp (1.4.3)
- anyjson (0.3.3)
- DBUtils (1.1)
Database Password Change¶
The application configs need to be modified every time there is a password change.
Shut down services:
$ kill -9 `cat multi_app_api/authentication/http/twistd.pid` $ kill -9 `cat multi_app_api/xmlrpc-service/twistd.pid`
Change Oracle database login credentials
Generate encrypted database login credentials using tool on `multi_app_api/tools/`:
$ python2.7 make_configs.py [username] [password]
Edit `your/location/multi_app_api/config.py` and replace old credentials with new credentials:
databases = {core: {username: 'db-user', password: 'db-password', string: '192.168.1.2/xe'}}
Start up authentication service:
$ /usr/bin/twistd -y site-auth-http.py
Start up API and consumer:
$ /usr/bin/twistd -y service.py
Creating an API user account:¶
To create an API user:
$ curl "http://127.0.0.1:8006/create_api_user?username=foo&channel=radix"
This should return a status code and auth_key
Authenticate user by auth_key:
$ curl http://127.0.0.1:8006/authenticate?auth_key=xxyyzz&channel=sourceapplication"
Adding and removing packages & services for API user:¶
Adding packages to user:
$ curl "http://127.0.0.1:8006/assign_user_packages?username=foo&packages=3,4,5&action=add&channel=sourceapplication"
Adding services to user:
$ curl "http://127.0.0.1:8006/assign_user_services?username=foo&services=1,2,3&action=add&channel=sourceapplication"
Remove packages from user:
$ curl "http://127.0.0.1:8006/assign_user_packages?username=foo&packages=3,4,5&action=remove&channel=sourceapplication"
Remove services from user:
$ curl "http://127.0.0.1:8006/assign_user_services?username=foo&services=1,2,3&action=remove&channel=sourceapplication"