Skip to content

Commit 76edf92

Browse files
Added CONNECT_TOKEN env var (#19)
Co-authored-by: NixNux123 <[email protected]>
1 parent 3f93019 commit 76edf92

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

core/src/main/java/com/minekube/connect/module/CommonModule.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,19 @@ private static class Token {
157157
@SerializedName("token") final String token;
158158

159159
static Optional<String> load(Path tokenFile) throws IOException {
160-
if (Files.exists(tokenFile)) {
161-
// Read existing token file
162-
try (Reader reader = Files.newBufferedReader(tokenFile)) {
163-
return Optional.ofNullable(new Gson().fromJson(reader, Token.class))
164-
.map(t -> t.token);
160+
String TOKEN_ENV = System.getenv("CONNECT_TOKEN");
161+
if (TOKEN_ENV != null && !TOKEN_ENV.isEmpty()) {
162+
return Optional.of(TOKEN_ENV);
163+
} else {
164+
if (Files.exists(tokenFile)) {
165+
// Read existing token file
166+
try (Reader reader = Files.newBufferedReader(tokenFile)) {
167+
return Optional.ofNullable(new Gson().fromJson(reader, Token.class))
168+
.map(t -> t.token);
169+
}
165170
}
171+
return Optional.empty();
166172
}
167-
return Optional.empty();
168173
}
169174

170175
static void save(Path tokenFile, String token) throws IOException {

0 commit comments

Comments
 (0)