-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (57 loc) · 1.63 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"fmt"
"github.com/kong/go-kong/kong"
)
func main() {
fmt.Println("Reproducing bug...")
CallingCorrectKongPort()
CallingIncorrectKongPort()
}
func CallingCorrectKongPort() {
fmt.Println("Calling AdminAPI in Port 8001")
correctKongHost := "http://localhost:8001"
kongAdmClient := CreateKongAdminClient(&correctKongHost)
ctx := context.Background()
plugin := GetSamplePlugin()
result, msg, err := kongAdmClient.Plugins.Validate(ctx, plugin)
if err != nil {
panic("error validating plugin")
}
fmt.Println(fmt.Sprintf("validation of %s", *plugin.Name))
fmt.Println(fmt.Sprintf("result: %v", result))
fmt.Println(fmt.Sprintf("message: %s", msg))
}
func CallingIncorrectKongPort() {
fmt.Println("Calling AdminAPI in Port 9000")
incorrectKongHost := "http://localhost:9001"
kongAdmClient := CreateKongAdminClient(&incorrectKongHost)
ctx := context.Background()
plugin := GetSamplePlugin()
result, msg, err := kongAdmClient.Plugins.Validate(ctx, plugin)
if err != nil {
panic("error validating plugin")
}
// code not reached
fmt.Println(fmt.Sprintf("validation of %s", *plugin.Name))
fmt.Println(fmt.Sprintf("result: %v", result))
fmt.Println(fmt.Sprintf("message: %s", msg))
}
func CreateKongAdminClient(host *string) *kong.Client {
kongAdmClient, err := kong.NewClient(host, nil)
if err != nil {
panic("error creating kong admin client")
}
return kongAdmClient
}
func GetSamplePlugin() *kong.Plugin {
name := "correlation-id"
enabled := true
configuration := make(map[string]interface{})
return &kong.Plugin{
Name: &name,
Config: configuration,
Enabled: &enabled,
}
}