Skip to content

Commit 1798bd7

Browse files
committed
feat: create Secrets.java to contain project secrets
1 parent 6bf34d8 commit 1798bd7

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

  • application/src/main/java/org/togetherjava/tjbot/secrets
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package org.togetherjava.tjbot.secrets;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
7+
8+
import java.io.IOException;
9+
import java.nio.file.Path;
10+
import java.util.Objects;
11+
12+
public class Secrets {
13+
private final String token;
14+
private final String githubApiKey;
15+
private final String logInfoChannelWebhook;
16+
private final String logErrorChannelWebhook;
17+
private final String openaiApiKey;
18+
private final String jshellBaseUrl;
19+
20+
@SuppressWarnings("ConstructorWithTooManyParameters")
21+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
22+
private Secrets(@JsonProperty(value = "token", required = true) String token,
23+
@JsonProperty(value = "githubApiKey", required = true) String githubApiKey,
24+
@JsonProperty(value = "logInfoChannelWebhook",
25+
required = true) String logInfoChannelWebhook,
26+
@JsonProperty(value = "logErrorChannelWebhook",
27+
required = true) String logErrorChannelWebhook,
28+
@JsonProperty(value = "openaiApiKey", required = true) String openaiApiKey,
29+
@JsonProperty(value = "jshellBaseUrl", required = true) String jshellBaseUrl) {
30+
this.token = Objects.requireNonNull(token);
31+
this.githubApiKey = Objects.requireNonNull(githubApiKey);
32+
this.logInfoChannelWebhook = Objects.requireNonNull(logInfoChannelWebhook);
33+
this.logErrorChannelWebhook = Objects.requireNonNull(logErrorChannelWebhook);
34+
this.openaiApiKey = Objects.requireNonNull(openaiApiKey);
35+
this.jshellBaseUrl = Objects.requireNonNull(jshellBaseUrl);
36+
}
37+
38+
public static Secrets load(Path path) throws IOException {
39+
return new ObjectMapper().registerModule(new JavaTimeModule())
40+
.readValue(path.toFile(), Secrets.class);
41+
}
42+
43+
/**
44+
* Gets the token of the Discord bot to connect this application to.
45+
*
46+
* @return the Discord bot token
47+
*/
48+
public String getToken() {
49+
return token;
50+
}
51+
52+
/**
53+
* Gets the API Key of GitHub.
54+
*
55+
* @return the API Key
56+
* @see <a href=
57+
* "https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token">Create
58+
* a GitHub key</a>
59+
*/
60+
public String getGitHubApiKey() {
61+
return githubApiKey;
62+
}
63+
64+
/**
65+
* The Discord channel webhook for posting log messages with levels INFO, DEBUG and TRACE.
66+
*
67+
* @return the webhook URL
68+
*/
69+
public String getLogInfoChannelWebhook() {
70+
return logInfoChannelWebhook;
71+
}
72+
73+
/**
74+
* The Discord channel webhook for posting log messages with levels FATAL, ERROR and WARNING.
75+
*
76+
* @return the webhook URL
77+
*/
78+
public String getLogErrorChannelWebhook() {
79+
return logErrorChannelWebhook;
80+
}
81+
82+
/**
83+
* The OpenAI token needed for communicating with OpenAI ChatGPT.
84+
*
85+
* @return the OpenAI API Token
86+
*/
87+
public String getOpenaiApiKey() {
88+
return openaiApiKey;
89+
}
90+
91+
/**
92+
* The base URL for the jshell REST API.
93+
*
94+
* @return the jshell base url
95+
*/
96+
public String getJshellBaseUrl() {
97+
return jshellBaseUrl;
98+
}
99+
}

0 commit comments

Comments
 (0)