added if statment
This commit is contained in:
parent
8dfd01c5f4
commit
e1da27038c
|
@ -11,6 +11,7 @@ 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
|
||||||
|
@ -66,7 +67,7 @@ def check_solr_connection(retry=None):
|
||||||
print('[prerun] Giving up after 5 tries...')
|
print('[prerun] Giving up after 5 tries...')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
url = os.environ.get('CKAN_SOLR_URL_AUTH', '')
|
url = os.environ.get('CKAN_SOLR_URL', '')
|
||||||
username = os.environ.get('SOLR_ADMIN_USERNAME', '')
|
username = os.environ.get('SOLR_ADMIN_USERNAME', '')
|
||||||
password = os.environ.get('SOLR_ADMIN_PASSWORD', '')
|
password = os.environ.get('SOLR_ADMIN_PASSWORD', '')
|
||||||
search_url = '{url}/schema/name?wt=json'.format(url=url)
|
search_url = '{url}/schema/name?wt=json'.format(url=url)
|
||||||
|
@ -74,6 +75,9 @@ def check_solr_connection(retry=None):
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if not username:
|
||||||
|
connection = urllib.request.urlopen(search_url)
|
||||||
|
else:
|
||||||
request = urllib.request.Request(search_url)
|
request = urllib.request.Request(search_url)
|
||||||
base64string = base64.b64encode(bytes('%s:%s' % (username, password),'ascii'))
|
base64string = base64.b64encode(bytes('%s:%s' % (username, password),'ascii'))
|
||||||
request.add_header("Authorization", "Basic %s" % base64string.decode('utf-8'))
|
request.add_header("Authorization", "Basic %s" % base64string.decode('utf-8'))
|
||||||
|
|
Loading…
Reference in New Issue