Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Removes DBI related code, which is no longer needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
alokmenghrajani committed Apr 23, 2015
1 parent b97d33c commit b138d18
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 311 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@
<artifactId>dropwizard-java8-auth</artifactId>
<version>0.8.0-1</version>
</dependency>
<dependency>
<groupId>io.dropwizard.modules</groupId>
<artifactId>dropwizard-java8-jdbi</artifactId>
<version>0.8.0-1</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@
<groupId>io.dropwizard.modules</groupId>
<artifactId>dropwizard-java8-auth</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard.modules</groupId>
<artifactId>dropwizard-java8-jdbi</artifactId>
</dependency>

<!-- Necessary for object type detection. -->
<dependency>
Expand Down
2 changes: 0 additions & 2 deletions server/src/main/java/keywhiz/KeywhizService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.inject.Injector;
import io.dropwizard.Application;
import io.dropwizard.java8.Java8Bundle;
import io.dropwizard.jdbi.bundles.DBIExceptionsBundle;
import io.dropwizard.jersey.setup.JerseyEnvironment;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
Expand Down Expand Up @@ -144,7 +143,6 @@ public void addSecretGenerator(String name, SecretGenerator<?> secretGenerator)
bootstrap.addBundle(new Java8Bundle());
bootstrap.addBundle(new NamedAssetsBundle());
bootstrap.addBundle(new UiAssetsBundle());
bootstrap.addBundle(new DBIExceptionsBundle());
}

@SuppressWarnings("unchecked")
Expand Down
111 changes: 16 additions & 95 deletions server/src/main/java/keywhiz/ServiceModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package keywhiz;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import com.codahale.metrics.jdbi.InstrumentedTimingCollector;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
Expand All @@ -27,17 +24,6 @@
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.db.ManagedDataSource;
import io.dropwizard.java8.auth.Authenticator;
import io.dropwizard.java8.jdbi.DBIFactory;
import io.dropwizard.java8.jdbi.OptionalContainerFactory;
import io.dropwizard.java8.jdbi.args.LocalDateTimeArgumentFactory;
import io.dropwizard.java8.jdbi.args.LocalDateTimeMapper;
import io.dropwizard.java8.jdbi.args.OptionalArgumentFactory;
import io.dropwizard.jdbi.ImmutableListContainerFactory;
import io.dropwizard.jdbi.ImmutableSetContainerFactory;
import io.dropwizard.jdbi.NamePrependingStatementRewriter;
import io.dropwizard.jdbi.args.JodaDateTimeArgumentFactory;
import io.dropwizard.jdbi.args.JodaDateTimeMapper;
import io.dropwizard.jdbi.logging.LogbackLog;
import io.dropwizard.setup.Environment;
import java.sql.SQLException;
import java.time.Clock;
Expand All @@ -49,31 +35,23 @@
import keywhiz.auth.xsrf.Xsrf;
import keywhiz.generators.SecretGeneratorBindingModule;
import keywhiz.generators.TemplatedSecretGenerator;
import keywhiz.jdbi.SanerNamingStrategy;
import keywhiz.service.config.Readonly;
import keywhiz.service.crypto.ContentCryptographer;
import keywhiz.service.crypto.CryptoModule;
import keywhiz.service.crypto.SecretTransformer;
import keywhiz.service.daos.AclDAO;
import keywhiz.service.daos.ClientDAO;
import keywhiz.service.daos.GroupDAO;
import keywhiz.service.daos.MapArgumentFactory;
import keywhiz.service.daos.SecretContentDAO;
import keywhiz.service.daos.SecretController;
import keywhiz.service.daos.SecretDAO;
import keywhiz.service.daos.SecretSeriesDAO;
import org.jooq.DSLContext;
import org.jooq.impl.DSL;
import org.skife.jdbi.v2.ColonPrefixNamedParamStatementRewriter;
import org.skife.jdbi.v2.DBI;
import org.slf4j.LoggerFactory;

import static com.google.common.base.Preconditions.checkNotNull;

public class ServiceModule extends AbstractModule {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ServiceModule.class);
private static final Logger DBI_LOGGER = (Logger) LoggerFactory.getLogger(DBI.class);

private final Environment environment;
private final KeywhizConfig config;

Expand Down Expand Up @@ -134,6 +112,10 @@ public ServiceModule(KeywhizConfig config, Environment environment) {
return dataSource;
}

@Provides ObjectMapper configuredObjectMapper(Environment environment) {
return environment.getObjectMapper();
}

// jOOQ

@Provides @Singleton DSLContext jooqContext(ManagedDataSource dataSource) throws SQLException {
Expand All @@ -146,79 +128,7 @@ public ServiceModule(KeywhizConfig config, Environment environment) {
return DSL.using(dataSource.getConnection());
}

// DBI

@Provides ObjectMapper configuredObjectMapper(Environment environment) {
return environment.getObjectMapper();
}

@Provides @Singleton DBIFactory dbiFactory() {
return new DBIFactory();
}

/**
* Super lame copy of functionality from {@link DBIFactory}. Want both DBI instances to perform
* similarly, however do NOT want a health check of the writable DBI. Failure should allow host
* to remain in rotation of healthy servers since readonly DBI sufficient for critical tasks.
*/
@Provides @Singleton DBI dbi(Environment environment, KeywhizConfig config,
MapArgumentFactory mapArgumentFactory, ManagedDataSource dataSource) throws ClassNotFoundException {
logger.debug("Creating DBI");

DataSourceFactory dataSourceFactory = config.getDataSourceFactory();
final DBI dbi = new DBI(dataSource);
dbi.setSQLLog(new LogbackLog(DBI_LOGGER, Level.TRACE));
dbi.setTimingCollector(new InstrumentedTimingCollector(environment.metrics(),
new SanerNamingStrategy()));
if (dataSourceFactory.isAutoCommentsEnabled()) {
dbi.setStatementRewriter(new NamePrependingStatementRewriter(new ColonPrefixNamedParamStatementRewriter()));
}

dbi.registerArgumentFactory(mapArgumentFactory);
dbi.registerArgumentFactory(
new io.dropwizard.jdbi.args.OptionalArgumentFactory(dataSourceFactory.getDriverClass()));
dbi.registerContainerFactory(new ImmutableListContainerFactory());
dbi.registerContainerFactory(new ImmutableSetContainerFactory());
dbi.registerContainerFactory(new io.dropwizard.jdbi.OptionalContainerFactory());
dbi.registerArgumentFactory(new JodaDateTimeArgumentFactory());
dbi.registerMapper(new JodaDateTimeMapper());
dbi.registerArgumentFactory(new OptionalArgumentFactory(dataSourceFactory.getDriverClass()));
dbi.registerContainerFactory(new OptionalContainerFactory());
dbi.registerArgumentFactory(new LocalDateTimeArgumentFactory());
dbi.registerMapper(new LocalDateTimeMapper());

return dbi;
}

@Provides @Singleton
@Readonly DBI readonlyDbi(KeywhizConfig config, MapArgumentFactory mapArgumentFactory,
@Readonly ManagedDataSource dataSource)
throws ClassNotFoundException {
logger.debug("Creating read-only DBI");
final DBI dbi = new DBI(dataSource);
dbi.registerArgumentFactory(new OptionalArgumentFactory(config.getReadonlyDataSourceFactory().getDriverClass()));
dbi.registerContainerFactory(new OptionalContainerFactory());
dbi.registerArgumentFactory(new LocalDateTimeArgumentFactory());
dbi.registerMapper(new LocalDateTimeMapper());

dbi.registerArgumentFactory(mapArgumentFactory);
return dbi;
}

// DAOs using DBI

@Provides @Singleton @Readonly SecretController readonlySecretController(
SecretTransformer transformer, ContentCryptographer cryptographer,
@Readonly SecretDAO secretDAO) {
return new SecretController(transformer, cryptographer, secretDAO);
}

@Provides @Singleton SecretController secretController(SecretTransformer transformer,
ContentCryptographer cryptographer, SecretDAO secretDAO) {
return new SecretController(transformer, cryptographer, secretDAO);
}

// DAOs using jOOQ
// DAOs

@Provides @Singleton AclDAO aclDAO(DSLContext jooqContext, ClientDAO clientDAO,
GroupDAO groupDAO, SecretContentDAO secretContentDAO,
Expand Down Expand Up @@ -283,6 +193,17 @@ public ServiceModule(KeywhizConfig config, Environment environment) {
return new SecretDAO(jooqContext, secretContentDAO, secretSeriesDAO);
}

@Provides @Singleton SecretController secretController(SecretTransformer transformer,
ContentCryptographer cryptographer, SecretDAO secretDAO) {
return new SecretController(transformer, cryptographer, secretDAO);
}

@Provides @Singleton
@Readonly SecretController readonlySecretController(SecretTransformer transformer,
ContentCryptographer cryptographer, @Readonly SecretDAO secretDAO) {
return new SecretController(transformer, cryptographer, secretDAO);
}

@Provides @Singleton
@Readonly Authenticator<BasicCredentials, User> authenticator(KeywhizConfig config,
@Readonly DSLContext jooqContext) {
Expand Down
32 changes: 0 additions & 32 deletions server/src/main/java/keywhiz/jdbi/SanerNamingStrategy.java

This file was deleted.

66 changes: 0 additions & 66 deletions server/src/main/java/keywhiz/service/daos/BindSecret.java

This file was deleted.

68 changes: 0 additions & 68 deletions server/src/main/java/keywhiz/service/daos/MapArgumentFactory.java

This file was deleted.

0 comments on commit b138d18

Please sign in to comment.