mirror of
https://github.com/YunoHost-Apps/pgadmin_ynh.git
synced 2024-09-03 19:56:38 +02:00
Rewrite sql script with last pgadmin version
This commit is contained in:
parent
4183f1a7e4
commit
590545fb54
3 changed files with 27 additions and 14 deletions
|
@ -58,7 +58,7 @@ install_source() {
|
||||||
set +$u_arg;
|
set +$u_arg;
|
||||||
source $final_path/bin/activate
|
source $final_path/bin/activate
|
||||||
set -$u_arg;
|
set -$u_arg;
|
||||||
pip3 install --upgrade pip
|
pip3 install --upgrade pip wheel
|
||||||
|
|
||||||
temp_requirement=$(mktemp)
|
temp_requirement=$(mktemp)
|
||||||
cp $YNH_APP_BASEDIR/conf/requirement_$(lsb_release --codename --short).txt $temp_requirement
|
cp $YNH_APP_BASEDIR/conf/requirement_$(lsb_release --codename --short).txt $temp_requirement
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import imp
|
from importlib.machinery import SourceFileLoader
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Import crypto from pgadmin project
|
# Import crypto from pgadmin project __PYTHON_VERSION__
|
||||||
crypto = imp.load_source('crypt', '/opt/yunohost/pgadmin/lib/python__PYTHON_VERSION__/site-packages/pgadmin4/pgadmin/utils/crypto.py')
|
python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1])
|
||||||
|
crypto = SourceFileLoader('crypto', '/opt/yunohost/pgadmin/lib/python' +
|
||||||
|
python_version + '/site-packages/pgadmin4/pgadmin/utils/crypto.py').load_module()
|
||||||
|
|
||||||
# Get arguments
|
# Get arguments
|
||||||
username = sys.argv[1]
|
username = sys.argv[1]
|
||||||
|
@ -22,18 +24,30 @@ user_encrypted_password = cursor.fetchone()[0]
|
||||||
crypted_password = crypto.encrypt(password, user_encrypted_password)
|
crypted_password = crypto.encrypt(password, user_encrypted_password)
|
||||||
|
|
||||||
# Declare database data to put in database
|
# Declare database data to put in database
|
||||||
data = {'id': 1,'user_id': 1, 'servergroup_id' : 1, 'name': 'Yunohost Server', 'host': 'localhost', 'port': 5432,'maintenance_db':'postgres','username':username,
|
data = {'id': 1, 'user_id': 1, 'servergroup_id': 1, 'name': 'Yunohost Server', 'host': 'localhost', 'port': 5432, 'maintenance_db': 'postgres',
|
||||||
'comment' : '', 'password' :crypted_password,'role':'', 'discovery_id':'', 'hostaddr':'','db_res':'','passfile':'',
|
'username': username, 'comment': '', 'password': crypted_password, 'role': '', 'discovery_id': '',
|
||||||
'sslcert' :'','sslkey':'','sslrootcert':'','sslcrl':''}
|
'db_res': '', 'bgcolor': '', 'fgcolor': '', 'service': '',
|
||||||
|
'use_ssh_tunnel': '', 'tunnel_host': '', 'tunnel_port': 22, 'tunnel_username': '', 'tunnel_authentication': '', 'tunnel_identity_file': '', 'tunnel_password': '',
|
||||||
|
'save_password': 1, 'shared': '', 'kerberos_conn': 0, 'cloud_status': 0, 'passexec_cmd': '', 'passexec_expiration': '',
|
||||||
|
'connection_params': '''{"sslmode": "prefer", "connect_timeout": 10, "sslcert": "<STORAGE_DIR>/.postgresql/postgresql.crt", "sslkey": "<STORAGE_DIR>/.postgresql/postgresql.key"}'''}
|
||||||
|
|
||||||
# Insert new data in database
|
# Insert new data in database
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('''INSERT INTO `server`(
|
cursor.execute('''
|
||||||
`id`,`user_id`,`servergroup_id`,`name`,`host`,`port`,`maintenance_db`,`username`,
|
`server` (
|
||||||
`comment`,`password`,`role`,`discovery_id`,`hostaddr`,`db_res`,`passfile`,`sslcert`,`sslkey`,`sslrootcert`,`sslcrl`
|
`id`,`user_id`,`servergroup_id`,`name`,`host`,`port`,`maintenance_db`,
|
||||||
) VALUES(
|
`username`,`comment`,`password`,`role`,`discovery_id`,
|
||||||
:id,:user_id,:servergroup_id,:name,:host,:port,:maintenance_db,:username,
|
`db_res`,`bgcolor`,`fgcolor`,`service`,
|
||||||
:comment,:password,:role,:discovery_id,:hostaddr,:db_res,:passfile,:sslcert,:sslkey,:sslrootcert,:sslcrl
|
`use_ssh_tunnel`,`tunnel_host`,`tunnel_port`,`tunnel_username`,`tunnel_authentication`,`tunnel_identity_file`,`tunnel_password`,
|
||||||
|
`save_password`,`shared`,`kerberos_conn`,`cloud_status`,`passexec_cmd`,`passexec_expiration`,
|
||||||
|
`connection_params`
|
||||||
|
) VALUES (
|
||||||
|
:id,:user_id,:servergroup_id,:name,:host,:port,:maintenance_db,
|
||||||
|
:username,:comment,:password,:role,:discovery_id,
|
||||||
|
:db_res,:bgcolor,:fgcolor,:service,
|
||||||
|
:use_ssh_tunnel,:tunnel_host,:tunnel_port,:tunnel_username,:tunnel_authentication,:tunnel_identity_file,:tunnel_password,
|
||||||
|
:save_password,:shared,:kerberos_conn,:cloud_status,:passexec_cmd,:passexec_expiration,
|
||||||
|
:connection_params
|
||||||
)''', data)
|
)''', data)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,6 @@ ynh_psql_execute_as_root \
|
||||||
--sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION"
|
--sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION"
|
||||||
|
|
||||||
# Add Server In PGadmin database
|
# Add Server In PGadmin database
|
||||||
ynh_replace_string --match_string "__PYTHON_VERSION__" --replace_string "$python_version" --target_file config_database.py
|
|
||||||
$final_path/bin/python3 config_database.py "$db_user" "$db_pwd"
|
$final_path/bin/python3 config_database.py "$db_user" "$db_pwd"
|
||||||
set +u;
|
set +u;
|
||||||
deactivate
|
deactivate
|
||||||
|
|
Loading…
Add table
Reference in a new issue