added if statment

This commit is contained in:
filip.mihajlovski 2022-03-15 15:25:52 +01:00
parent 8dfd01c5f4
commit e1da27038c
1 changed files with 10 additions and 6 deletions

View File

@ -11,6 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
from multiprocessing import connection
import os
import sys
import subprocess
@ -66,7 +67,7 @@ def check_solr_connection(retry=None):
print('[prerun] Giving up after 5 tries...')
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', '')
password = os.environ.get('SOLR_ADMIN_PASSWORD', '')
search_url = '{url}/schema/name?wt=json'.format(url=url)
@ -74,6 +75,9 @@ def check_solr_connection(retry=None):
try:
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'))