|
42 | 42 | import java.util.function.Supplier; |
43 | 43 | import land.oras.auth.AuthProvider; |
44 | 44 | import land.oras.auth.AuthStoreAuthenticationProvider; |
| 45 | +import land.oras.auth.BearerTokenProvider; |
45 | 46 | import land.oras.auth.HttpClient; |
46 | 47 | import land.oras.auth.NoAuthProvider; |
47 | 48 | import land.oras.auth.RegistriesConf; |
@@ -294,6 +295,15 @@ public Registry copy(String newRegistry) { |
294 | 295 | return new Builder().from(this).withRegistry(newRegistry).build(); |
295 | 296 | } |
296 | 297 |
|
| 298 | + /** |
| 299 | + * Return a new registry with a new auth external token and same settings |
| 300 | + * @param authToken The new refreshed token |
| 301 | + * @return The new registry |
| 302 | + */ |
| 303 | + public Registry withAuthToken(String authToken) { |
| 304 | + return new Builder().from(this).withAuthToken(authToken).build(); |
| 305 | + } |
| 306 | + |
297 | 307 | /** |
298 | 308 | * Return a new registry as insecure but with same settings |
299 | 309 | * @return The new registry |
@@ -1281,6 +1291,18 @@ public Builder withAuthProvider(AuthProvider authProvider) { |
1281 | 1291 | return this; |
1282 | 1292 | } |
1283 | 1293 |
|
| 1294 | + /** |
| 1295 | + * Use given auth token for the registry. |
| 1296 | + * Useful when the auth token is obtained by other mean (like a token exchange). |
| 1297 | + * Caller are responsible to handle token expiration if any |
| 1298 | + * @param authToken The auth token |
| 1299 | + * @return The builder |
| 1300 | + */ |
| 1301 | + public Builder withAuthToken(String authToken) { |
| 1302 | + registry.setAuthProvider(new BearerTokenProvider(authToken)); |
| 1303 | + return this; |
| 1304 | + } |
| 1305 | + |
1284 | 1306 | /** |
1285 | 1307 | * Set the maximum number of concurrent downloads when pulling an artifact with multiple layers. Default is 4. |
1286 | 1308 | * @param parallelism The maximum number of parallel uploads/download |
|
0 commit comments