Skip to content

Commit

Permalink
PXY-860 Add metadata to Plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
framiere committed Jul 11, 2023
1 parent af0c639 commit dd0c182
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@

import org.apache.kafka.common.requests.AbstractRequestResponse;

import java.util.*;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface Plugin {

Expand All @@ -36,4 +44,30 @@ default Map<Class<?>, List<Interceptor<? extends AbstractRequestResponse>>> getT
});
return result;
}

default String readme() {
try {
return resourceAsString("/META-INF/services/README.md");
} catch (Exception e) {
return "";
}
}

private String resourceAsString(String name) throws IOException, URISyntaxException {
return Files.readString(
Paths.get(getClass().getResource(name).toURI()),
Charset.forName("utf-8"));
}

default List<String> examples() {
try {
return List.of(resourceAsString("/META-INF/services/example.json"));
} catch (Exception e) {
return List.of();
}
}

default List<String> tags() {
return List.of();
}
}
14 changes: 13 additions & 1 deletion logger-interceptor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
<artifactId>interceptor-framework</artifactId>
<version>0.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.23.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -31,7 +44,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>

</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.conduktor.example.loggerinterceptor;


import com.google.common.collect.Lists;
import io.conduktor.gateway.interceptor.Interceptor;
import io.conduktor.gateway.interceptor.InterceptorConfigurationException;
import io.conduktor.gateway.interceptor.InterceptorProvider;
Expand Down Expand Up @@ -45,4 +46,8 @@ public List<InterceptorProvider<?>> getInterceptors(Map<String, Object> config)
);
}

@Override
public List<String> tags() {
return List.of("data");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Interceptor

Welcome to Logger interceptor!
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"pluginClass": "io.conduktor.example.loggerinterceptor.LoggerInterceptorPlugin",
"priority": 100,
"config": {
"loggingStyle": "obiWan"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.conduktor.example.loggerinterceptor;

import org.junit.jupiter.api.Test;

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())
.containsExactly("data");
}

@Test
void hasExamples() {
assertThat(new LoggerInterceptorPlugin().examples())
.hasSize(1);
assertThat(new LoggerInterceptorPlugin().examples().get(0))
.contains("\"pluginClass\": \"io.conduktor.example.loggerinterceptor.LoggerInterceptorPlugin\"");

}
}

0 comments on commit dd0c182

Please sign in to comment.