چرک نویس برنامه نویس
2 subscribers
3 files
23 links
در اینجا هر چی که پیدا می کنم و بدرد بخوره رو قرار میدم و توضیح کوتاهی هم در موردش میدم
Download Telegram
#API_Gateway
راه اندازی 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
cp kong.conf.default kong.conf
nano kong.conf
#in this file find pg_user (ctrl+w) and set for theis:

pg_user = kong 
pg_password = Kong
pg_database = kong
# becarful in postgares user and database should be in small case and password is case-sensitive
# 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 \
--data name=admin-api \
--data host=localhost \
--data port=8001


# create admin-api route
curl -X POST http://localhost:8001/services/admin-api/routes \
--data paths\[\]=/admin-api


# test new service
در این مرحله باید از طریق ای پی پابلیک سرور در خارج از ان به این سرویس دسترسی داشته باشید و جسون زیر را ببینید
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 \
--data "name=basic-auth" \
--data "config.hide_credentials=true"


# create a consumer
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 \
--data "username=my-user" \
--data "password=my-password"


# how to access with this consumer
# 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 ***************='