Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PXY-860 Add metadata to Plugins #67

Merged
merged 5 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration is done by yaml from configuration file in gateway. Maybe we should provide multiple configuration files.

Also if multiple plugins (let's say 2) are loaded in the classpath and each ref a /META-INF/services/example.json what happen ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, addressed here: 84033e0

} 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\"");

}
}