kongにコンシューマを追加する方法を学ぶ。
ここを読みながら
kong コンシューマとは
Consumerオブジェクトは、サービスのコンシューマーまたはユーザーを表します。 Kongをプライマリデータストアとして使用するか、または消費者リストをデータベースにマップして、Kongと既存のプライマリデータストア間の整合性を保つことができます。
https://docs.konghq.com/0.13.x/admin-api/#consumer-object
コンシューマは、サービスを使用する個人に関連付けられ、追跡、アクセス管理などに使用できます
Create a Consumer through the RESTful API
登録前コンシューマ確認
$ curl http://localhost:8001/consumers/
{"next":null,"data":[]}
コンシューマ Jason 登録
$ curl -i -X POST \
--url http://localhost:8001/consumers/ \
--data "username=Jason"
HTTP/1.1 201 Created
:
{
"custom_id":null,
"created_at":1569321722,
"id":"d97459a6-866b-436b-88e4-5ab43dd67da0",
"tags":null,
"username":"Jason"
}
登録後コンシューマ確認
curl http://localhost:8001/consumers/
{"next":null,"data":[{"custom_id":null,"created_at":1569321722,"id":"d97459a6-866b-436b-88e4-5ab43dd67da0","tags":null,"username":"Jason"}]}
Provision key credentials for your Consumer
登録前にコンシューマ Jason の key-auth を確認
$ curl http://localhost:8001/consumers/Jason/key-auth/
{"next":null,"data":[]}
コンシューマ Jason の key-auth を登録
$ curl -i -X POST \
--url http://localhost:8001/consumers/Jason/key-auth/ \
--data 'key=ENTER_KEY_HERE'
HTTP/1.1 201 Created
:
{
"consumer":{"id":"d97459a6-866b-436b-88e4-5ab43dd67da0"},
"created_at":1569322022,
"key":"ENTER_KEY_HERE",
"id":"501b6fcc-428b-4439-86e3-2b20cd18ba4a"
}
登録後にコンシューマ Jason の key-auth を確認
$ curl http://localhost:8001/consumers/Jason/key-auth/ | jq
{
"next": null,
"data": [
{
"key": "ENTER_KEY_HERE",
"created_at": 1569322022,
"consumer": {
"id": "d97459a6-866b-436b-88e4-5ab43dd67da0"
},
"id": "501b6fcc-428b-4439-86e3-2b20cd18ba4a"
}
]
}
Verify that your Consumer credentials are valid
コンシューマ Jason 認証情報の有効性を確認
$ curl -i -X GET \ --url http://localhost:8000 \ --header "Host: example.com" \ --header "apikey: ENTER_KEY_HERE" HTTP/1.1 200 OK : <!DOCTYPE html><html><head><meta charset="utf-8"><title>Mockbin by Kong</title>...
キー誤り
$ curl -i -X GET \
--url http://localhost:8000 \
--header "Host: example.com" \
--header "apikey: qwerqwerqwer"
HTTP/1.1 401 Unauthorized
:
{"message":"Invalid authentication credentials"}
まとめ
- コンシューマ:Jason 登録
- コンシューマ:Jason plugin:key-auth にキーを登録
- コンシューマ:Jason 認証情報の有効性を確認