Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
update pom with dm's
update bundle with conf
  • Loading branch information
chaitanyachavali committed Nov 18, 2020
1 parent 79a04f7 commit 0c25bba
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 13 deletions.
50 changes: 40 additions & 10 deletions README.md
@@ -1,17 +1,47 @@
# dropwizard-filter-bundle
A small dropwizard bundle to filter resources based on mode supplied

## What does it do?
This bundle essentially restricts/allows the API based on mode supplied

#### Modes available:
- `READ_ONLY`
- Allows only `GET` resources
- `READ_WRITE`
- Allows all resources

#### Additional options:
- There might cases where we end up having a read-only API with `POST` method, cases when we have a request body for filter params and so on. In these scenarios you can annotate specific resource with `@ReadOnlyAPI` which discounts the `HttpMethod` and allows all requests even incase of `READ_ONLY` mode.


## Usage
Add the repository
```xml
<repository>
<id>clojars</id>
<name>Clojars repository</name>
<url>https://clojars.org/repo</url>
</repository>
```
@Override
public void initialize(final Bootstrap...) {
bootstrap.addBundle(new ResourceFilterBundle() {
public boolean withMode() {
return FilterMode.READ_WRITE;
}
});
}

Add the dependency
```xml
<dependency>
<groupId>com.chaitanyachavali.dropwizard</groupId>
<artifactId>dropwizard-filters-bundle</artifactId>
<version>1.0.0</version>
</dependency>
```

Add the bundle to your application
```
@Override
public void initialize(Bootstrap bootstrap) {
bootstrap.addBundle(new ResourceFilterBundle<ApplicationConfiguration>() {
@Override
public FilterMode withMode(ApplicationConfiguration conf) {
return conf.getFilterMode();
}
});
}
```
34 changes: 33 additions & 1 deletion pom.xml
Expand Up @@ -6,7 +6,8 @@

<groupId>com.chaitanyachavali.dropwizard</groupId>
<artifactId>dropwizard-filters-bundle</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0</version>
<packaging>jar</packaging>

<properties>
<dropwizard.version>1.3.27</dropwizard.version>
Expand All @@ -21,4 +22,35 @@
</dependency>
</dependencies>

<developers>
<developer>
<id>chaitanyachavali</id>
<name>Chaitanya Reddy</name>
<email>chavalichaithanyachinna@gmail.com</email>
</developer>
</developers>

<scm>
<connection>scm:git:https://github.com/Chaitanyachavali/dropwizard-filter-bundle.git</connection>
<developerConnection>scm:git:https://github.com/Chaitanyachavali/dropwizard-filter-bundle.git</developerConnection>
<tag>HEAD</tag>
<url>https://github.com/Chaitanyachavali/dropwizard-filter-bundle.git</url>
</scm>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>

<distributionManagement>
<repository>
<id>clojars</id>
<name>Clojars repository</name>
<url>https://clojars.org/repo</url>
</repository>
</distributionManagement>
</project>
Expand Up @@ -19,15 +19,21 @@
import com.chaitanyachavali.dropwizard.features.ReadWriteDynamicFeature;
import io.dropwizard.Configuration;
import io.dropwizard.ConfiguredBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;

public abstract class ResourceFilterBundle<T extends Configuration> implements ConfiguredBundle<T> {

public abstract FilterMode withMode();
public abstract FilterMode withMode(T configuration);

public void run(T configuration, Environment environment) {
FilterMode effectiveMode = withMode() == null ? FilterMode.READ_WRITE : withMode();
FilterMode effectiveMode = withMode(configuration) == null
? FilterMode.READ_WRITE
: withMode(configuration);
environment.jersey().register(new ReadWriteDynamicFeature(effectiveMode));
}

public void initialize(Bootstrap<?> bootstrap) {
}

}

0 comments on commit 0c25bba

Please sign in to comment.