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

added application.properties for custom properties #60

Merged
merged 7 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -2,16 +2,23 @@

import com.ddd.server.commands.CommandProcessor;
import com.ddd.server.commands.bundleuploader.BundleUploader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import java.io.File;
import java.util.Arrays;
import java.util.Properties;

@Slf4j
@SpringBootApplication
@EnableJpaRepositories("com.ddd.server")
@EntityScan("com.ddd.server.repository.entity")
Expand All @@ -28,7 +35,7 @@ protected void refresh(ConfigurableApplicationContext applicationContext) {
// check for obvious configuration errors
var root = applicationContext.getEnvironment().getProperty("bundle-server.bundle-store-root");
if (root == null || !new File(root).isDirectory()) {
System.err.println("bundle-server.bundle-store-root is not a directory or not set: " + root);
log.error("bundle-server.bundle-store-root is not a directory or not set: " + root);
System.exit(1);
}
super.refresh(applicationContext);
Expand All @@ -42,6 +49,27 @@ protected void refresh(ConfigurableApplicationContext applicationContext) {
app.setLogStartupInfo(false);
}
new BundleUploader().run(args);

if (args.length > 0) {
Resource resource = new FileSystemResource(args[0]);
if (resource.exists()) {
try {
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
app.setDefaultProperties(properties);
args = Arrays.copyOfRange(args, 1, args.length);
} catch (Exception e) {
log.error("Please enter valid properties file path!");
System.exit(1);
}
} else {
log.error("Entered properties file path does not exist!");
System.exit(1);
}
} else {
log.error("Please enter properties file path as argument!");
System.exit(1);
}

app.run(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ private ServerSecurity(String serverRootPath) throws ServerIntializationExceptio
e.printStackTrace();
System.out.printf(
"Error loading server keys. Ensure the following key files exist in your application.yml's " +
"{bundle-server.bundle-security.server-serverkeys-path} path:\n" +
"%s\n" + "server_identity.pub\n" + "serverIdentity.pvt\n" + "server_signed_pre.pub\n" +
"{bundle-server.bundle-security.server-serverkeys-path} path:\n" + "%s\n" +
"server_identity.pub\n" + "serverIdentity.pvt\n" + "server_signed_pre.pub\n" +
"serverSignedPreKey.pvt\n" + "server_ratchet.pub\n" + "serverRatchetKey.pvt\n",
serverKeyPath);
// BundleServerApplication.exit();
Expand Down
4 changes: 2 additions & 2 deletions bundleserver/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ spring:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/dtn_server_db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
username: root
password: ddd2024
# password: <add in external properties file>
db-name: dtn_server_db

server:
port: 8081
bundle-server:
bundle-store-root: "/Users/manaschougule/College/SJSU/DDD-server-storage/"
# bundle-store-root: <add directory path containing key files in external properties file>
bundle-store-shared: "${bundle-server.bundle-store-root}Shared"
registered-app-ids: "${bundle-server.bundle-store-root}Shared/REGISTERED_APP_IDS.txt"
bundle-transmission:
Expand Down