Merge pull request #71 from keitaroinc/ckan-chart-update
Integration for solr auth connection
This commit is contained in:
commit
3da78d6434
|
@ -1,12 +1,9 @@
|
|||
"""
|
||||
Copyright (c) 2016 Keitaro AB
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -14,12 +11,13 @@ 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
|
||||
|
||||
|
@ -70,10 +68,20 @@ def check_solr_connection(retry=None):
|
|||
sys.exit(1)
|
||||
|
||||
url = os.environ.get('CKAN_SOLR_URL', '')
|
||||
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:
|
||||
connection = urllib.request.urlopen(search_url)
|
||||
if not username:
|
||||
connection = urllib.request.urlopen(search_url)
|
||||
else:
|
||||
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
|
||||
|
@ -217,4 +225,4 @@ if __name__ == '__main__':
|
|||
init_db()
|
||||
if os.environ.get('CKAN_DATASTORE_WRITE_URL'):
|
||||
init_datastore()
|
||||
create_sysadmin()
|
||||
create_sysadmin()
|
Loading…
Reference in New Issue