Skip to content

Commit 1de7962

Browse files
committed
Add more secret value declaration
1 parent 550f3cf commit 1de7962

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

docs/default/store/web-supervisor.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ URL: 'https://shop.mysite.com'
3232
* `group` - Is the server associated with the name that the supervisor is looking for orders.
3333
* `url` - Is the store url.
3434

35+
### Secret declaration
36+
37+
In any part of the configuration where a "secret", "key" or any value that is supposed to be private, can be declared in the following ways:
38+
39+
* `<value>` - The simple one, where `<value>` is just the value.
40+
* `file:<path>` - To get the value from a file content, where `<path>` is the file path.
41+
* `property:<key>` - To get the value from a system property, where `<key>` is the system property key.
42+
3543
## PixelBuy
3644

3745
The PixelBuy web supervisor retrieves information from a site compatible with PixelBuy web API schema:

docs/es/store/web-supervisor.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ URL: 'https://shop.mysite.com'
3232
* `group` - Es el grupo de servidor al que el supervisor está añadiendo las órdenes de compra encontradas.
3333
* `url` - Es el url de la tienda.
3434

35+
### Declarar secretos
36+
37+
En cualquier parte de la configuración donde se requiera una "clave secreta", "un secreto" o cualquier valor que se supone que sea privado, puede declararse de las siguientes maneras:
38+
39+
* `<value>` - La forma simple, donde el `<value>` es solo el valor.
40+
* `file:<path>` - Para obtener el valor al leer el contenido de un archivo, donde el `<path>` es la ruta hacia el archivo.
41+
* `property:<key>` - Para obtener el valor desde una propiedad del sistema, donde el `<key>` es la key de la propiedad.
42+
3543
## PixelBuy
3644

3745
El supervisor de PixelBuy obtiene información de un sitio web compatible con el esquema de la API de PixelBuy:

src/main/java/com/saicone/pixelbuy/core/web/WebSupervisor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import org.jetbrains.annotations.NotNull;
1212
import org.jetbrains.annotations.Nullable;
1313

14+
import java.io.IOException;
15+
import java.nio.file.Files;
16+
import java.nio.file.Paths;
1417
import java.util.HashMap;
1518
import java.util.List;
1619
import java.util.Map;
@@ -94,6 +97,15 @@ protected String addSecret(@Nullable String secret) {
9497
if (secret == null) {
9598
return null;
9699
}
100+
if (secret.startsWith("file:")) {
101+
try {
102+
secret = String.join("", Files.readAllLines(Paths.get(secret.substring(5)))).trim();
103+
} catch (IOException e) {
104+
PixelBuy.logException(2, e);
105+
}
106+
} else if (secret.startsWith("property:")) {
107+
secret = System.getProperty(secret.substring(9));
108+
}
97109
secrets.put(secret, "*".repeat(secret.length()));
98110
return secret;
99111
}

src/main/java/com/saicone/pixelbuy/core/web/supervisor/WooMinecraftWeb.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public void onLoad(@NotNull BukkitSettings config) {
8989

9090
this.metaKey = "_wmc_commands_" + password;
9191

92-
final String consumerKey = config.getRegex("(?i)woocommerce", "(?i)consumer-?key").asString();
93-
final String consumerSecret = config.getRegex("(?i)woocommerce", "(?i)consumer-?secret").asString();
92+
final String consumerKey = addSecret(config.getRegex("(?i)woocommerce", "(?i)consumer-?key").asString());
93+
final String consumerSecret = addSecret(config.getRegex("(?i)woocommerce", "(?i)consumer-?secret").asString());
9494
if (consumerKey == null || consumerSecret == null) {
9595
this.orderConnection = null;
9696
this.productConnection = null;

0 commit comments

Comments
 (0)