Move the database file location to the commandline so that the config files inside the JAR shouldn't matter to end-users

This commit is contained in:
skogaby
2019-04-12 19:52:39 -05:00
parent d92e3eb89f
commit 8a5d537d94
7 changed files with 14 additions and 22 deletions

View File

@@ -54,9 +54,6 @@ public class HibernateConfiguration {
@Value("${hibernate.show_sql}")
private String showSql;
@Value("${hibernate.db_path}")
private String databasePath;
@Bean
public LocalSessionFactoryBean sessionFactory(final DriverManagerDataSource dataSource) {
final Properties hibernateProperties = new Properties();
@@ -81,7 +78,8 @@ public class HibernateConfiguration {
// locate the database in the user directory, and replace backslashes with forward slashes so it works on
// Windows correctly, per sqlite-jdbc's spec
source.setUrl("jdbc:sqlite:" + this.databasePath.replace('\\', '/'));
final String dbPath = System.getProperty("db_path");
source.setUrl("jdbc:sqlite:" + dbPath.replace('\\', '/'));
return source;
}

View File

@@ -4,5 +4,4 @@ jdbc.password =
hibernate.hbm2ddl.auto = update
hibernate.dialect = com.buttongames.butterflydao.hibernate.SQLiteDialect
hibernate.show_sql = false
hibernate.db_path = /home/ec2-user/butterfly.sqlite
hibernate.show_sql = false

View File

@@ -56,3 +56,11 @@ buildscript {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}
run {
if (project.hasProperty("appArgs")) {
args Eval.me(appArgs)
}
systemProperties System.getProperties()
}

View File

@@ -324,12 +324,13 @@ public class ButterflyHttpServer {
Machine machine = this.machineDao.findByPcbId(requestBodyPcbId);
if (machine == null) {
// create a machine and ban them, unban manually if you want to
// create a machine and leave them enabled, ban them later if you want or change this
// to ban-by-default
final LocalDateTime now = LocalDateTime.now();
final ButterflyUser newUser = new ButterflyUser("0000", now, now, 10000);
userDao.create(newUser);
machine = new Machine(newUser, requestBodyPcbId, LocalDateTime.now(), false, 0);
machine = new Machine(newUser, requestBodyPcbId, LocalDateTime.now(), true, 0);
machineDao.create(machine);
throw new InvalidPcbIdException();

View File

@@ -86,18 +86,6 @@ public abstract class BaseRequestHandler {
respBytes = PublicKt.kbinEncode(new String(respBytes));
}
// compress if needed
/*final String compressionScheme = request.headers(COMPRESSION_HEADER);
if (!StringUtils.isBlank(compressionScheme) &&
compressionScheme.equals(LZ77_COMPRESSION)) {
respBytes = Lz77.compress(respBytes);
response.header(COMPRESSION_HEADER, LZ77_COMPRESSION);
} else {
response.header(COMPRESSION_HEADER, "none");
}*/
// TODO: For some reason this is breaking on very large responses (i.e. events). Fix later, leave uncompressed for now.
response.header(COMPRESSION_HEADER, "none");
// encrypt if needed

View File

@@ -8,5 +8,4 @@ public class PropertyNames {
public static final String PORT = "${server.port}";
public static final String MAINT_MODE = "${server.maintenance}";
public static final String HOME_DIR = "${server.home_dir}";
}

View File

@@ -1,4 +1,3 @@
# Server properties
server.port = 80
server.maintenance = false
server.home_dir = /home/ec2-user/