Skip to content

Commit c32c0d2

Browse files
feat(client): allow configuring env via system properties
1 parent 15ac3d4 commit c32c0d2

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ import com.withorb.api.client.okhttp.OrbOkHttpClient;
4646
import com.withorb.api.models.Customer;
4747
import com.withorb.api.models.CustomerCreateParams;
4848

49-
// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
49+
// Configures using the `orb.apiKey`, `orb.webhookSecret` and `orb.baseUrl` system properties
50+
// Or configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
5051
OrbClient client = OrbOkHttpClient.fromEnv();
5152

5253
CustomerCreateParams params = CustomerCreateParams.builder()
@@ -58,13 +59,14 @@ Customer customer = client.customers().create(params);
5859

5960
## Client configuration
6061

61-
Configure the client using environment variables:
62+
Configure the client using system properties or environment variables:
6263

6364
```java
6465
import com.withorb.api.client.OrbClient;
6566
import com.withorb.api.client.okhttp.OrbOkHttpClient;
6667

67-
// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
68+
// Configures using the `orb.apiKey`, `orb.webhookSecret` and `orb.baseUrl` system properties
69+
// Or configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
6870
OrbClient client = OrbOkHttpClient.fromEnv();
6971
```
7072

@@ -86,19 +88,22 @@ import com.withorb.api.client.OrbClient;
8688
import com.withorb.api.client.okhttp.OrbOkHttpClient;
8789

8890
OrbClient client = OrbOkHttpClient.builder()
89-
// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
91+
// Configures using the `orb.apiKey`, `orb.webhookSecret` and `orb.baseUrl` system properties
92+
Or configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
9093
.fromEnv()
9194
.apiKey("My API Key")
9295
.build();
9396
```
9497

9598
See this table for the available options:
9699

97-
| Setter | Environment variable | Required | Default value |
98-
| --------------- | -------------------- | -------- | ------------------------------ |
99-
| `apiKey` | `ORB_API_KEY` | true | - |
100-
| `webhookSecret` | `ORB_WEBHOOK_SECRET` | false | - |
101-
| `baseUrl` | `ORB_BASE_URL` | true | `"https://api.withorb.com/v1"` |
100+
| Setter | System property | Environment variable | Required | Default value |
101+
| --------------- | ------------------- | -------------------- | -------- | ------------------------------ |
102+
| `apiKey` | `orb.apiKey` | `ORB_API_KEY` | true | - |
103+
| `webhookSecret` | `orb.webhookSecret` | `ORB_WEBHOOK_SECRET` | false | - |
104+
| `baseUrl` | `orb.baseUrl` | `ORB_BASE_URL` | true | `"https://api.withorb.com/v1"` |
105+
106+
System properties take precedence over environment variables.
102107

103108
> [!TIP]
104109
> Don't create more than one client in the same application. Each client has a connection pool and
@@ -144,7 +149,8 @@ import com.withorb.api.models.Customer;
144149
import com.withorb.api.models.CustomerCreateParams;
145150
import java.util.concurrent.CompletableFuture;
146151

147-
// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
152+
// Configures using the `orb.apiKey`, `orb.webhookSecret` and `orb.baseUrl` system properties
153+
// Or configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
148154
OrbClient client = OrbOkHttpClient.fromEnv();
149155

150156
CustomerCreateParams params = CustomerCreateParams.builder()
@@ -163,7 +169,8 @@ import com.withorb.api.models.Customer;
163169
import com.withorb.api.models.CustomerCreateParams;
164170
import java.util.concurrent.CompletableFuture;
165171

166-
// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
172+
// Configures using the `orb.apiKey`, `orb.webhookSecret` and `orb.baseUrl` system properties
173+
// Or configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
167174
OrbClientAsync client = OrbOkHttpClientAsync.fromEnv();
168175

169176
CustomerCreateParams params = CustomerCreateParams.builder()

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,13 @@ private constructor(
242242
fun timeout(): Timeout = timeout
243243

244244
fun fromEnv() = apply {
245-
System.getenv("ORB_BASE_URL")?.let { baseUrl(it) }
246-
System.getenv("ORB_API_KEY")?.let { apiKey(it) }
247-
System.getenv("ORB_WEBHOOK_SECRET")?.let { webhookSecret(it) }
245+
(System.getProperty("orb.baseUrl") ?: System.getenv("ORB_BASE_URL"))?.let {
246+
baseUrl(it)
247+
}
248+
(System.getProperty("orb.apiKey") ?: System.getenv("ORB_API_KEY"))?.let { apiKey(it) }
249+
(System.getProperty("orb.webhookSecret") ?: System.getenv("ORB_WEBHOOK_SECRET"))?.let {
250+
webhookSecret(it)
251+
}
248252
}
249253

250254
/**

0 commit comments

Comments
 (0)