Skip to content

Commit 3b78f9e

Browse files
feat(client): allow configuring env via system properties
1 parent 12496f2 commit 3b78f9e

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ import com.lithic.api.client.okhttp.LithicOkHttpClient;
5151
import com.lithic.api.models.Card;
5252
import com.lithic.api.models.CardCreateParams;
5353

54-
// Configures using the `LITHIC_API_KEY`, `LITHIC_WEBHOOK_SECRET` and `LITHIC_BASE_URL` environment variables
54+
// Configures using the `lithic.apiKey`, `lithic.webhookSecret` and `lithic.baseUrl` system properties
55+
// Or configures using the `LITHIC_API_KEY`, `LITHIC_WEBHOOK_SECRET` and `LITHIC_BASE_URL` environment variables
5556
LithicClient client = LithicOkHttpClient.fromEnv();
5657

5758
CardCreateParams params = CardCreateParams.builder()
@@ -62,13 +63,14 @@ Card card = client.cards().create(params);
6263

6364
## Client configuration
6465

65-
Configure the client using environment variables:
66+
Configure the client using system properties or environment variables:
6667

6768
```java
6869
import com.lithic.api.client.LithicClient;
6970
import com.lithic.api.client.okhttp.LithicOkHttpClient;
7071

71-
// Configures using the `LITHIC_API_KEY`, `LITHIC_WEBHOOK_SECRET` and `LITHIC_BASE_URL` environment variables
72+
// Configures using the `lithic.apiKey`, `lithic.webhookSecret` and `lithic.baseUrl` system properties
73+
// Or configures using the `LITHIC_API_KEY`, `LITHIC_WEBHOOK_SECRET` and `LITHIC_BASE_URL` environment variables
7274
LithicClient client = LithicOkHttpClient.fromEnv();
7375
```
7476

@@ -90,19 +92,22 @@ import com.lithic.api.client.LithicClient;
9092
import com.lithic.api.client.okhttp.LithicOkHttpClient;
9193

9294
LithicClient client = LithicOkHttpClient.builder()
93-
// Configures using the `LITHIC_API_KEY`, `LITHIC_WEBHOOK_SECRET` and `LITHIC_BASE_URL` environment variables
95+
// Configures using the `lithic.apiKey`, `lithic.webhookSecret` and `lithic.baseUrl` system properties
96+
Or configures using the `LITHIC_API_KEY`, `LITHIC_WEBHOOK_SECRET` and `LITHIC_BASE_URL` environment variables
9497
.fromEnv()
9598
.apiKey("My Lithic API Key")
9699
.build();
97100
```
98101

99102
See this table for the available options:
100103

101-
| Setter | Environment variable | Required | Default value |
102-
| --------------- | ----------------------- | -------- | -------------------------- |
103-
| `apiKey` | `LITHIC_API_KEY` | true | - |
104-
| `webhookSecret` | `LITHIC_WEBHOOK_SECRET` | false | - |
105-
| `baseUrl` | `LITHIC_BASE_URL` | true | `"https://api.lithic.com"` |
104+
| Setter | System property | Environment variable | Required | Default value |
105+
| --------------- | ---------------------- | ----------------------- | -------- | -------------------------- |
106+
| `apiKey` | `lithic.apiKey` | `LITHIC_API_KEY` | true | - |
107+
| `webhookSecret` | `lithic.webhookSecret` | `LITHIC_WEBHOOK_SECRET` | false | - |
108+
| `baseUrl` | `lithic.baseUrl` | `LITHIC_BASE_URL` | true | `"https://api.lithic.com"` |
109+
110+
System properties take precedence over environment variables.
106111

107112
> [!TIP]
108113
> Don't create more than one client in the same application. Each client has a connection pool and
@@ -148,7 +153,8 @@ import com.lithic.api.models.Card;
148153
import com.lithic.api.models.CardCreateParams;
149154
import java.util.concurrent.CompletableFuture;
150155

151-
// Configures using the `LITHIC_API_KEY`, `LITHIC_WEBHOOK_SECRET` and `LITHIC_BASE_URL` environment variables
156+
// Configures using the `lithic.apiKey`, `lithic.webhookSecret` and `lithic.baseUrl` system properties
157+
// Or configures using the `LITHIC_API_KEY`, `LITHIC_WEBHOOK_SECRET` and `LITHIC_BASE_URL` environment variables
152158
LithicClient client = LithicOkHttpClient.fromEnv();
153159

154160
CardCreateParams params = CardCreateParams.builder()
@@ -166,7 +172,8 @@ import com.lithic.api.models.Card;
166172
import com.lithic.api.models.CardCreateParams;
167173
import java.util.concurrent.CompletableFuture;
168174

169-
// Configures using the `LITHIC_API_KEY`, `LITHIC_WEBHOOK_SECRET` and `LITHIC_BASE_URL` environment variables
175+
// Configures using the `lithic.apiKey`, `lithic.webhookSecret` and `lithic.baseUrl` system properties
176+
// Or configures using the `LITHIC_API_KEY`, `LITHIC_WEBHOOK_SECRET` and `LITHIC_BASE_URL` environment variables
170177
LithicClientAsync client = LithicOkHttpClientAsync.fromEnv();
171178

172179
CardCreateParams params = CardCreateParams.builder()

lithic-java-core/src/main/kotlin/com/lithic/api/core/ClientOptions.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,14 @@ private constructor(
246246
fun timeout(): Timeout = timeout
247247

248248
fun fromEnv() = apply {
249-
System.getenv("LITHIC_BASE_URL")?.let { baseUrl(it) }
250-
System.getenv("LITHIC_API_KEY")?.let { apiKey(it) }
251-
System.getenv("LITHIC_WEBHOOK_SECRET")?.let { webhookSecret(it) }
249+
(System.getProperty("lithic.baseUrl") ?: System.getenv("LITHIC_BASE_URL"))?.let {
250+
baseUrl(it)
251+
}
252+
(System.getProperty("lithic.apiKey") ?: System.getenv("LITHIC_API_KEY"))?.let {
253+
apiKey(it)
254+
}
255+
(System.getProperty("lithic.webhookSecret") ?: System.getenv("LITHIC_WEBHOOK_SECRET"))
256+
?.let { webhookSecret(it) }
252257
}
253258

254259
/**

0 commit comments

Comments
 (0)