Skip to content

Commit 6ab3538

Browse files
authored
Merge pull request #514 from marle3003/develop
v0.14.2
2 parents 9a8fced + c54b5c1 commit 6ab3538

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1206
-235
lines changed

acceptance/cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Start(cfg *static.Config) (*Cmd, error) {
3939
feature.Enable(cfg.Features)
4040

4141
registerDynamicTypes()
42-
app := runtime.New()
42+
app := runtime.New(cfg)
4343

4444
watcher := server.NewConfigWatcher(cfg)
4545

api/handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
122122
h.getExampleData(w, r)
123123
case p == "/api/schema/validate":
124124
h.validate(w, r)
125+
case strings.HasPrefix(p, "/api/system/"):
126+
h.serveSystem(w, r)
125127
case strings.HasPrefix(p, "/api/configs"):
126128
h.handleConfig(w, r)
127129
case strings.HasPrefix(p, "/api/faker/tree"):

api/handler_events_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ func TestHandler_Events(t *testing.T) {
8989
tc := tc
9090
t.Run(tc.name, func(t *testing.T) {
9191
defer events.Reset()
92-
h := New(runtime.New(), static.Api{})
92+
93+
cfg := &static.Config{}
94+
h := New(runtime.New(cfg), static.Api{})
9395
tc.fn(t, h)
9496
})
9597
}

api/handler_fileserver_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ func TestHandler_FileServer(t *testing.T) {
143143
tc := tc
144144
t.Run(tc.name, func(t *testing.T) {
145145
t.Parallel()
146-
h := api.New(runtime.New(), tc.config)
146+
147+
cfg := &static.Config{}
148+
h := api.New(runtime.New(cfg), tc.config)
147149
tc.fn(t, h)
148150
})
149151
}
@@ -157,7 +159,8 @@ func TestOpenGraphInDashboard(t *testing.T) {
157159
{
158160
name: "http service",
159161
test: func(t *testing.T) {
160-
app := runtime.New()
162+
cfg := &static.Config{}
163+
app := runtime.New(cfg)
161164
app.Http.Add(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0", openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."))})
162165
h := api.New(app, static.Api{Path: "/mokapi", Dashboard: true})
163166
try.Handler(t,
@@ -176,7 +179,8 @@ func TestOpenGraphInDashboard(t *testing.T) {
176179
{
177180
name: "http service path without summary and description",
178181
test: func(t *testing.T) {
179-
app := runtime.New()
182+
cfg := &static.Config{}
183+
app := runtime.New(cfg)
180184
app.Http.Add(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0",
181185
openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."),
182186
openapitest.WithPath("/pet/{petId}", openapitest.NewPath()),
@@ -199,7 +203,8 @@ func TestOpenGraphInDashboard(t *testing.T) {
199203
{
200204
name: "http service path with summary and description",
201205
test: func(t *testing.T) {
202-
app := runtime.New()
206+
cfg := &static.Config{}
207+
app := runtime.New(cfg)
203208
app.Http.Add(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0",
204209
openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."),
205210
openapitest.WithPath("/pet/{petId}", openapitest.NewPath(
@@ -224,7 +229,8 @@ func TestOpenGraphInDashboard(t *testing.T) {
224229
{
225230
name: "http service path with no summary but description",
226231
test: func(t *testing.T) {
227-
app := runtime.New()
232+
cfg := &static.Config{}
233+
app := runtime.New(cfg)
228234
app.Http.Add(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0",
229235
openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."),
230236
openapitest.WithPath("/pet/{petId}", openapitest.NewPath(
@@ -248,7 +254,8 @@ func TestOpenGraphInDashboard(t *testing.T) {
248254
{
249255
name: "http service endpoint no summary and no description",
250256
test: func(t *testing.T) {
251-
app := runtime.New()
257+
cfg := &static.Config{}
258+
app := runtime.New(cfg)
252259
app.Http.Add(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0",
253260
openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."),
254261
openapitest.WithPath("/pet/{petId}", openapitest.NewPath(
@@ -272,7 +279,8 @@ func TestOpenGraphInDashboard(t *testing.T) {
272279
{
273280
name: "http service endpoint get right path",
274281
test: func(t *testing.T) {
275-
app := runtime.New()
282+
cfg := &static.Config{}
283+
app := runtime.New(cfg)
276284
app.Http.Add(&dynamic.Config{Info: dynamic.ConfigInfo{Url: mustParse("https://foo.bar")}, Data: openapitest.NewConfig("3.0",
277285
openapitest.WithInfo("Swagger Petstore", "1.0", "This is a sample server Petstore server."),
278286
openapitest.WithPath("/pet/{petId}", openapitest.NewPath(

api/handler_http_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestHandler_Http(t *testing.T) {
6666
{
6767
name: "get http service info",
6868
app: func() *runtime.App {
69-
app := runtime.New()
69+
app := runtime.New(&static.Config{})
7070
cfg := &dynamic.Config{
7171
Info: dynamictest.NewConfigInfo(), Data: openapitest.NewConfig("3.0.0",
7272
openapitest.WithInfo("foo", "1.0", "bar"),
@@ -320,7 +320,8 @@ func TestHandler_Http(t *testing.T) {
320320
}
321321

322322
func TestHandler_Http_NotFound(t *testing.T) {
323-
h := New(runtime.New(), static.Api{})
323+
cfg := &static.Config{}
324+
h := New(runtime.New(cfg), static.Api{})
324325

325326
try.Handler(t,
326327
http.MethodGet,

api/handler_kafka.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,11 @@ func getKafka(info *runtime.KafkaInfo) kafka {
183183
if ch.Value == nil {
184184
continue
185185
}
186-
t := info.Store.Topic(name)
186+
addr := ch.Value.Address
187+
if addr == "" {
188+
addr = name
189+
}
190+
t := info.Store.Topic(addr)
187191
k.Topics = append(k.Topics, newTopic(info.Store, t, ch.Value, info.DefaultContentType))
188192
}
189193
sort.Slice(k.Topics, func(i, j int) bool {

api/handler_kafka_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestHandler_Kafka(t *testing.T) {
6262
{
6363
name: "get specific",
6464
app: func() *runtime.App {
65-
app := runtime.New()
65+
app := runtime.New(&static.Config{})
6666
cfg := &dynamic.Config{
6767
Info: dynamictest.NewConfigInfo(),
6868
Data: asyncapi3test.NewConfig(
@@ -173,7 +173,7 @@ func TestHandler_Kafka(t *testing.T) {
173173
{
174174
name: "get specific with group",
175175
app: func() *runtime.App {
176-
app := runtime.New()
176+
app := runtime.New(&static.Config{})
177177
app.Kafka.Set("foo", getKafkaInfoWithGroup(asyncapi3test.NewConfig(
178178
asyncapi3test.WithInfo("foo", "bar", "1.0"),
179179
asyncapi3test.WithServer("foo", "kafka", "foo.bar"),
@@ -206,7 +206,7 @@ func TestHandler_Kafka(t *testing.T) {
206206
return t1
207207
}
208208

209-
app := runtime.New()
209+
app := runtime.New(&static.Config{})
210210
app.Kafka.Set("foo", getKafkaInfoWithGroup(asyncapi3test.NewConfig(
211211
asyncapi3test.WithInfo("foo", "bar", "1.0"),
212212
asyncapi3test.WithServer("foo", "kafka", "foo.bar"),
@@ -254,7 +254,7 @@ func TestHandler_Kafka(t *testing.T) {
254254
{
255255
name: "get specific with topic and openapi schema",
256256
app: func() *runtime.App {
257-
app := runtime.New()
257+
app := runtime.New(&static.Config{})
258258
app.Kafka.Set("foo", getKafkaInfo(asyncapi3test.NewConfig(
259259
asyncapi3test.WithInfo("foo", "bar", "1.0"),
260260
asyncapi3test.WithChannel("foo",
@@ -294,7 +294,7 @@ func TestHandler_Kafka(t *testing.T) {
294294
}
295295

296296
func TestHandler_Kafka_NotFound(t *testing.T) {
297-
h := New(runtime.New(), static.Api{})
297+
h := New(runtime.New(&static.Config{}), static.Api{})
298298

299299
try.Handler(t,
300300
http.MethodGet,

api/handler_ldap_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestHandler_Ldap(t *testing.T) {
3232
{
3333
name: "get ldap services",
3434
app: func() *runtime.App {
35-
app := runtime.New()
35+
app := runtime.New(&static.Config{})
3636
app.Ldap.Set("foo", &runtime.LdapInfo{
3737
Config: &directory.Config{Info: directory.Info{Name: "foo", Description: "bar", Version: "1.0"}},
3838
})
@@ -45,7 +45,7 @@ func TestHandler_Ldap(t *testing.T) {
4545
{
4646
name: "get ldap service",
4747
app: func() *runtime.App {
48-
app := runtime.New()
48+
app := runtime.New(&static.Config{})
4949
cfg := &dynamic.Config{
5050
Info: dynamictest.NewConfigInfo(),
5151
Data: &directory.Config{

api/handler_smtp_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestHandler_Smtp(t *testing.T) {
4040
{
4141
name: "get smtp services",
4242
app: func() *runtime.App {
43-
app := runtime.New()
43+
app := runtime.New(&static.Config{})
4444
app.Mail.Set("foo", &runtime.MailInfo{
4545
Config: &mail.Config{Info: mail.Info{Name: "foo", Description: "bar", Version: "1.0"}},
4646
Store: &mail.Store{},
@@ -54,7 +54,7 @@ func TestHandler_Smtp(t *testing.T) {
5454
{
5555
name: "/api/services/smtp",
5656
app: func() *runtime.App {
57-
app := runtime.New()
57+
app := runtime.New(&static.Config{})
5858
app.Mail.Set("foo", &runtime.MailInfo{
5959
Config: &mail.Config{Info: mail.Info{Name: "foo"}},
6060
Store: &mail.Store{},
@@ -68,7 +68,7 @@ func TestHandler_Smtp(t *testing.T) {
6868
{
6969
name: "get smtp service",
7070
app: func() *runtime.App {
71-
app := runtime.New()
71+
app := runtime.New(&static.Config{})
7272
cfg := &dynamic.Config{
7373
Info: dynamictest.NewConfigInfo(),
7474
Data: &mail.Config{
@@ -88,7 +88,7 @@ func TestHandler_Smtp(t *testing.T) {
8888
{
8989
name: "get smtp service with mailbox",
9090
app: func() *runtime.App {
91-
app := runtime.New()
91+
app := runtime.New(&static.Config{})
9292
app.Mail.Set("foo", &runtime.MailInfo{
9393
Config: &mail.Config{
9494
Info: mail.Info{Name: "foo"},
@@ -113,7 +113,7 @@ func TestHandler_Smtp(t *testing.T) {
113113
{
114114
name: "get smtp service with rules",
115115
app: func() *runtime.App {
116-
app := runtime.New()
116+
app := runtime.New(&static.Config{})
117117
app.Mail.Set("foo", &runtime.MailInfo{
118118
Config: &mail.Config{
119119
Info: mail.Info{Name: "foo"},
@@ -136,7 +136,7 @@ func TestHandler_Smtp(t *testing.T) {
136136
{
137137
name: "get smtp mailbox",
138138
app: func() *runtime.App {
139-
app := runtime.New()
139+
app := runtime.New(&static.Config{})
140140
app.Mail.Set("foo", &runtime.MailInfo{
141141
Config: &mail.Config{
142142
Info: mail.Info{Name: "foo"},
@@ -175,7 +175,7 @@ func TestHandler_Smtp(t *testing.T) {
175175
{
176176
name: "get smtp mail",
177177
app: func() *runtime.App {
178-
app := runtime.New()
178+
app := runtime.New(&static.Config{})
179179
app.Mail.Set("foo", &runtime.MailInfo{
180180
Config: &mail.Config{
181181
Info: mail.Info{Name: "foo"},
@@ -215,7 +215,7 @@ func TestHandler_Smtp(t *testing.T) {
215215
{
216216
name: "get smtp mail attachment content",
217217
app: func() *runtime.App {
218-
app := runtime.New()
218+
app := runtime.New(&static.Config{})
219219
app.Mail.Set("foo", &runtime.MailInfo{
220220
Config: &mail.Config{
221221
Info: mail.Info{Name: "foo"},

api/handler_system.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package api
2+
3+
import (
4+
"mokapi/runtime/events"
5+
"net/http"
6+
"strings"
7+
)
8+
9+
func (h *handler) serveSystem(w http.ResponseWriter, r *http.Request) {
10+
segments := strings.Split(r.URL.Path, "/")
11+
if len(segments) == 4 && segments[3] == "events" {
12+
traits := events.NewTraits()
13+
for k := range r.URL.Query() {
14+
traits.With(k, r.URL.Query().Get(k))
15+
}
16+
17+
data := events.GetStores(traits)
18+
if data == nil {
19+
w.WriteHeader(404)
20+
} else {
21+
w.Header().Set("Content-Type", "application/json")
22+
writeJsonBody(w, data)
23+
}
24+
} else {
25+
w.WriteHeader(404)
26+
return
27+
}
28+
}

0 commit comments

Comments
 (0)