#API_Gateway
راه اندازی API Gateway با Kong
#درحالتکمیل
{توضیحاتی در مورد API Gateway و Kong}
##### Kong start guide
### KONG CORE
# install Kong from repository
# add Kong repository to debian list
# config kong for connect to databse and reply port 8000 and dont reply port 8001 publicaly
# cong configur file put to /etc/kong/kong.conf.default copy this file to kong.conf and edit kong.conf
# save the setting and exit
# initialize Kong to database
# Kong start
# open this url to make sure its work correctly:
# congragulation you start Kong susseccfuly
# for stoping Kong use this command:
برای کانفیگ خود کونگ یک ادمین ای پی ای وجود دارد که فقط از طریق پورت ۸۰۰۱ یا ۸۴۴۴ و از داخل خود سرور (۱۲۷.۰.۰.۱) در دسترس است. برای درست شدن این مشکل میآیید و خود سرویس ادمین کونگ را به عنوان یکی از سرویس های کونگ قرار میدهیم و برایش آتنتیکیشن مینویسییم
تمامی کد های زیر را باید در ترمینال خود دستگاهی که سرویس روی آن ران است بنویسیم
# create admin-api service
در این مرحله باید از طریق ای پی پابلیک سرور در خارج از ان به این سرویس دسترسی داشته باشید و جسون زیر را ببینید
# add basic-auth plugin to admin-api service
# encode the credential
راه اندازی API Gateway با Kong
#درحالتکمیل
{توضیحاتی در مورد API Gateway و Kong}
##### Kong start guide
### KONG CORE
# install Kong from repository
# add Kong repository to debian list
echo "deb [trusted=yes] https://download.konghq.com/gateway-2.x-debian-$(lsb_release -sc)/ default all" | sudo tee /etc/apt/sources.list.d/kong.list# get update
sudo apt-get update# install kong OSS core
sudo apt install -y kong#### isntall postgare database
# config kong for connect to databse and reply port 8000 and dont reply port 8001 publicaly
# cong configur file put to /etc/kong/kong.conf.default copy this file to kong.conf and edit kong.conf
cd /etc/kong#in this file find pg_user (ctrl+w) and set for theis:
cp kong.conf.default kong.conf
nano kong.conf
pg_user = kong# becarful in postgares user and database should be in small case and password is case-sensitive
pg_password = Kong
pg_database = kong
# save the setting and exit
# initialize Kong to database
kong migrations bootstrap [-c /etc/kong/kong.conf]# at the end you should see this message: "Database is up-to-date"
# Kong start
kong start [-c /etc/kong/kong.conf]# see Kong started
# open this url to make sure its work correctly:
http://ServerPublicIP:8000# this json shuold be show: {"message":"no Route matched with those values"}
# congragulation you start Kong susseccfuly
# for stoping Kong use this command:
kong stop### Kong admin-API
برای کانفیگ خود کونگ یک ادمین ای پی ای وجود دارد که فقط از طریق پورت ۸۰۰۱ یا ۸۴۴۴ و از داخل خود سرور (۱۲۷.۰.۰.۱) در دسترس است. برای درست شدن این مشکل میآیید و خود سرویس ادمین کونگ را به عنوان یکی از سرویس های کونگ قرار میدهیم و برایش آتنتیکیشن مینویسییم
تمامی کد های زیر را باید در ترمینال خود دستگاهی که سرویس روی آن ران است بنویسیم
# create admin-api service
curl -X POST http://localhost:8001/services \# create admin-api route
--data name=admin-api \
--data host=localhost \
--data port=8001
curl -X POST http://localhost:8001/services/admin-api/routes \# test new service
--data paths\[\]=/admin-api
در این مرحله باید از طریق ای پی پابلیک سرور در خارج از ان به این سرویس دسترسی داشته باشید و جسون زیر را ببینید
https://serverPublicIP:8443/admin-api# lua_version : ...
# add basic-auth plugin to admin-api service
curl -X POST http://localhost:8001/services/admin-api/plugins \# create a consumer
--data "name=basic-auth" \
--data "config.hide_credentials=true"
curl -d "username=my-user&custom_id=1" http://localhost:8001/consumers/# add password for this consumer
curl -X POST http://localhost:8001/consumers/my-user/basic-auth \# how to access with this consumer
--data "username=my-user" \
--data "password=my-password"
# encode the credential
echo "my-user:my-password" |base64# and make the request:
curl -s -X GET \
--url https://*.*.*.*:8443/admin-api \
--header 'Authorization: Basic ***************='