-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from conduktor/framiere/PXY-860
PXY-860 Add metadata to Plugins
- Loading branch information
Showing
8 changed files
with
199 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...rceptor-framework/src/main/java/io/conduktor/gateway/interceptor/MarkdownHeadersUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.conduktor.gateway.interceptor; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class MarkdownHeadersUtil { | ||
private static final Pattern pattern = Pattern.compile("\\s*([^\\s]+):\\s*(.*+)", Pattern.MULTILINE); | ||
public static final String HEADER_SEPARATOR = "---"; | ||
|
||
public Map<String, String> extractHeaders(String markdown) { | ||
String headers = markdownHeaders(markdown); | ||
Matcher matcher = pattern.matcher(headers); | ||
Map<String, String> ret = new HashMap<>(); | ||
while (matcher.find()) { | ||
ret.put(matcher.group(1), matcher.group(2)); | ||
} | ||
return ret; | ||
} | ||
|
||
@NotNull | ||
private String markdownHeaders(String v) { | ||
int first = v.indexOf(HEADER_SEPARATOR); | ||
if (first == -1) { | ||
return ""; | ||
} | ||
String newStr = v.substring(first + HEADER_SEPARATOR.length()); | ||
int second = newStr.indexOf(HEADER_SEPARATOR); | ||
if (second == -1) { | ||
return ""; | ||
} | ||
|
||
return v.substring(first + HEADER_SEPARATOR.length(), second + first + HEADER_SEPARATOR.length()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...tor-framework/src/test/java/io/conduktor/gateway/interceptor/MarkdownHeadersUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.conduktor.gateway.interceptor; | ||
|
||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class MarkdownHeadersUtilTest { | ||
@Test | ||
public void validHeader() { | ||
assertThat(new MarkdownHeadersUtil().extractHeaders(""" | ||
--- | ||
version: 1.0.1-SNAPSHOT | ||
title: Virtual SQL Topic | ||
description: Don't reinvent the wheel to filter and project your messages, just use SQL! | ||
parent: safeguard | ||
--- | ||
# Interceptor""")) | ||
.containsExactlyInAnyOrderEntriesOf(Map.of( | ||
"version", "1.0.1-SNAPSHOT", | ||
"title", "Virtual SQL Topic", | ||
"description", "Don't reinvent the wheel to filter and project your messages, just use SQL!", | ||
"parent", "safeguard" | ||
)); | ||
} | ||
|
||
@Test | ||
public void emptyHeaders() { | ||
assertThat(new MarkdownHeadersUtil().extractHeaders(""" | ||
--- | ||
--- | ||
# Interceptor""")) | ||
.isEmpty(); | ||
} | ||
|
||
@Test | ||
public void emptyHeader() { | ||
assertThat(new MarkdownHeadersUtil().extractHeaders(""" | ||
--- | ||
version: | ||
--- | ||
# Interceptor""")) | ||
.containsAllEntriesOf(Map.of( | ||
"version", "" | ||
)); | ||
} | ||
|
||
@Test | ||
public void noHeader() { | ||
assertThat(new MarkdownHeadersUtil().extractHeaders(""" | ||
# Interceptor""")) | ||
.isEmpty(); | ||
} | ||
|
||
@Test | ||
public void unclosedHeader() { | ||
assertThat(new MarkdownHeadersUtil().extractHeaders(""" | ||
--- | ||
title: Virtual SQL Topic | ||
# Interceptor""")) | ||
.isEmpty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
logger-interceptor/src/main/resources/META-INF/services/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
version: 1.0.1-SNAPSHOT | ||
title: Virtual SQL Topic | ||
description: Don't reinvent the wheel to filter and project your messages, just use SQL! | ||
parent: safeguard | ||
--- | ||
# Interceptor | ||
|
||
Welcome to Logger interceptor! |
26 changes: 26 additions & 0 deletions
26
...tor/src/test/java/io/conduktor/example/loggerinterceptor/LoggerInterceptorPluginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.conduktor.example.loggerinterceptor; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class LoggerInterceptorPluginTest { | ||
@Test | ||
void hasReadme() { | ||
assertThat(new LoggerInterceptorPlugin().readme()) | ||
.contains("Welcome to Logger interceptor!"); | ||
} | ||
|
||
@Test | ||
void hasTags() { | ||
assertThat(new LoggerInterceptorPlugin().tags()) | ||
.containsExactlyInAnyOrderEntriesOf(Map.of( | ||
"version", "1.0.1-SNAPSHOT", | ||
"title", "Virtual SQL Topic", | ||
"description", "Don't reinvent the wheel to filter and project your messages, just use SQL!", | ||
"parent", "safeguard" | ||
)); | ||
} | ||
} |