Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite ckan 2.10 prerun script to connect to solr #127

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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