jupyter / nb2kg

Other
73 stars 31 forks source link

Allow KG_HEADERS to specify Authorization without being overwritten #30

Closed chuyqa closed 5 years ago

chuyqa commented 5 years ago

https://github.com/jupyter/nb2kg/issues/28

Currently if KG_HEADERS Includes an Authorization: header, it always be replaced by and empty token: Authorization: token

This PR attempts to keep the existing functionality when KG_HEADERS does not include Authorization by

  1. Loading KG_HEADERS
  2. If Authorization was NOT present in the KG_HEADERS, this maintains the existing functionality of creating in the Authorization: token $KG_AUTH_TOKEN even if KG_AUTH_TOKEN is empty string

Tested using Apache Knox 1.2 w/ JWT Authentication. This uses the form {'Authorization': "Bearer '${authToken}'"}

dsxl="${topology}.fyre.ibm.com:31843"
gateway="${knoxhost}:8443/gateway/${topology}"
authToken="$(curl -k -X GET https://$dsxl/v1/preauth/validateAuth -u $user:$password 2> /dev/null | grep -o "accessToken\":\".*\",\"_" | grep -o ":\".*" | grep -o ".*\"," | awk -F\" '{print $2}')"

docker run -t --rm \
--name localnb2kg \
-p 8888:8888 \
-e KG_URL="https://${gateway}/jkg" \
-e KG_WS_URL="wss://${gateway}/jkgws"  \
-e VALIDATE_KG_CERT=no \
-e KG_HEADERS='{"Authorization": "Bearer '${authToken}'"}' \
-e KERNEL_EXTRA_SPARK_OPTS='--archives hdfs:///user/dsxhi/environments/x86_glibc2_17.tar.gz --conf spark.yarn.appMasterEnv.PYSPARK_PYTHON=x86_glibc2_17.tar.gz/x86_glibc2_17/bin/python --conf spark.executor.memory=1g' \
nb2kg:2.0.0.iss28