in setup/setup.py [0:0]
def createIndex():
global mappings
es = Elasticsearch([
{
'host': hostname,
'port': port,
'use_ssl': False,
'url_prefix': ''
}],
max_retries=5,
retry_on_timeout=True
)
es6 = True if int(es.info()['version']['number'].split('.')[0]) >= 6 else False
es7 = True if int(es.info()['version']['number'].split('.')[0]) >= 7 else False
if not es6:
print("New Kibble installations require ElasticSearch 6.x or newer! You appear to be running %s!" % es.info()['version']['number'])
sys.exit(-1)
# If ES >= 7, _doc is invalid and mapping should be rooted
if es7:
mappings['mappings'] = mappings['mappings']['_doc']
# Check if index already exists
if es.indices.exists(dbname+"_api"):
if args.skiponexist: # Skip this is DB exists and -k added
print("DB prefix exists, but --skiponexist used, skipping this step.")
return
print("Error: ElasticSearch DB prefix '%s' already exists!" % dbname)
sys.exit(-1)
types = [
'api',
# ci_*: CI service stats
'ci_build',
'ci_queue',
# code_* + evolution + file_history: git repo stats
'code_commit',
'code_commit_unique',
'code_modification',
'evolution',
'file_history',
# forum_*: forum stats (SO, Discourse, Askbot etc)
'forum_post',
'forum_topic',
# GitHub stats
'ghstats',
# im_*: Instant messaging stats
'im_stats',
'im_ops',
'im_msg',
'issue',
'logstats',
# email, mail*: Email statitics
'email',
'mailstats',
'mailtop',
# organisation, view, source, publish: UI Org DB
'organisation',
'view',
'publish',
'source',
# stats: Miscellaneous stats
'stats',
# social_*: Twitter, Mastodon, Facebook etc
'social_follow',
'social_followers',
'social_follower',
'social_person',
# uisession, useraccount, message: UI user DB
'uisession',
'useraccount',
'message',
# person: contributor DB
'person',
]
for t in types:
iname = "%s_%s" % (dbname, t)
print("Creating index " + iname)
settings = {
"number_of_shards" : shards,
"number_of_replicas" : replicas
}
res = es.indices.create(index = iname, body = {
"mappings" : mappings['mappings'],
"settings": settings
}
)
print("Indices created! %s " % res)
salt = bcrypt.gensalt()
pwd = bcrypt.hashpw(adminPass.encode('utf-8'), salt).decode('ascii')
print("Creating administrator account")
doc = {
'email': adminName, # Username (email)
'password': pwd, # Hashed password
'displayName': "Administrator", # Display Name
'organisations': [], # Orgs user belongs to (default is none)
'ownerships': [], # Orgs user owns (default is none)
'defaultOrganisation': None, # Default org for user
'verified': True, # Account verified via email?
'userlevel': "admin" # User level (user/admin)
}
dbdoc = {
'apiversion': KIBBLE_VERSION, # Log current API version
'dbversion': KIBBLE_DB_VERSION # Log the database revision we accept (might change!)
}
es.index(index=dbname+'_useraccount', doc_type = '_doc', id = adminName, body = doc)
es.index(index=dbname+'_api', doc_type = '_doc', id = 'current', body = dbdoc)
print("Account created!")