|
| 1 | +package software.amazon.awssdk.crt.auth.credentials; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | +import java.util.concurrent.CompletableFuture; |
| 5 | + |
| 6 | +/** |
| 7 | + * Interface to allow for dynamic sourcing (ie per fetch-credentials request submitted to Cognito) of Cognito login |
| 8 | + * token pairs. It is *critical* to follow the guidance given in the documentation for `startLoginTokenFetch` |
| 9 | + */ |
| 10 | +public interface CognitoLoginTokenSource { |
| 11 | + |
| 12 | + /** |
| 13 | + * Method that a Cognito credentials provider should invoke before sending a fetch credentials |
| 14 | + * request to Cognito. The CognitoLoginTokenPairs that the future gets completed with are joined |
| 15 | + * with the (static) CognitoLoginTokenPairs that were specified in the credential provider configuration |
| 16 | + * on construction. The merged set of CognitoLoginTokenPairs are added to the HTTP request sent |
| 17 | + * to Cognito that sources credentials. |
| 18 | + * |
| 19 | + * You must follow several guidelines to properly use this feature; not following these guidelines can result |
| 20 | + * in deadlocks, poor performance, or other undesirable behavior. |
| 21 | + * |
| 22 | + * 1. If you use this feature, you must complete the future or the underlying connection attempt will hang forever. |
| 23 | + * Credentials sourcing is halted until the future gets completed. If something goes wrong during |
| 24 | + * login token sourcing, complete the future exceptionally. |
| 25 | + * |
| 26 | + * 2. You must not block or wait for asynchronous operations in this function. This function is invoked from a CRT |
| 27 | + * event loop thread, and the event loop is halted until this function is returned from. If you need to perform |
| 28 | + * an asynchronous or non-trivial operation in order to source the necessary login token pairs, then you must |
| 29 | + * ensure that sourcing task executes on another thread. The easiest way to do this would be to pass the future |
| 30 | + * to a sourcing task that runs on an external executor. |
| 31 | + */ |
| 32 | + void startLoginTokenFetch(CompletableFuture<List<CognitoCredentialsProvider.CognitoLoginTokenPair>> tokenFuture); |
| 33 | +} |
0 commit comments