rewrite ckan 2.10 prerun script to connect to solr

This commit is contained in:
Kiril-Poposki1998 2024-03-07 14:42:44 +01:00
parent 40f792b2e7
commit 0969b45121
1 changed files with 8 additions and 10 deletions

View File

@ -13,16 +13,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """
from multiprocessing import connection
import os import os
import sys import sys
import subprocess import subprocess
import psycopg2 import psycopg2
from sqlalchemy.engine.url import make_url from sqlalchemy.engine.url import make_url
import urllib.request, urllib.error, urllib.parse import urllib.request, urllib.error, urllib.parse, base64
import re import re
import json import json
import time import time
ckan_ini = os.environ.get('CKAN_INI', '/srv/app/production.ini') ckan_ini = os.environ.get('CKAN_INI', '/srv/app/production.ini')
@ -70,20 +70,18 @@ def check_solr_connection(retry=None):
sys.exit(1) sys.exit(1)
url = os.environ.get('CKAN_SOLR_URL', '') url = os.environ.get('CKAN_SOLR_URL', '')
username = os.environ.get('SOLR_ADMIN_USERNAME', 'admin') username = os.environ.get('CKAN_SOLR_USER', '')
password = os.environ.get('SOLR_ADMIN_PASSWORD', 'pass') password = os.environ.get('CKAN_SOLR_PASSWORD', '')
search_url = '{url}/schema/name?wt=json'.format(url=url) search_url = '{url}/schema/name?wt=json'.format(url=url)
try: try:
if not username: if not username:
connection = urllib.request.urlopen(search_url) connection = urllib.request.urlopen(search_url)
else: else:
passman = urllib.request.HTTPPasswordMgrWithDefaultRealm() request = urllib.request.Request(search_url)
passman.add_password(None, search_url, username, password) base64string = base64.b64encode(bytes('%s:%s' % (username, password),'ascii'))
authhandler = urllib.request.HTTPBasicAuthHandler(passman) request.add_header("Authorization", "Basic %s" % base64string.decode('utf-8'))
opener = urllib.request.build_opener(authhandler) connection = urllib.request.urlopen(request)
urllib.request.install_opener(opener)
connection = urllib.request.urlopen(search_url)
except urllib.error.URLError as e: except urllib.error.URLError as e:
print('[prerun] Unable to connect to solr...try again in a while.') print('[prerun] Unable to connect to solr...try again in a while.')
import time import time