Skip to content

Commit 9977dcf

Browse files
committed
Search for GOOGLE_APPLICATION_CREDENTIALS
1 parent 08c3c91 commit 9977dcf

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ lavalink:
1616
1717
# Configuration
1818
The plugin exposes these configuration options
19-
<br><b>NOTE:</b> this plugins block is a root level object, don't place it where you import the plugin
19+
<br><b>NOTE:</b> This plugins block is a root level object, don't place it where you import the plugin
20+
<br><b>NOTE:</b> The double quotes are required for the private key
21+
<br><b>NOTE:</b> Having a `GOOGLE_APPLICATION_CREDENTIALS` env var set with the path to your credentials file overrides these settings
2022
```yml
2123
plugins:
2224
dunctebot:
2325
tts:
24-
clientEmail: '' # The client_email from your service account json
25-
privateKey: '' # The private_key from your service account json
26+
clientEmail: "" # The client_email from your service account json
27+
privateKey: "" # The private_key from your service account json
2628
```
2729

2830
# Usage

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group "com.dunctebot"
10-
version "1.0.0"
10+
version "1.0.1"
1111
mainClassName = "org.springframework.boot.loader.JarLauncher"
1212
sourceCompatibility = 11
1313
compileJava.options.encoding = "UTF-8"

src/main/java/com/dunctebot/tss/TTSPlugin.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.dunctebot.tss;
22

33
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
4+
import com.sedmelluq.discord.lavaplayer.tools.JsonBrowser;
45
import dev.arbjerg.lavalink.api.AudioPlayerManagerConfiguration;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
78
import org.springframework.stereotype.Service;
89
import org.springframework.util.StringUtils;
910

11+
import java.io.File;
12+
import java.nio.file.Files;
13+
1014
@Service
1115
public class TTSPlugin implements AudioPlayerManagerConfiguration {
1216
private static final Logger LOG = LoggerFactory.getLogger(TTSPlugin.class);
@@ -15,6 +19,8 @@ public class TTSPlugin implements AudioPlayerManagerConfiguration {
1519
public TTSPlugin(LavalinkTTSConfig config) throws Exception {
1620
LOG.info("Loading GCLOUD TTS plugin");
1721

22+
this.checkEnvVar(config);
23+
1824
if (StringUtils.isEmpty(config.getClientEmail())) {
1925
LOG.error("Client email is not set in the config, aborting. Config key is 'plugins.dunctebot.tts.clientEmail'");
2026
return;
@@ -36,4 +42,23 @@ public AudioPlayerManager configure(AudioPlayerManager manager) {
3642

3743
return manager;
3844
}
45+
46+
private void checkEnvVar(LavalinkTTSConfig config) {
47+
final String googleCreds = System.getenv("GOOGLE_APPLICATION_CREDENTIALS");
48+
49+
if (googleCreds == null) {
50+
return;
51+
}
52+
53+
try {
54+
final String json = Files.readString(new File(googleCreds).toPath());
55+
final JsonBrowser browser = JsonBrowser.parse(json);
56+
57+
config.setClientEmail(browser.get("client_email").text());
58+
config.setPrivateKey(browser.get("private_key").text());
59+
} catch (Exception e) {
60+
// Fail silently?
61+
LOG.error("Found google application credentials but could not parse json", e);
62+
}
63+
}
3964
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name=Google Cloud TTS
22
path=com.dunctebot.tss
3-
version=1.0.0
3+
version=1.0.1

0 commit comments

Comments
 (0)