Skip to content

Commit

Permalink
Merge pull request #127 from keitaroinc/fix-solr-issue
Browse files Browse the repository at this point in the history
rewrite ckan 2.10 prerun script to connect to solr
  • Loading branch information
KirilPoposki98 committed Mar 7, 2024
2 parents daa578a + 9c2bd7f commit e04af27
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions images/ckan/2.10/setup/app/prerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
from multiprocessing import connection

import os
import sys
import subprocess
import psycopg2
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 json

import time

ckan_ini = os.environ.get('CKAN_INI', '/srv/app/production.ini')
Expand Down Expand Up @@ -70,20 +70,18 @@ def check_solr_connection(retry=None):
sys.exit(1)

url = os.environ.get('CKAN_SOLR_URL', '')
username = os.environ.get('SOLR_ADMIN_USERNAME', 'admin')
password = os.environ.get('SOLR_ADMIN_PASSWORD', 'pass')
username = os.environ.get('CKAN_SOLR_USER', '')
password = os.environ.get('CKAN_SOLR_PASSWORD', '')
search_url = '{url}/schema/name?wt=json'.format(url=url)

try:
if not username:
connection = urllib.request.urlopen(search_url)
else:
passman = urllib.request.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, search_url, username, password)
authhandler = urllib.request.HTTPBasicAuthHandler(passman)
opener = urllib.request.build_opener(authhandler)
urllib.request.install_opener(opener)
connection = urllib.request.urlopen(search_url)
request = urllib.request.Request(search_url)
base64string = base64.b64encode(bytes('%s:%s' % (username, password),'ascii'))
request.add_header("Authorization", "Basic %s" % base64string.decode('utf-8'))
connection = urllib.request.urlopen(request)
except urllib.error.URLError as e:
print('[prerun] Unable to connect to solr...try again in a while.')
import time
Expand Down

0 comments on commit e04af27

Please sign in to comment.