Merge pull request #51 from Fashionscape/postgres
Secret Management and Log Enhancement
This commit is contained in:
commit
175bab19b6
@ -23,6 +23,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'org.xerial:sqlite-jdbc:3.36.0.2'
|
||||
implementation 'org.postgresql:postgresql:42.2.24'
|
||||
implementation 'com.github.Kaaz:ConfigurationBuilder:0.4'
|
||||
implementation 'org.javacord:javacord:3.3.2'
|
||||
implementation 'com.vdurmont:emoji-java:5.1.1'
|
||||
@ -32,8 +33,13 @@ dependencies {
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.5.4'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web:2.5.4'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.4'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.5.4'
|
||||
|
||||
implementation platform('com.google.cloud:libraries-bom:23.0.0')
|
||||
implementation 'com.google.cloud:google-cloud-secretmanager'
|
||||
|
||||
|
||||
testImplementation group: 'junit', name: 'junit', version: '4.12'
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
package dev.salmonllama.fsbot;
|
||||
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import dev.salmonllama.fsbot.config.SecretManager;
|
||||
import dev.salmonllama.fsbot.database.FSDB;
|
||||
import dev.salmonllama.fsbot.guthix.Guthix;
|
||||
import dev.salmonllama.fsbot.listeners.*;
|
||||
@ -23,11 +24,11 @@ public class Main {
|
||||
private final static Logger logger = LoggerFactory.getLogger(Main.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
BotConfig.initConfig(Constants.BOT_FOLDER, false);
|
||||
BotConfig.initConfig(Constants.BOT_FOLDER, false); // TODO: Sunset the bot config once and for all
|
||||
|
||||
FSDB.init();
|
||||
|
||||
new DiscordApiBuilder().setToken(BotConfig.TOKEN).login().thenAccept(api -> {
|
||||
new DiscordApiBuilder().setToken(SecretManager.DISCORD_TOKEN.getPlainText()).login().thenAccept(api -> {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
Guthix guthix = new Guthix(api);
|
||||
|
@ -18,8 +18,7 @@ public class ColorCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
ctx.getApi().getOwner().thenAcceptAsync(owner -> {
|
||||
ctx.reply("This command is no longer active. An alternative is currently being developed. For more information, please contact " + owner.getDiscriminatedName());
|
||||
});
|
||||
ctx.reply("This command is no longer active. An alternative is currently being developed. For more information, please contact Salmonllama#7233");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,6 @@ public class ColorsCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
ctx.getApi().getOwner().thenAcceptAsync(owner -> {
|
||||
ctx.reply("This command is no longer active. An alternative is currently being developed. For more information, please contact " + owner.getDiscriminatedName());
|
||||
});
|
||||
ctx.reply("This command is no longer active. An alternative is currently being developed. For more information, please contact Salmonllama#7233");
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ public class RemoveOutfitCommand extends Command {
|
||||
|
||||
EmbedBuilder log = new EmbedBuilder()
|
||||
.setTitle("Outfit Marked as Deleted")
|
||||
.setFooter(outfit.getId())
|
||||
.setThumbnail(outfit.getLink())
|
||||
.setColor(Color.RED)
|
||||
.addField("Deleted By:", ctx.getAuthor().getDiscriminatedName());
|
||||
|
@ -73,6 +73,7 @@ public class RestoreOutfitCommand extends Command {
|
||||
|
||||
EmbedBuilder log = new EmbedBuilder()
|
||||
.setTitle("Outfit Restored as Active")
|
||||
.setFooter(outfit.getId())
|
||||
.setThumbnail(outfit.getLink())
|
||||
.setColor(Color.BLUE)
|
||||
.addField("Restored By:", ctx.getAuthor().getDiscriminatedName());
|
||||
|
@ -76,6 +76,7 @@ public class RetagCommand extends Command {
|
||||
|
||||
EmbedBuilder log = new EmbedBuilder()
|
||||
.setTitle("Outfit Retagged")
|
||||
.setFooter(outfit.getId())
|
||||
.setColor(Color.YELLOW)
|
||||
.setThumbnail(outfit.getLink())
|
||||
.addField("New tag:", newTag);
|
||||
|
@ -15,16 +15,13 @@ import java.nio.file.Paths;
|
||||
|
||||
public class BotConfig {
|
||||
@ConfigurationOption
|
||||
public static String TOKEN = "token-goes-here";
|
||||
public static String DB_ADDR = "SQLite connection address here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String DB_ADDR = "fsbot.db";
|
||||
public static String DB_NAME = "SQLite database name here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String DB_NAME = "fsbot";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String DEFAULT_PREFIX = "~";
|
||||
public static String DEFAULT_PREFIX = "default prefix here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String BOT_OWNER = "owner's id here";
|
||||
@ -68,12 +65,6 @@ public class BotConfig {
|
||||
@ConfigurationOption
|
||||
public static String MEMBER_ROLE = "member role id here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String IMGUR_ID = "imgur_id_here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String IMGUR_BEARER = "imgur bearer here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String DEFAULT_REACTION = ":heartpulse:";
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
package dev.salmonllama.fsbot.config;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.google.cloud.secretmanager.v1.SecretManagerServiceClient;
|
||||
|
||||
public enum SecretManager {
|
||||
DISCORD_TOKEN ("projects/fashionscapers-212707/secrets/fs_discord_token/versions/1"),
|
||||
IMGUR_ID ("projects/fashionscapers-212707/secrets/fs_imgur_client_id/versions/1"),
|
||||
IMGUR_BEARER ("projects/fashionscapers-212707/secrets/fs_imgur_bearer_token/versions/1")
|
||||
;
|
||||
|
||||
private final String resourceId;
|
||||
|
||||
SecretManager(String resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public String getPlainText() {
|
||||
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
|
||||
return client.accessSecretVersion(this.resourceId).getPayload().getData().toStringUtf8();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // TODO: Add plain text error message to log to console
|
||||
System.exit(1); // Secrets are integral to full operation, crash if not retrieved properly.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
|
||||
package dev.salmonllama.fsbot.endpoints.imgur;
|
||||
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import dev.salmonllama.fsbot.config.SecretManager;
|
||||
import okhttp3.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -22,8 +22,8 @@ public class ImgurAPIConnection {
|
||||
private final Request.Builder requestBuilder;
|
||||
|
||||
public ImgurAPIConnection() {
|
||||
CLIENT_ID = BotConfig.IMGUR_ID;
|
||||
BEARER_TOKEN = BotConfig.IMGUR_BEARER;
|
||||
CLIENT_ID = SecretManager.IMGUR_ID.getPlainText();
|
||||
BEARER_TOKEN = SecretManager.IMGUR_BEARER.getPlainText();
|
||||
|
||||
client = new OkHttpClient().newBuilder().build();
|
||||
requestBuilder = new Request.Builder();
|
||||
|
Loading…
Reference in New Issue
Block a user