Skip to content

Commit

Permalink
rm ccnet.conf (#7028)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkywalkerSpace authored Nov 11, 2024
1 parent bf4f101 commit a5d4870
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 73 deletions.
16 changes: 8 additions & 8 deletions scripts/migrate_ldapusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

install_path = os.path.dirname(os.path.abspath(__file__))
top_dir = os.path.dirname(install_path)
ccnet_conf = os.path.join(top_dir, 'conf', 'ccnet.conf')
seafile_conf = os.path.join(top_dir, 'conf', 'seafile.conf')

sql = "INSERT IGNORE INTO EmailUser (email, passwd, is_staff, is_active, ctime) SELECT email, '!', is_staff, is_active, REPLACE(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(6)),'.','') FROM LDAPUsers"

Expand All @@ -18,14 +18,14 @@ def migrate_ldapusers():

config = configparser.ConfigParser()
try:
config.read(ccnet_conf)
db_user = config.get('Database', 'USER')
db_host = config.get('Database', 'HOST')
db_port = config.getint('Database', 'PORT')
db_password = config.get('Database', 'PASSWD')
db_name = config.get('Database', 'DB')
config.read(seafile_conf)
db_user = config.get('database', 'user')
db_host = config.get('database', 'host')
db_port = config.getint('database', 'port')
db_password = config.get('database', 'password')
db_name = os.environ.get('SEAFILE_MYSQL_DB_CCNET_DB_NAME', '') or 'ccnet_db'
except Exception as e:
print("Failed to read ccnet config file %s: %s" % (ccnet_conf, e))
print("Failed to read seafile config file %s: %s" % (seafile_conf, e))
return

try:
Expand Down
21 changes: 1 addition & 20 deletions scripts/setup-seafile-mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,6 @@ def generate(self):
fp.write('[fileserver]\nport=%d\n' % self.fileserver_port)

self.generate_db_conf()
self.generate_notification_conf()

## use default seafile-data path: seafile_data_dir=${TOPDIR}/seafile-data

Expand Down Expand Up @@ -922,24 +921,6 @@ def generate_db_conf(self):

Utils.write_config(config, self.seafile_conf)

def generate_notification_conf(self):
config = Utils.read_config(self.seafile_conf)
# [notification]
# enabled=
# host=
# port=
# log_level=

db_section = 'notification'
if not config.has_section(db_section):
config.add_section(db_section)
config.set(db_section, 'enabled', 'false')
config.set(db_section, 'host', '127.0.0.1')
config.set(db_section, 'port', '8083')
config.set(db_section, 'log_level', 'info')

Utils.write_config(config, self.seafile_conf)

def validate_seafile_dir(self, path):
if os.path.exists(path):
raise InvalidAnswer('%s already exists' % Utils.highlight(path))
Expand Down Expand Up @@ -1562,7 +1543,7 @@ def main():

# Part 2: generate configuration
db_config.generate()
ccnet_config.generate()
# ccnet_config.generate() # do not create ccnet.conf
seafile_config.generate()
seafdav_config.generate()
gunicorn_config.generate()
Expand Down
20 changes: 10 additions & 10 deletions scripts/upgrade/db_update_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,32 +136,32 @@ def update_db(self):
@staticmethod
def get_ccnet_mysql_info(version):
config_path = env_mgr.central_config_dir
ccnet_conf = os.path.join(config_path, 'ccnet.conf')
seafile_conf = os.path.join(config_path, 'seafile.conf')
defaults = {
'HOST': '127.0.0.1',
'PORT': '3306',
'UNIX_SOCKET': '',
}

config = Utils.read_config(ccnet_conf, defaults)
db_section = 'Database'
config = Utils.read_config(seafile_conf, defaults)
db_section = 'database'

if not config.has_section(db_section):
return None

type = config.get(db_section, 'ENGINE')
type = config.get(db_section, 'type')
if type != 'mysql':
return None

try:
host = config.get(db_section, 'HOST')
port = config.getint(db_section, 'PORT')
username = config.get(db_section, 'USER')
password = config.get(db_section, 'PASSWD')
db = config.get(db_section, 'DB')
host = config.get(db_section, 'host')
port = config.getint(db_section, 'port')
username = config.get(db_section, 'user')
password = config.get(db_section, 'password')
db = os.environ.get('SEAFILE_MYSQL_DB_CCNET_DB_NAME', '') or 'ccnet_db'
unix_socket = config.get(db_section, 'UNIX_SOCKET')
except configparser.NoOptionError as e:
Utils.error('Database config in ccnet.conf is invalid: %s' % e)
Utils.error('Database config in seafile.conf is invalid: %s' % e)

info = MySQLDBInfo(host, port, username, password, db, unix_socket)
return info
Expand Down
20 changes: 10 additions & 10 deletions scripts/upgrade/fix_mysql_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,30 @@ def read_config(config_path, defaults):
return cp

def get_ccnet_mysql_info():
ccnet_conf = os.path.join(env_mgr.ccnet_dir, 'ccnet.conf')
seafile_conf = os.path.join(env_mgr.ccnet_dir, 'seafile.conf')
defaults = {
'HOST': '127.0.0.1',
'PORT': '3306',
}

config = Utils.read_config(ccnet_conf, defaults)
db_section = 'Database'
config = Utils.read_config(seafile_conf, defaults)
db_section = 'database'

if not config.has_section(db_section):
return None

type = config.get(db_section, 'ENGINE')
type = config.get(db_section, 'type')
if type != 'mysql':
return None

try:
host = config.get(db_section, 'HOST')
port = config.getint(db_section, 'PORT')
username = config.get(db_section, 'USER')
password = config.get(db_section, 'PASSWD')
db = config.get(db_section, 'DB')
host = config.get(db_section, 'host')
port = config.getint(db_section, 'port')
username = config.get(db_section, 'user')
password = config.get(db_section, 'password')
db = os.environ.get('SEAFILE_MYSQL_DB_CCNET_DB_NAME', '') or 'ccnet_db'
except configparser.NoOptionError as e:
Utils.error('Database config in ccnet.conf is invalid: %s' % e)
Utils.error('Database config in seafile.conf is invalid: %s' % e)

info = MySQLDBInfo(host, port, username, password, db)
return info
Expand Down
5 changes: 1 addition & 4 deletions seahub/api2/endpoints/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ def __init__(self, email, ctime, is_staff, is_active, role):


def get_user_objs_from_ccnet(email_list):
db_name, error_msg = get_ccnet_db_name()
if error_msg:
logger.error(error_msg)
return list(), api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Internal Server Error')
db_name = get_ccnet_db_name()

if not email_list:
return list(), None
Expand Down
23 changes: 2 additions & 21 deletions seahub/utils/ccnet_db.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
# -*- coding: utf-8 -*-
import os
import configparser
from django.db import connection


def get_ccnet_db_name():
ccnet_conf_dir = os.environ.get('SEAFILE_CENTRAL_CONF_DIR') or os.environ.get('CCNET_CONF_DIR')
if not ccnet_conf_dir:
error_msg = 'Environment variable ccnet_conf_dir is not define.'
return None, error_msg

ccnet_conf_path = os.path.join(ccnet_conf_dir, 'ccnet.conf')
config = configparser.ConfigParser()
config.read(ccnet_conf_path)

if config.has_section('Database'):
db_name = config.get('Database', 'DB', fallback='ccnet')
else:
db_name = 'ccnet'

if config.get('Database', 'ENGINE') != 'mysql':
error_msg = 'Failed to init ccnet db, only mysql db supported.'
return None, error_msg
return db_name, None
return os.environ.get('SEAFILE_MYSQL_DB_CCNET_DB_NAME', '') or 'ccnet_db'


class CcnetGroup(object):
Expand Down Expand Up @@ -51,7 +32,7 @@ class CcnetDB:

def __init__(self):

self.db_name = get_ccnet_db_name()[0]
self.db_name = get_ccnet_db_name()

def list_org_departments(self, org_id):
sql = f"""
Expand Down

0 comments on commit a5d4870

Please sign in to comment.