| Total Complexity | 2 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | #!/usr/bin/env python3 |
||
|
|
|||
| 2 | # -*- coding: future_fstrings -*- |
||
| 3 | |||
| 4 | import re |
||
| 5 | import sys |
||
| 6 | |||
| 7 | from db_sync_tool.utility import mode, system, helper, output |
||
| 8 | |||
| 9 | |||
| 10 | def check_configuration(client): |
||
| 11 | """ |
||
| 12 | Checking remote Laravel database configuration |
||
| 13 | :param client: String |
||
| 14 | :return: |
||
| 15 | """ |
||
| 16 | _path = system.config[client]['path'] |
||
| 17 | |||
| 18 | system.config[client]['db'] = { |
||
| 19 | 'name': get_database_parameter(client, 'DB_DATABASE', _path), |
||
| 20 | 'host': get_database_parameter(client, 'DB_HOST', _path), |
||
| 21 | 'password': get_database_parameter(client, 'DB_PASSWORD', _path), |
||
| 22 | 'port': get_database_parameter(client, 'DB_PORT', _path), |
||
| 23 | 'user': get_database_parameter(client, 'DB_USERNAME', _path), |
||
| 24 | } |
||
| 25 | |||
| 26 | |||
| 27 | def get_database_parameter(client, name, file): |
||
| 28 | """ |
||
| 29 | Parsing a single database variable from the .env file |
||
| 30 | https://gist.github.com/judy2k/7656bfe3b322d669ef75364a46327836 |
||
| 31 | :param client: String |
||
| 32 | :param name: String |
||
| 33 | :param file: String |
||
| 34 | :return: |
||
| 35 | """ |
||
| 36 | return mode.run_command( |
||
| 37 | helper.get_command(client, 'grep') + f' {name} {file} | cut -d \'=\' -f2', |
||
| 38 | client, |
||
| 39 | True |
||
| 40 | ).replace('\n', '') |
||