@sassoftware/viya-serverjs 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +6 -0
- package/.dockerignore +2 -0
- package/.env +29 -0
- package/.env.proxy +31 -0
- package/.env.server +29 -0
- package/.eslintignore +4 -0
- package/.eslintrc.json +42 -0
- package/Dockerfile +44 -0
- package/README.md +6 -4
- package/cli.js +9 -0
- package/images/viya-apiserverjs.png +0 -0
- package/lib/{core/config.js → config.js} +5 -24
- package/lib/handlers/appCallback.js +62 -0
- package/lib/handlers/codeAuth.js +61 -0
- package/lib/{core/handlers → handlers}/decodeJwt.js +2 -2
- package/lib/handlers/favicon.js +45 -0
- package/lib/handlers/getApp.js +77 -0
- package/lib/handlers/getApp2.js +48 -0
- package/lib/handlers/getUser.js +49 -0
- package/lib/{core/handlers → handlers}/index.js +2 -2
- package/lib/handlers/keepAlive.js +99 -0
- package/lib/handlers/keepAlive2.js +33 -0
- package/lib/handlers/logon.js +44 -0
- package/lib/handlers/logout.js +88 -0
- package/lib/handlers/proxyMapUri.js +78 -0
- package/lib/handlers/proxyOnResponse.js +26 -0
- package/lib/handlers/reactDev.js +52 -0
- package/lib/handlers/setCookies.js +110 -0
- package/lib/{core/iService.js → iService.js} +45 -30
- package/lib/index.js +177 -10
- package/lib/{core/parseDocker.js → parseDocker.js} +1 -1
- package/lib/plugins/SASauth.js +101 -0
- package/lib/plugins/appCookie.js +99 -0
- package/lib/plugins/setContext.js +56 -0
- package/lib/{core/plugins → plugins}/setDefaultRoutes.js +67 -58
- package/lib/plugins/setupAuth.js +87 -0
- package/lib/{core/plugins → plugins}/setupUserRoutes.js +21 -12
- package/lib/plugins/token.js +31 -0
- package/lib/schemes/SASTokenScheme.js +71 -0
- package/package.json +56 -14
- package/packages/core/config.js +86 -0
- package/packages/core/handlers/appCallback.js +40 -0
- package/packages/core/handlers/codeAuth.js +31 -0
- package/packages/core/handlers/decodeJwt.js +11 -0
- package/packages/core/handlers/favicon.js +24 -0
- package/packages/core/handlers/getApp.js +41 -0
- package/packages/core/handlers/getApp2.js +26 -0
- package/packages/core/handlers/getUser.js +20 -0
- package/packages/core/handlers/index.js +36 -0
- package/packages/core/handlers/keepAlive.js +54 -0
- package/packages/core/handlers/keepAlive2.js +13 -0
- package/packages/core/handlers/logon.js +24 -0
- package/packages/core/handlers/logout.js +43 -0
- package/{lib → packages}/core/handlers/proxyMapUri.js +25 -36
- package/packages/core/handlers/proxyOnResponse.js +12 -0
- package/packages/core/handlers/reactDev.js +30 -0
- package/packages/core/handlers/setCookies.js +78 -0
- package/packages/core/iService.js +369 -0
- package/packages/core/index.js +249 -0
- package/packages/core/parseDocker.js +33 -0
- package/packages/core/plugins/SASauth.js +79 -0
- package/packages/core/plugins/appCookie.js +49 -0
- package/packages/core/plugins/setContext.js +34 -0
- package/packages/core/plugins/setDefaultRoutes.js +262 -0
- package/packages/core/plugins/setupAuth.js +48 -0
- package/packages/core/plugins/setupUserRoutes.js +48 -0
- package/packages/core/plugins/token.js +10 -0
- package/packages/core/schemes/SASTokenScheme.js +43 -0
- package/packages/core/visionIndex.html +24 -0
- package/packages/examples/apitest/.env +11 -0
- package/packages/examples/apitest/.eslintrc.json +42 -0
- package/packages/examples/apitest/Dockerfile +41 -0
- package/packages/examples/apitest/api.js +88 -0
- package/packages/examples/apitest/appenv.js +6 -0
- package/packages/examples/apitest/docker-compose.yml +10 -0
- package/packages/examples/apitest/package.json +19 -0
- package/packages/examples/apitest/public/data/Cluster_SDOH1.sas +182 -0
- package/packages/examples/apitest/public/data/Cluster_SDOH6.sas +180 -0
- package/packages/examples/apitest/public/data/LeNet_snzrle.astore +0 -0
- package/packages/examples/apitest/public/data/NeuralNetwork_High_med.sas +2409 -0
- package/packages/examples/apitest/public/data/NeuralNetwork_high_med1.sas +2409 -0
- package/packages/examples/apitest/public/data/ast/GBlocalcopy.sasast +0 -0
- package/packages/examples/apitest/public/data/ast/LeNet_snzrle.astore +0 -0
- package/packages/examples/apitest/public/data/ast/gb_IrisGB.sasast +0 -0
- package/packages/examples/apitest/public/data/ast/paysimsvdd.sasast +0 -0
- package/packages/examples/apitest/public/data/ast/svmlocalcopy.sasast +0 -0
- package/packages/examples/apitest/public/data/cars.csv +429 -0
- package/packages/examples/apitest/public/data/cluster_test2.sas7bdat +0 -0
- package/packages/examples/apitest/public/data/cmdList.txt +15 -0
- package/packages/examples/apitest/public/data/gradBoost.sashdat +0 -0
- package/packages/examples/apitest/public/data/iris.csv +151 -0
- package/packages/examples/apitest/public/data/model1.sas7bdat +0 -0
- package/packages/examples/apitest/public/favicon.ico +0 -0
- package/packages/examples/apitest/public/index.html +316 -0
- package/packages/examples/apitest/public/index2.html +102 -0
- package/packages/examples/apitest/public/logon.html +42 -0
- package/packages/examples/apitest/public/myapp/secondary.html +1 -0
- package/packages/examples/apitest/public/myapp/test.js +2 -0
- package/packages/examples/apitest/public/onlogoff.html +53 -0
- package/packages/examples/apitest/start.sh +15 -0
- package/packages/examples/app/.env +32 -0
- package/packages/examples/app/.envProxy +19 -0
- package/packages/examples/app/.envimpl +12 -0
- package/packages/examples/app/.eslintrc.json +42 -0
- package/packages/examples/app/Dockerfile +42 -0
- package/packages/examples/app/appenv.js +6 -0
- package/packages/examples/app/certs/ca.crt +19 -0
- package/packages/examples/app/certs/tls.crt +25 -0
- package/packages/examples/app/certs/tls.key +28 -0
- package/packages/examples/app/certs/tls.sh +5 -0
- package/packages/examples/app/docker-compose.yml +12 -0
- package/packages/examples/app/index.js +15 -0
- package/packages/examples/app/package.json +20 -0
- package/packages/examples/app/public/casread.html +324 -0
- package/packages/examples/app/public/data/Cluster_SDOH1.sas +182 -0
- package/packages/examples/app/public/data/Cluster_SDOH6.sas +180 -0
- package/packages/examples/app/public/data/LeNet_snzrle.astore +0 -0
- package/packages/examples/app/public/data/NeuralNetwork_High_med.sas +2409 -0
- package/packages/examples/app/public/data/NeuralNetwork_high_med1.sas +2409 -0
- package/packages/examples/app/public/data/ast/GBlocalcopy.sasast +0 -0
- package/packages/examples/app/public/data/ast/LeNet_snzrle.astore +0 -0
- package/packages/examples/app/public/data/ast/gb_IrisGB.sasast +0 -0
- package/packages/examples/app/public/data/ast/paysimsvdd.sasast +0 -0
- package/packages/examples/app/public/data/ast/svmlocalcopy.sasast +0 -0
- package/packages/examples/app/public/data/cars.csv +429 -0
- package/packages/examples/app/public/data/cluster_test2.sas7bdat +0 -0
- package/packages/examples/app/public/data/cmdList.txt +15 -0
- package/packages/examples/app/public/data/gradBoost.sashdat +0 -0
- package/packages/examples/app/public/data/iris.csv +151 -0
- package/packages/examples/app/public/data/model1.sas7bdat +0 -0
- package/packages/examples/app/public/favicon.ico +0 -0
- package/packages/examples/app/public/index.html +332 -0
- package/packages/examples/app/public/indexProxy.html +346 -0
- package/packages/examples/app/public/indextest.html +316 -0
- package/packages/examples/app/public/logon.html +44 -0
- package/packages/examples/app/public/micburger.html +345 -0
- package/packages/examples/app/public/micburger.txt.html +311 -0
- package/packages/examples/app/public/myapp/secondary.html +1 -0
- package/packages/examples/app/public/myapp/test.js +2 -0
- package/packages/examples/app/public/sara.txt +345 -0
- package/packages/examples/app/public/testva2.html +311 -0
- package/packages/examples/app/startup.sh +15 -0
- package/packages/examples/appdocker/.env +21 -0
- package/packages/examples/appdocker/.envProxy +22 -0
- package/packages/examples/appdocker/.envimpl +12 -0
- package/packages/examples/appdocker/.eslintrc.json +42 -0
- package/packages/examples/appdocker/Dockerfile +43 -0
- package/packages/examples/appdocker/appenv.js +6 -0
- package/packages/examples/appdocker/certs/ca.crt +19 -0
- package/packages/examples/appdocker/certs/tls.crt +25 -0
- package/packages/examples/appdocker/certs/tls.key +28 -0
- package/packages/examples/appdocker/certs/tls.sh +5 -0
- package/packages/examples/appdocker/docker-compose.yml +12 -0
- package/packages/examples/appdocker/index.js +15 -0
- package/packages/examples/appdocker/package.json +20 -0
- package/packages/examples/appdocker/public/data/Cluster_SDOH1.sas +182 -0
- package/packages/examples/appdocker/public/data/Cluster_SDOH6.sas +180 -0
- package/packages/examples/appdocker/public/data/LeNet_snzrle.astore +0 -0
- package/packages/examples/appdocker/public/data/NeuralNetwork_High_med.sas +2409 -0
- package/packages/examples/appdocker/public/data/NeuralNetwork_high_med1.sas +2409 -0
- package/packages/examples/appdocker/public/data/ast/GBlocalcopy.sasast +0 -0
- package/packages/examples/appdocker/public/data/ast/LeNet_snzrle.astore +0 -0
- package/packages/examples/appdocker/public/data/ast/gb_IrisGB.sasast +0 -0
- package/packages/examples/appdocker/public/data/ast/paysimsvdd.sasast +0 -0
- package/packages/examples/appdocker/public/data/ast/svmlocalcopy.sasast +0 -0
- package/packages/examples/appdocker/public/data/cars.csv +429 -0
- package/packages/examples/appdocker/public/data/cluster_test2.sas7bdat +0 -0
- package/packages/examples/appdocker/public/data/cmdList.txt +15 -0
- package/packages/examples/appdocker/public/data/gradBoost.sashdat +0 -0
- package/packages/examples/appdocker/public/data/iris.csv +151 -0
- package/packages/examples/appdocker/public/data/model1.sas7bdat +0 -0
- package/packages/examples/appdocker/public/favicon.ico +0 -0
- package/packages/examples/appdocker/public/index.html +346 -0
- package/packages/examples/appdocker/public/indexProxy.html +346 -0
- package/packages/examples/appdocker/public/indextest.html +316 -0
- package/packages/examples/appdocker/public/logon.html +44 -0
- package/packages/examples/appdocker/public/myapp/secondary.html +1 -0
- package/packages/examples/appdocker/public/myapp/test.js +2 -0
- package/packages/examples/appdocker/startup.sh +15 -0
- package/packages/examples/apptest/.env +28 -0
- package/packages/examples/apptest/.envProxy +22 -0
- package/packages/examples/apptest/.envimpl +12 -0
- package/packages/examples/apptest/.eslintrc.json +42 -0
- package/packages/examples/apptest/Dockerfile +44 -0
- package/packages/examples/apptest/appDir/app1/design.html +350 -0
- package/packages/examples/apptest/appDir/app1/index.html +353 -0
- package/packages/examples/apptest/appDir/index.html +350 -0
- package/packages/examples/apptest/appenv.js +6 -0
- package/packages/examples/apptest/docker-compose.yml +12 -0
- package/packages/examples/apptest/index.js +444 -0
- package/packages/examples/apptest/package.json +24 -0
- package/packages/examples/apptest/public/casread2.html +321 -0
- package/packages/examples/apptest/public/data/Cluster_SDOH1.sas +182 -0
- package/packages/examples/apptest/public/data/Cluster_SDOH6.sas +180 -0
- package/packages/examples/apptest/public/data/LeNet_snzrle.astore +0 -0
- package/packages/examples/apptest/public/data/NeuralNetwork_High_med.sas +2409 -0
- package/packages/examples/apptest/public/data/NeuralNetwork_high_med1.sas +2409 -0
- package/packages/examples/apptest/public/data/ast/GBlocalcopy.sasast +0 -0
- package/packages/examples/apptest/public/data/ast/LeNet_snzrle.astore +0 -0
- package/packages/examples/apptest/public/data/ast/gb_IrisGB.sasast +0 -0
- package/packages/examples/apptest/public/data/ast/paysimsvdd.sasast +0 -0
- package/packages/examples/apptest/public/data/ast/svmlocalcopy.sasast +0 -0
- package/packages/examples/apptest/public/data/cars.csv +429 -0
- package/packages/examples/apptest/public/data/cluster_test2.sas7bdat +0 -0
- package/packages/examples/apptest/public/data/cmdList.txt +15 -0
- package/packages/examples/apptest/public/data/gradBoost.sashdat +0 -0
- package/packages/examples/apptest/public/data/iris.csv +151 -0
- package/packages/examples/apptest/public/data/model1.sas7bdat +0 -0
- package/packages/examples/apptest/public/design.html +349 -0
- package/packages/examples/apptest/public/favicon.ico +0 -0
- package/packages/examples/apptest/public/help.html +1 -0
- package/packages/examples/apptest/public/index.html +353 -0
- package/packages/examples/apptest/public/index2.html +353 -0
- package/packages/examples/apptest/public/indexProxy.html +346 -0
- package/packages/examples/apptest/public/indextest.html +316 -0
- package/packages/examples/apptest/public/logon.html +44 -0
- package/packages/examples/apptest/public/myapp/q.html +349 -0
- package/packages/examples/apptest/public/myapp/secondary.html +1 -0
- package/packages/examples/apptest/public/myapp/test.js +2 -0
- package/packages/examples/apptest/public/push1.html +187 -0
- package/packages/examples/apptest/startup.sh +15 -0
- package/packages/examples/apptesti/.env +13 -0
- package/packages/examples/apptesti/.eslintrc.json +42 -0
- package/packages/examples/apptesti/Dockerfile +42 -0
- package/packages/examples/apptesti/appenv.js +6 -0
- package/packages/examples/apptesti/certs/ca.crt +19 -0
- package/packages/examples/apptesti/certs/tls.crt +25 -0
- package/packages/examples/apptesti/certs/tls.key +28 -0
- package/packages/examples/apptesti/certs/tls.sh +5 -0
- package/packages/examples/apptesti/docker-compose.yml +12 -0
- package/{lib/cli.js → packages/examples/apptesti/index.js} +4 -6
- package/packages/examples/apptesti/package.json +20 -0
- package/packages/examples/apptesti/public/data/Cluster_SDOH1.sas +182 -0
- package/packages/examples/apptesti/public/data/Cluster_SDOH6.sas +180 -0
- package/packages/examples/apptesti/public/data/LeNet_snzrle.astore +0 -0
- package/packages/examples/apptesti/public/data/NeuralNetwork_High_med.sas +2409 -0
- package/packages/examples/apptesti/public/data/NeuralNetwork_high_med1.sas +2409 -0
- package/packages/examples/apptesti/public/data/ast/GBlocalcopy.sasast +0 -0
- package/packages/examples/apptesti/public/data/ast/LeNet_snzrle.astore +0 -0
- package/packages/examples/apptesti/public/data/ast/gb_IrisGB.sasast +0 -0
- package/packages/examples/apptesti/public/data/ast/paysimsvdd.sasast +0 -0
- package/packages/examples/apptesti/public/data/ast/svmlocalcopy.sasast +0 -0
- package/packages/examples/apptesti/public/data/cars.csv +429 -0
- package/packages/examples/apptesti/public/data/cluster_test2.sas7bdat +0 -0
- package/packages/examples/apptesti/public/data/cmdList.txt +15 -0
- package/packages/examples/apptesti/public/data/gradBoost.sashdat +0 -0
- package/packages/examples/apptesti/public/data/iris.csv +151 -0
- package/packages/examples/apptesti/public/data/model1.sas7bdat +0 -0
- package/packages/examples/apptesti/public/favicon.ico +0 -0
- package/packages/examples/apptesti/public/index.html +346 -0
- package/packages/examples/apptesti/public/indexProxy.html +346 -0
- package/packages/examples/apptesti/public/indextest.html +316 -0
- package/packages/examples/apptesti/public/logon.html +44 -0
- package/packages/examples/apptesti/public/main.html +346 -0
- package/packages/examples/apptesti/public/myapp/secondary.html +1 -0
- package/packages/examples/apptesti/public/myapp/test.js +2 -0
- package/packages/examples/apptesti/startup.sh +15 -0
- package/packages/examples/basic/.env +10 -0
- package/packages/examples/basic/.eslintrc.json +42 -0
- package/packages/examples/basic/Dockerfile +41 -0
- package/packages/examples/basic/api.js +88 -0
- package/packages/examples/basic/appenv.js +6 -0
- package/packages/examples/basic/docker-compose.yml +10 -0
- package/packages/examples/basic/package.json +19 -0
- package/packages/examples/basic/public/data/Cluster_SDOH1.sas +182 -0
- package/packages/examples/basic/public/data/Cluster_SDOH6.sas +180 -0
- package/packages/examples/basic/public/data/LeNet_snzrle.astore +0 -0
- package/packages/examples/basic/public/data/NeuralNetwork_High_med.sas +2409 -0
- package/packages/examples/basic/public/data/NeuralNetwork_high_med1.sas +2409 -0
- package/packages/examples/basic/public/data/ast/GBlocalcopy.sasast +0 -0
- package/packages/examples/basic/public/data/ast/LeNet_snzrle.astore +0 -0
- package/packages/examples/basic/public/data/ast/gb_IrisGB.sasast +0 -0
- package/packages/examples/basic/public/data/ast/paysimsvdd.sasast +0 -0
- package/packages/examples/basic/public/data/ast/svmlocalcopy.sasast +0 -0
- package/packages/examples/basic/public/data/cars.csv +429 -0
- package/packages/examples/basic/public/data/cluster_test2.sas7bdat +0 -0
- package/packages/examples/basic/public/data/cmdList.txt +15 -0
- package/packages/examples/basic/public/data/gradBoost.sashdat +0 -0
- package/packages/examples/basic/public/data/iris.csv +151 -0
- package/packages/examples/basic/public/data/model1.sas7bdat +0 -0
- package/packages/examples/basic/public/favicon.ico +0 -0
- package/packages/examples/basic/public/index.html +29 -0
- package/packages/examples/basic/public/index2.html +102 -0
- package/packages/examples/basic/public/logon.html +42 -0
- package/packages/examples/basic/public/myapp/secondary.html +1 -0
- package/packages/examples/basic/public/myapp/test.js +2 -0
- package/packages/examples/basic/public/onlogoff.html +53 -0
- package/packages/examples/basic/start.sh +15 -0
- package/packages/examples/proxytest/.env +23 -0
- package/packages/examples/proxytest/.envimpl +11 -0
- package/packages/examples/proxytest/.eslintrc.json +42 -0
- package/packages/examples/proxytest/Dockerfile +42 -0
- package/packages/examples/proxytest/appenv.js +6 -0
- package/packages/examples/proxytest/docker-compose.yml +12 -0
- package/packages/examples/proxytest/index.js +57 -0
- package/packages/examples/proxytest/package.json +18 -0
- package/packages/examples/proxytest/public/data/Cluster_SDOH1.sas +182 -0
- package/packages/examples/proxytest/public/data/Cluster_SDOH6.sas +180 -0
- package/packages/examples/proxytest/public/data/LeNet_snzrle.astore +0 -0
- package/packages/examples/proxytest/public/data/NeuralNetwork_High_med.sas +2409 -0
- package/packages/examples/proxytest/public/data/NeuralNetwork_high_med1.sas +2409 -0
- package/packages/examples/proxytest/public/data/ast/GBlocalcopy.sasast +0 -0
- package/packages/examples/proxytest/public/data/ast/LeNet_snzrle.astore +0 -0
- package/packages/examples/proxytest/public/data/ast/gb_IrisGB.sasast +0 -0
- package/packages/examples/proxytest/public/data/ast/paysimsvdd.sasast +0 -0
- package/packages/examples/proxytest/public/data/ast/svmlocalcopy.sasast +0 -0
- package/packages/examples/proxytest/public/data/cars.csv +429 -0
- package/packages/examples/proxytest/public/data/cluster_test2.sas7bdat +0 -0
- package/packages/examples/proxytest/public/data/cmdList.txt +15 -0
- package/packages/examples/proxytest/public/data/gradBoost.sashdat +0 -0
- package/packages/examples/proxytest/public/data/iris.csv +151 -0
- package/packages/examples/proxytest/public/data/model1.sas7bdat +0 -0
- package/packages/examples/proxytest/public/favicon.ico +0 -0
- package/packages/examples/proxytest/public/index.html +357 -0
- package/packages/examples/proxytest/public/index.js +57 -0
- package/packages/examples/proxytest/public/indextest.html +316 -0
- package/packages/examples/proxytest/public/logon.html +44 -0
- package/packages/examples/proxytest/public/main.html +357 -0
- package/packages/examples/proxytest/public/myapp/secondary.html +1 -0
- package/packages/examples/proxytest/public/myapp/test.js +2 -0
- package/packages/examples/proxytest/public/restaf.js +2461 -0
- package/packages/examples/proxytest/public/restaf.min.js +11 -0
- package/packages/examples/proxytest/public/sas/iris.txt +10 -0
- package/packages/examples/proxytest/startup.sh +15 -0
- package/public/casread2.html +321 -0
- package/public/data/Cluster_SDOH1.sas +182 -0
- package/public/data/Cluster_SDOH6.sas +180 -0
- package/public/data/LeNet_snzrle.astore +0 -0
- package/public/data/NeuralNetwork_High_med.sas +2409 -0
- package/public/data/NeuralNetwork_high_med1.sas +2409 -0
- package/public/data/ast/GBlocalcopy.sasast +0 -0
- package/public/data/ast/LeNet_snzrle.astore +0 -0
- package/public/data/ast/gb_IrisGB.sasast +0 -0
- package/public/data/ast/paysimsvdd.sasast +0 -0
- package/public/data/ast/svmlocalcopy.sasast +0 -0
- package/public/data/cars.csv +429 -0
- package/public/data/cluster_test2.sas7bdat +0 -0
- package/public/data/cmdList.txt +15 -0
- package/public/data/gradBoost.sashdat +0 -0
- package/public/data/iris.csv +151 -0
- package/public/data/model1.sas7bdat +0 -0
- package/public/design.html +350 -0
- package/public/display.html +354 -0
- package/public/favicon.ico +0 -0
- package/public/help.html +1 -0
- package/public/index.html +354 -0
- package/public/index2.html +353 -0
- package/public/indexProxy.html +350 -0
- package/public/indextest.html +316 -0
- package/public/logon.html +44 -0
- package/public/myapp/q.html +349 -0
- package/public/myapp/secondary.html +1 -0
- package/public/myapp/test.js +2 -0
- package/public/push1.html +187 -0
- package/server.js +444 -0
- package/src/config.js +90 -0
- package/src/handlers/appCallback.js +40 -0
- package/src/handlers/codeAuth.js +31 -0
- package/src/handlers/decodeJwt.js +11 -0
- package/src/handlers/favicon.js +24 -0
- package/src/handlers/getApp.js +52 -0
- package/src/handlers/getApp2.js +26 -0
- package/src/handlers/getUser.js +20 -0
- package/src/handlers/index.js +36 -0
- package/src/handlers/keepAlive.js +54 -0
- package/src/handlers/keepAlive2.js +13 -0
- package/src/handlers/logon.js +24 -0
- package/src/handlers/logout.js +43 -0
- package/src/handlers/proxyMapUri.js +56 -0
- package/src/handlers/proxyOnResponse.js +12 -0
- package/src/handlers/reactDev.js +30 -0
- package/src/handlers/setCookies.js +76 -0
- package/src/iService.js +369 -0
- package/src/index.js +243 -0
- package/src/parseDocker.js +32 -0
- package/src/plugins/SASauth.js +79 -0
- package/src/plugins/appCookie.js +49 -0
- package/src/plugins/setContext.js +34 -0
- package/src/plugins/setDefaultRoutes.js +262 -0
- package/src/plugins/setupAuth.js +48 -0
- package/src/plugins/setupUserRoutes.js +48 -0
- package/src/plugins/token.js +10 -0
- package/src/schemes/SASTokenScheme.js +43 -0
- package/src/visionIndex.html +24 -0
- package/start.sh +15 -0
- package/lib/core/handlers/appCallback.js +0 -51
- package/lib/core/handlers/codeAuth.js +0 -61
- package/lib/core/handlers/favicon.js +0 -45
- package/lib/core/handlers/getApp.js +0 -67
- package/lib/core/handlers/getApp2.js +0 -48
- package/lib/core/handlers/getUser.js +0 -49
- package/lib/core/handlers/keepAlive.js +0 -96
- package/lib/core/handlers/keepAlive2.js +0 -33
- package/lib/core/handlers/logon.js +0 -44
- package/lib/core/handlers/logout.js +0 -88
- package/lib/core/handlers/proxyOnResponse.js +0 -26
- package/lib/core/handlers/reactDev.js +0 -52
- package/lib/core/handlers/setCookies.js +0 -116
- package/lib/core/index.js +0 -195
- package/lib/core/plugins/SASauth.js +0 -100
- package/lib/core/plugins/appCookie.js +0 -98
- package/lib/core/plugins/setContext.js +0 -55
- package/lib/core/plugins/setupAuth.js +0 -86
- package/lib/core/plugins/token.js +0 -31
- package/lib/core/schemes/SASTokenScheme.js +0 -71
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
let uuid = require('uuid');
|
|
6
|
+
let debug = require('debug')('setcookies');
|
|
7
|
+
|
|
8
|
+
async function setCookies (req, h, options) {
|
|
9
|
+
let credentials = req.auth.credentials;
|
|
10
|
+
debug('setcookie', credentials);
|
|
11
|
+
req.log('setcookie', credentials);
|
|
12
|
+
if (credentials != null && req.auth.error != null) {
|
|
13
|
+
debug('logon failed');
|
|
14
|
+
return { status: false, error: req.auth.error };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// create a cookie(sid) and save credentials in cache
|
|
18
|
+
const sid = uuid.v4();
|
|
19
|
+
credentials.sid = sid;
|
|
20
|
+
if (options != null) {
|
|
21
|
+
options.allAppEnv.LOGONPAYLOAD.token = credentials.token;
|
|
22
|
+
options.allAppEnv.LOGONPAYLOAD.tokenType = 'bearer';
|
|
23
|
+
debug(options.allAppEnv.LOGONPAYLOAD);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
await req.server.app.cache.set(sid, credentials, 0);
|
|
28
|
+
// Can we get away without setting cookie for this session?
|
|
29
|
+
// Need to also modify keepAlive
|
|
30
|
+
if (process.env.COOKIES !== 'NO') {
|
|
31
|
+
debugger;
|
|
32
|
+
req.cookieAuth.set({ sid });
|
|
33
|
+
};
|
|
34
|
+
debug('credentials query', credentials.query);
|
|
35
|
+
let redirect = (credentials.query != null && credentials.query.next != null) ? credentials.query.next : null;
|
|
36
|
+
req.server.log('setcookie-redirect', redirect);
|
|
37
|
+
return { status: true, error: null , redirect: redirect};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default setCookies;
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
save for future reference - not used at this time
|
|
44
|
+
async function getCredentials (req) {
|
|
45
|
+
let route = process.env.REDIRECT == null ? `/callback` : '/' + process.env.REDIRECT;
|
|
46
|
+
let info = req.server.info;
|
|
47
|
+
let location = info.uri + route;
|
|
48
|
+
if (info.host === '0.0.0.0') {
|
|
49
|
+
location = `${info.protocol}://${process.env.APPHOST}:${info.port}${route}`;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
let payload = {
|
|
53
|
+
url : `${process.env.VIYA_SERVER}/SASLogon/oauth/token`,
|
|
54
|
+
method: 'POST',
|
|
55
|
+
|
|
56
|
+
headers: {
|
|
57
|
+
// 'Authorization': 'Basic ' + Buffer.from(`${process.env.CLIENTID}:${process.env.CLIENTSECRET}`).toString('base64'),
|
|
58
|
+
'Accept' : 'application/json',
|
|
59
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
60
|
+
},
|
|
61
|
+
data: qs.stringify({
|
|
62
|
+
client_id : `${process.env.CLIENTID}`,
|
|
63
|
+
client_secret: `${process.env.CLIENTSECRET}`,
|
|
64
|
+
redirect_uri : `${location}`,
|
|
65
|
+
|
|
66
|
+
'grant_type': 'authorization_code',
|
|
67
|
+
code : req.query.code
|
|
68
|
+
})
|
|
69
|
+
};
|
|
70
|
+
try {
|
|
71
|
+
let r = await axios(payload);
|
|
72
|
+
return r.data;
|
|
73
|
+
} catch (err) {
|
|
74
|
+
console.log(err);
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
*/
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ------------------------------------------------------------------------------------
|
|
3
|
+
* * Copyright (c) SAS Institute Inc.
|
|
4
|
+
* * Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* * you may not use this file except in compliance with the License.
|
|
6
|
+
* * You may obtain a copy of the License at
|
|
7
|
+
* *
|
|
8
|
+
* * http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
* *
|
|
10
|
+
* * Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* * distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* * See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
* ----------------------------------------------------------------------------------------
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
let fs = require('fs');
|
|
20
|
+
let debug = require('debug')('service');
|
|
21
|
+
let debug2 = require('debug')('tls');
|
|
22
|
+
// let isDocker = require('is-docker');
|
|
23
|
+
let Hapi = require('@hapi/hapi');
|
|
24
|
+
let H202 = require('@hapi/h2o2');
|
|
25
|
+
// const { isSameSiteNoneCompatible } = require('should-send-same-site-none');
|
|
26
|
+
let NodeCache = require("node-cache-promise");
|
|
27
|
+
let Vision = require('@hapi/vision');
|
|
28
|
+
let inert = require('@hapi/inert');
|
|
29
|
+
let selfsigned = require('selfsigned');
|
|
30
|
+
import setupAuth from './plugins/setupAuth';
|
|
31
|
+
|
|
32
|
+
let os = require('os');
|
|
33
|
+
|
|
34
|
+
function iService (userRouteTable, useDefault, asset, allAppEnv, serverMode, userInfo) {
|
|
35
|
+
// process.env.APPHOST_ADDR = process.env.APPHOST;
|
|
36
|
+
const init = async () => {
|
|
37
|
+
|
|
38
|
+
if (process.env.APPHOST === '*') {
|
|
39
|
+
process.env.APPHOST = os.hostname();
|
|
40
|
+
}
|
|
41
|
+
let defaultMaxBytes = 10485760;
|
|
42
|
+
let maxBytes;
|
|
43
|
+
if (isNaN(process.env.PAYLOADMAXBYTES)) {
|
|
44
|
+
maxBytes = defaultMaxBytes;
|
|
45
|
+
} else {
|
|
46
|
+
maxBytes = Number(process.env.PAYLOADMAXBYTES);
|
|
47
|
+
}
|
|
48
|
+
let isSameSite = 'None';
|
|
49
|
+
let isSecure = false;
|
|
50
|
+
|
|
51
|
+
if (process.env.SAMESITE != null) {
|
|
52
|
+
let [s1, s2] = process.env.SAMESITE.split(',');
|
|
53
|
+
isSameSite = s1;
|
|
54
|
+
isSecure = s2 === 'secure' ? true : false;
|
|
55
|
+
if (process.env.HTTPS !== 'true') {
|
|
56
|
+
isSecure = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
let sConfig = {
|
|
62
|
+
port: process.env.APPPORT,
|
|
63
|
+
host: process.env.APPHOST,
|
|
64
|
+
|
|
65
|
+
state: {
|
|
66
|
+
isSameSite: isSameSite,
|
|
67
|
+
isSecure : isSecure,
|
|
68
|
+
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
routes: {
|
|
73
|
+
payload: {
|
|
74
|
+
maxBytes: maxBytes
|
|
75
|
+
},
|
|
76
|
+
cors: {
|
|
77
|
+
origin : ['*'],
|
|
78
|
+
credentials: true,
|
|
79
|
+
|
|
80
|
+
"headers": ["Accept", "Authorization", "Content-Type", "If-None-Match", "Accept-language"]
|
|
81
|
+
/*
|
|
82
|
+
'Access-Control-Allow-Methods': ['GET', 'POST', 'OPTIONS'],
|
|
83
|
+
additionalHeaders : ['multipart/form-data', 'content-disposition'],
|
|
84
|
+
additionalExposedHeaders : ['location'],
|
|
85
|
+
*/
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
if (process.env.HAPIDEBUG === 'YES') {
|
|
91
|
+
sConfig.debug = { request: '*' };
|
|
92
|
+
}
|
|
93
|
+
debug(JSON.stringify(sConfig, null,4));
|
|
94
|
+
if (process.env.HTTPS === 'true') {
|
|
95
|
+
sConfig.tls = await getCertificates();
|
|
96
|
+
debug('Setup of SSL certificates completed');
|
|
97
|
+
} else {
|
|
98
|
+
debug('Running with no SSL certificates');
|
|
99
|
+
}
|
|
100
|
+
if (asset !== null) {
|
|
101
|
+
sConfig.routes.files= { relativeTo: asset };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
debug2(
|
|
105
|
+
`Application information:
|
|
106
|
+
APPLOC : ${process.env.APPLOC}
|
|
107
|
+
APPENTRY: ${process.env.APPENTRY}
|
|
108
|
+
`
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
let hapiServer = Hapi.server(sConfig);
|
|
112
|
+
|
|
113
|
+
/*
|
|
114
|
+
const cache = hapiServer.cache({ segment: 'sessions', expiresIn: 3 * 24 * 60 * 60 * 1000 });
|
|
115
|
+
hapiServer.app.cache = cache;
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
let nodeCacheOptions = {
|
|
119
|
+
stdTTL : 36000,
|
|
120
|
+
checkPeriod : 3600,
|
|
121
|
+
errorOnMissing: true,
|
|
122
|
+
useClones : false,
|
|
123
|
+
deleteOnExpire: true,
|
|
124
|
+
};
|
|
125
|
+
let storeCache = new NodeCache(nodeCacheOptions);
|
|
126
|
+
hapiServer.app.cache = storeCache;
|
|
127
|
+
|
|
128
|
+
// common plugins
|
|
129
|
+
let visionOptions = {
|
|
130
|
+
engines : { html: require('handlebars') },
|
|
131
|
+
relativeTo: __dirname,
|
|
132
|
+
path : '.',
|
|
133
|
+
};
|
|
134
|
+
await hapiServer.register(Vision);
|
|
135
|
+
hapiServer.views(visionOptions);
|
|
136
|
+
await hapiServer.register(inert);
|
|
137
|
+
if (process.env.HTTPS === 'true') {
|
|
138
|
+
await hapiServer.register({ plugin: require('hapi-require-https'), options: {} });
|
|
139
|
+
}
|
|
140
|
+
// register H202 for proxy handling
|
|
141
|
+
// https://hapi.dev/module/h2o2/api/?v=10.0.1
|
|
142
|
+
|
|
143
|
+
await hapiServer.register(H202);
|
|
144
|
+
/*
|
|
145
|
+
await hapiServer.register({
|
|
146
|
+
plugin : require('hapi-pino'),
|
|
147
|
+
options: {
|
|
148
|
+
prettyPrint: process.env.NODE_ENV !== 'production',
|
|
149
|
+
level : process.env.LOGLEVEL == null ? 'silent' : process.env.LOGLEVEL,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
// setup authentication related plugins
|
|
155
|
+
let options = {
|
|
156
|
+
serverMode : (serverMode === null) ? 'app' : 'api', /* api or app */
|
|
157
|
+
authFlow : process.env.AUTHFLOW,
|
|
158
|
+
host : process.env.VIYA_SERVER,
|
|
159
|
+
isSameSite : isSameSite,
|
|
160
|
+
isSecure : isSecure,
|
|
161
|
+
ns : (allAppEnv.LOGONPAYLOAD != null) ? allAppEnv.LOGONPAYLOAD.ns : null,
|
|
162
|
+
nsHost : (allAppEnv.LOGONPAYLOAD != null) ? allAppEnv.LOGONPAYLOAD.nsHost : null,
|
|
163
|
+
redirect : process.env.REDIRECT,
|
|
164
|
+
clientId : process.env.CLIENTID,
|
|
165
|
+
clientSecret : process.env.CLIENTSECRET,
|
|
166
|
+
redirectTo : `/${process.env.APPNAME}/logon`,
|
|
167
|
+
allAppEnv : allAppEnv,
|
|
168
|
+
useHapiCookie : true,
|
|
169
|
+
appName : process.env.APPNAME,
|
|
170
|
+
appHost : process.env.APPHOST,
|
|
171
|
+
appPort : process.env.APPPORT,
|
|
172
|
+
userRouteTable: userRouteTable,
|
|
173
|
+
useDefault : useDefault, /* not used - left here for potential reuse */
|
|
174
|
+
userInfo : userInfo,
|
|
175
|
+
https : process.env.HTTPS,
|
|
176
|
+
authDefault : false, /* set later in setDefaultRoutes */
|
|
177
|
+
authLogon : false /* set later in setDefaultRoutes */
|
|
178
|
+
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
debug2('Options',options);
|
|
182
|
+
if (process.env.AUTHFLOW != null) {
|
|
183
|
+
await setupAuth(hapiServer, options);
|
|
184
|
+
if (process.env.PREAUTH === 'YES') {
|
|
185
|
+
console.log('Preauth enabled');
|
|
186
|
+
hapiServer.ext('onPreAuth', (request, h) => {
|
|
187
|
+
debugger;
|
|
188
|
+
if (!request.auth.isAuthenticated && !request.path.startsWith(`/login`)) {
|
|
189
|
+
const redirectTo = `${request.path}?${new URLSearchParams(request.query).toString()}`;
|
|
190
|
+
console.log('Redirect to login', {redirectTo});
|
|
191
|
+
debugger;
|
|
192
|
+
return h.redirect(`/login`).takeover();
|
|
193
|
+
}
|
|
194
|
+
return h.continue;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
hapiServer.log('Plugin', process.env.PLUGIN);
|
|
199
|
+
|
|
200
|
+
if (process.env.PLUGIN === 'hapi-swagger' && serverMode !== null) {
|
|
201
|
+
let swaggerOptions = {
|
|
202
|
+
"info": {
|
|
203
|
+
"title" : `API for ${process.env.APPNAME}`,
|
|
204
|
+
"version" : "0.0.1",
|
|
205
|
+
"description": "This document was auto-generated at run time"
|
|
206
|
+
},
|
|
207
|
+
"schemes" : ["http", "https"],
|
|
208
|
+
"cors" : true,
|
|
209
|
+
"debug" : true,
|
|
210
|
+
"jsonPath" : `/${options.appName}/swagger.json`,
|
|
211
|
+
"jsonRoutePath" : `/${options.appName}/swagger.json`,
|
|
212
|
+
"documentationPage": true,
|
|
213
|
+
"documentationPath": `/${options.appName}/documentation`,
|
|
214
|
+
"swaggerUI" : true,
|
|
215
|
+
"swaggerUIPath" : `/${options.appName}/swaggerui`,
|
|
216
|
+
auth : options.authDefault
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
if (userInfo != null) {
|
|
220
|
+
let override = userInfo(options, 'SWAGGEROPTIONS');
|
|
221
|
+
swaggerOptions = {...swaggerOptions, ...override};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
debug('Swagger Options:' ,swaggerOptions);
|
|
225
|
+
await hapiServer.register({ plugin: serverMode, options: swaggerOptions });
|
|
226
|
+
} else if (process.env.PLUGIN == 'hapi-openapi' && serverMode !== null) {
|
|
227
|
+
console.log('hapi-openapi', 'coming soon');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
//
|
|
232
|
+
// Start server
|
|
233
|
+
//
|
|
234
|
+
// eslint-disable-next-line no-unused-vars
|
|
235
|
+
let allRoutes = hapiServer.table();
|
|
236
|
+
await hapiServer.start();
|
|
237
|
+
let hh = hapiServer.info.uri;
|
|
238
|
+
hh = hh.replace(/0.0.0.0/, 'localhost');
|
|
239
|
+
console.log('====================================================================================');
|
|
240
|
+
console.log('Server Start Time: ', Date());
|
|
241
|
+
let msg =
|
|
242
|
+
options.serverMode === 'app'
|
|
243
|
+
? `Visit ${hh}/${process.env.APPNAME} to access application`
|
|
244
|
+
: `Visit ${hh}/${process.env.APPNAME}/api to access swagger`;
|
|
245
|
+
console.log('\x1b[1m%s\x1b[0m',msg);
|
|
246
|
+
console.log('NOTE: If running in container use the exported port');
|
|
247
|
+
process.env.APPSERVER = `${hh}/${process.env.APPNAME}`;
|
|
248
|
+
process.env.HEALTH = 'true';
|
|
249
|
+
console.log('====================================================================================');
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
process.on('unhandledRejection', (err) => {
|
|
253
|
+
console.log(err);
|
|
254
|
+
process.exit(1);
|
|
255
|
+
});
|
|
256
|
+
init();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function getCertificates () {
|
|
260
|
+
|
|
261
|
+
let tls = {};
|
|
262
|
+
debug2('Getting tls certificates');
|
|
263
|
+
debug2('tls.crt', process.env['tls.crt'] != null);
|
|
264
|
+
debug2('tls.key', process.env['tls.key'] != null);
|
|
265
|
+
debug2('TLS_PFX', process.env.TLS_PFX != null);
|
|
266
|
+
debug2('TLS_PW', process.env.TLS_PW != null);
|
|
267
|
+
debug2('TLS_CERT', process.env.TLS_CERT != null);
|
|
268
|
+
debug2('TLS_CRT', process.env.TLS_CRT != null);
|
|
269
|
+
debug2('TLS_CREATE', process.env.TLS_CREATE != null);
|
|
270
|
+
if (process.env.TLS_CERT != null && process.env.TLS_CERT.length > 0) {
|
|
271
|
+
/* backward compatability */
|
|
272
|
+
debug2('TLS set: TLS_CERT');
|
|
273
|
+
tls.cert = fs.readFileSync(process.env.TLS_CERT);
|
|
274
|
+
tls.key = fs.readFileSync(process.env.TLS_KEY);
|
|
275
|
+
} else if (process.env.TLS_PFX != null) {
|
|
276
|
+
debug2('TLS set: PFX');
|
|
277
|
+
tls.pfx = fs.readFileSync(process.env.TLS_PFX);
|
|
278
|
+
if (process.env.TLS_PW != null) {
|
|
279
|
+
tls.passphrase = process.env.TLS_PW;
|
|
280
|
+
}
|
|
281
|
+
} else if (process.env.TLS_CRT != null && process.env.TLS_CRT.trim().length > 0) {
|
|
282
|
+
/* new key names to conform to k8s*/
|
|
283
|
+
debug2('TLS set: TLS_CRT');
|
|
284
|
+
tls.cert = process.env.TLS_CRT;
|
|
285
|
+
tls.key = process.env.TLS_KEY;
|
|
286
|
+
} else if (process.env['tls.crt'] != null) {
|
|
287
|
+
tls.cert = process.env['tls.crt'];
|
|
288
|
+
tls.key = process.env['tls.key'];
|
|
289
|
+
} else if (process.env.TLS_CREATE != null) {
|
|
290
|
+
/* unsigned certificate */
|
|
291
|
+
debug2('TLS set: TLS_CREATE=', process.env.TLS_CREATE);
|
|
292
|
+
tls = await getTls();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (process.env.TLS_CABUNDLE != null) {
|
|
296
|
+
tls.CA = fs.readFileSync(process.env.TLS_CABUNDLE);
|
|
297
|
+
}
|
|
298
|
+
debug2('TLS', tls);
|
|
299
|
+
if (Object.keys(tls).length > 0) {
|
|
300
|
+
return tls;
|
|
301
|
+
} else {
|
|
302
|
+
console.log('Warning: The current host protocol is https: No TLS certificate information has been specified.');
|
|
303
|
+
return tls;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async function getTls () {
|
|
308
|
+
let options = {
|
|
309
|
+
keySize : 2048,
|
|
310
|
+
days : 360,
|
|
311
|
+
algorithm : "sha256",
|
|
312
|
+
clientCertificate: true,
|
|
313
|
+
extensions : {},
|
|
314
|
+
};
|
|
315
|
+
let subjt = process.env.TLS_CREATE.replaceAll('"', '').trim();
|
|
316
|
+
let subj = subjt.split(',');
|
|
317
|
+
|
|
318
|
+
let d = {};
|
|
319
|
+
subj.map(c => {
|
|
320
|
+
let r = c.split(':');
|
|
321
|
+
d[ r[ 0 ] ] = r[ 1 ];
|
|
322
|
+
return { value: r[ 1 ] };
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// TLS_CREATE=C:US,ST:NC,L:Cary,O:SAS Institute,OU:STO,CN:localhost,ALT:na.sas.com
|
|
326
|
+
let attr = [
|
|
327
|
+
{
|
|
328
|
+
name : 'commonName',
|
|
329
|
+
value: d.CN /*process.env.APPHOST*/,
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
name : 'countryName',
|
|
333
|
+
value: d.C
|
|
334
|
+
}, {
|
|
335
|
+
shortName: 'ST',
|
|
336
|
+
value : d.ST
|
|
337
|
+
}, {
|
|
338
|
+
name : 'localityName',
|
|
339
|
+
value: d.L,
|
|
340
|
+
}, {
|
|
341
|
+
name : 'organizationName',
|
|
342
|
+
value: d.O
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
shortName: 'OU',
|
|
346
|
+
value : d.OU
|
|
347
|
+
}
|
|
348
|
+
];
|
|
349
|
+
|
|
350
|
+
options.extensions.altNames = [
|
|
351
|
+
// { type: 6, value: `http://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
|
|
352
|
+
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
|
|
353
|
+
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}/api` },
|
|
354
|
+
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}/logon` },
|
|
355
|
+
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}` },
|
|
356
|
+
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/api` },
|
|
357
|
+
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/logon` },
|
|
358
|
+
];
|
|
359
|
+
debug('tls options ', JSON.stringify(options, null,4));
|
|
360
|
+
let pems = selfsigned.generate(attr, options);
|
|
361
|
+
let tls = {
|
|
362
|
+
cert: pems.cert,
|
|
363
|
+
key : pems.private
|
|
364
|
+
};
|
|
365
|
+
return tls;
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
}
|
|
369
|
+
export default iService;
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ------------------------------------------------------------------------------------
|
|
3
|
+
* * Copyright (c) SAS Institute Inc.
|
|
4
|
+
* * Licensed under the Apache License, Version 2.0 (the 'License');
|
|
5
|
+
* * you may not use this file except in compliance with the License.
|
|
6
|
+
* * You may obtain a copy of the License at
|
|
7
|
+
* *
|
|
8
|
+
* * http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
* *
|
|
10
|
+
* * Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* * distributed under the License is distributed on an 'AS IS' BASIS,
|
|
12
|
+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* * See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
* ----------------------------------------------------------------------------------------
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import "core-js/stable";
|
|
20
|
+
import "regenerator-runtime/runtime";
|
|
21
|
+
import fs from "fs";
|
|
22
|
+
import iService from "./iService";
|
|
23
|
+
import config from "./config";
|
|
24
|
+
let debug = require("debug")("startup");
|
|
25
|
+
|
|
26
|
+
module.exports = function core (
|
|
27
|
+
uTable,
|
|
28
|
+
useDefault,
|
|
29
|
+
serverMode,
|
|
30
|
+
customize,
|
|
31
|
+
swaggerfcn
|
|
32
|
+
) {
|
|
33
|
+
let argv = require("yargs").argv;
|
|
34
|
+
let env = argv.env == null ? null : argv.env;
|
|
35
|
+
let appenv = argv.appenv == null ? null : argv.appenv;
|
|
36
|
+
let docker = argv.docker == null ? null : argv.docker;
|
|
37
|
+
process.env.SERVERMODE = serverMode !== null ? "api" : "app";
|
|
38
|
+
|
|
39
|
+
if (useDefault == null) {
|
|
40
|
+
useDefault = true;
|
|
41
|
+
}
|
|
42
|
+
console.log(
|
|
43
|
+
"Initialization started ============================================================"
|
|
44
|
+
);
|
|
45
|
+
console.log(`version: 2, Build Date: `, Date());
|
|
46
|
+
console.log(
|
|
47
|
+
`\nCommand Line Configuration:
|
|
48
|
+
Dockerfile: ${docker}
|
|
49
|
+
env file : ${env}
|
|
50
|
+
appenv : ${appenv}
|
|
51
|
+
customize : ${customize != null}
|
|
52
|
+
`
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
iapp(null, env, docker, uTable, useDefault, serverMode, customize);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function iapp (
|
|
59
|
+
appSrc,
|
|
60
|
+
rafEnv,
|
|
61
|
+
dockerFile,
|
|
62
|
+
uTable,
|
|
63
|
+
useDefault,
|
|
64
|
+
serverMode,
|
|
65
|
+
customize
|
|
66
|
+
) {
|
|
67
|
+
let asset = setup(rafEnv, dockerFile);
|
|
68
|
+
if (appSrc == null) {
|
|
69
|
+
appSrc = process.env.APPENV == null ? null : process.env.APPENV;
|
|
70
|
+
}
|
|
71
|
+
if (appSrc != null) {
|
|
72
|
+
console.log("appSrc",`+${appSrc}+`);
|
|
73
|
+
createPayload(appSrc, (err, r) => {
|
|
74
|
+
if (err) {
|
|
75
|
+
console.log(err);
|
|
76
|
+
console.log("createPayload failed");
|
|
77
|
+
process.exit(1);
|
|
78
|
+
} else {
|
|
79
|
+
iService(uTable, useDefault, asset, r, serverMode, customize);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
let appEnv = getAllEnv({});
|
|
84
|
+
iService(uTable, useDefault, asset, appEnv, serverMode, customize);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function setup (rafEnv, dockerFile) {
|
|
89
|
+
config(rafEnv, dockerFile);
|
|
90
|
+
let asset = process.env.APPLOC === "." ? process.cwd() : process.env.APPLOC;
|
|
91
|
+
process.env.APPASSET = asset;
|
|
92
|
+
return asset;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function createPayload (srcName, cb) {
|
|
96
|
+
let src = fs.readFileSync(srcName, "utf8");
|
|
97
|
+
if (src === null) {
|
|
98
|
+
cb(`Error: ${srcName} was not found. `);
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
// console.log(src);
|
|
102
|
+
let f = new Function(src);
|
|
103
|
+
console.log(`${srcName} compile completed`);
|
|
104
|
+
let r = f();
|
|
105
|
+
f = null;
|
|
106
|
+
|
|
107
|
+
let ar = getAllEnv(r);
|
|
108
|
+
cb(null, ar);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
console.log(`${srcName} compile failed`);
|
|
111
|
+
cb(err);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getAllEnv (userData) {
|
|
116
|
+
let env;
|
|
117
|
+
let l = null;
|
|
118
|
+
let host = trimit("VIYA_SERVER");
|
|
119
|
+
if (host === 'none'){
|
|
120
|
+
host = null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (process.env.AUTHTYPE != null) {
|
|
124
|
+
process.env.AUTHFLOW = process.env.AUTHTYPE;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let authflow = trimit("AUTHFLOW");
|
|
128
|
+
if (authflow === "authorization_code" || authflow === "code") {
|
|
129
|
+
authflow = "server";
|
|
130
|
+
}
|
|
131
|
+
if (host === null ) {
|
|
132
|
+
authflow = "none";
|
|
133
|
+
}
|
|
134
|
+
process.env.AUTHFLOW = authflow;
|
|
135
|
+
// let redirect = (process.env.REDIRECT != null) ? process.env.REDIRECT : null;
|
|
136
|
+
let redirect = trimit("REDIRECT");
|
|
137
|
+
|
|
138
|
+
let clientID = trimit("CLIENTID");
|
|
139
|
+
|
|
140
|
+
// eslint-disable-next-line no-unused-vars
|
|
141
|
+
let clientSecret = trimit("CLIENTSECRET");
|
|
142
|
+
let keepAlive = trimit("KEEPALIVE");
|
|
143
|
+
let appName = trimit("APPNAME");
|
|
144
|
+
let ns = trimit("NAMESPACE");
|
|
145
|
+
let nsHost = trimit("NSHOST");
|
|
146
|
+
|
|
147
|
+
l = {
|
|
148
|
+
authType: authflow,
|
|
149
|
+
redirect: redirect,
|
|
150
|
+
|
|
151
|
+
host : host,
|
|
152
|
+
clientID: clientID,
|
|
153
|
+
appName : appName,
|
|
154
|
+
|
|
155
|
+
keepAlive: null,
|
|
156
|
+
useToken : process.env.USETOKEN,
|
|
157
|
+
|
|
158
|
+
ns : ns,
|
|
159
|
+
nsHost: nsHost,
|
|
160
|
+
};
|
|
161
|
+
if (authflow === "server" || authflow === "implicit") {
|
|
162
|
+
if (authflow === "implicit") {
|
|
163
|
+
if (redirect === null) {
|
|
164
|
+
redirect = `${appName}/callback`;
|
|
165
|
+
process.env.REDIRECT = "callback";
|
|
166
|
+
} else {
|
|
167
|
+
if (redirect !== null && redirect.indexOf("/") !== 0) {
|
|
168
|
+
redirect =
|
|
169
|
+
redirect.indexOf("http") != -1
|
|
170
|
+
? redirect
|
|
171
|
+
: `${process.env.APPNAME}/${redirect}`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
l = {
|
|
176
|
+
authType : authflow,
|
|
177
|
+
redirect : redirect,
|
|
178
|
+
host : host,
|
|
179
|
+
clientID : clientID,
|
|
180
|
+
appName : appName,
|
|
181
|
+
keepAlive: null,
|
|
182
|
+
useToken : process.env.USETOKEN,
|
|
183
|
+
ns : ns,
|
|
184
|
+
nsHost : nsHost,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
if (authflow === "server" && keepAlive === "YES") {
|
|
188
|
+
let protocol = process.env.HTTPS === "true" ? "https://" : "http://";
|
|
189
|
+
l.keepAlive = `${protocol}${process.env.APPHOST}:${process.env.APPPORT}/${appName}/keepAlive`;
|
|
190
|
+
l.keepAlive = l.keepAlive.replace(/0.0.0.0/, "localhost");
|
|
191
|
+
}
|
|
192
|
+
if (process.env.TIMERS != null) {
|
|
193
|
+
l.timers = process.env.TIMERS;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// allow for no authtype
|
|
197
|
+
l = {
|
|
198
|
+
authType: authflow,
|
|
199
|
+
redirect: redirect,
|
|
200
|
+
|
|
201
|
+
host : host,
|
|
202
|
+
clientID: clientID,
|
|
203
|
+
appName : appName,
|
|
204
|
+
|
|
205
|
+
keepAlive: null,
|
|
206
|
+
useToken : process.env.USETOKEN,
|
|
207
|
+
|
|
208
|
+
ns : ns,
|
|
209
|
+
nsHost: nsHost,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// pick up the app env's - replacement for appenv.js
|
|
214
|
+
// appenv.js still supported for backward compatibility
|
|
215
|
+
for (let key in process.env) {
|
|
216
|
+
debug(key);
|
|
217
|
+
if (key.indexOf("APPENV_") === 0) {
|
|
218
|
+
let k = key.substring(7);
|
|
219
|
+
let v = process.env[key];
|
|
220
|
+
if (v != null && v.trim().length > 0) {
|
|
221
|
+
if (v.startsWith('$')) {
|
|
222
|
+
v = process.env[v.substring(1)];
|
|
223
|
+
}
|
|
224
|
+
userData[k] = (v != null) ? v.trim() : null;
|
|
225
|
+
} else {
|
|
226
|
+
userData[k] = null;
|
|
227
|
+
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
env = {
|
|
233
|
+
LOGONPAYLOAD: l,
|
|
234
|
+
APPENV : userData,
|
|
235
|
+
};
|
|
236
|
+
console.log("Final APPENV configuration for the server");
|
|
237
|
+
console.log(JSON.stringify(env, null, 4));
|
|
238
|
+
console.log(Date());
|
|
239
|
+
return env;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function trimit (e) {
|
|
243
|
+
let a = process.env[e];
|
|
244
|
+
if (a == null) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
a = a.trim();
|
|
248
|
+
return a.length === 0 ? null : a;
|
|
249
|
+
}
|