You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2023/01/17 08:05:08 UTC

[GitHub] [beam] EgbertW commented on pull request #25024: Add withDefaultHeaders to connection configuration for ElasticsearchIO

EgbertW commented on PR #25024:
URL: https://github.com/apache/beam/pull/25024#issuecomment-1384988804

   > I'm not denying the utility here, but I'm not 100% clear on how this addresses #25018. Could you elaborate on how this technique can be used to work with short-lived credentials?
   
   Of course. What I did to work with short-lived tokens is create a new header class, something resembling:
   
   ```
   class OauthTokenHeader extends BasicHeader {
       OIDCIDToken accessToken;
   
       ...
   
       @Override
       public String getValue() {
           if (accessToken.isExpired()) {
               accessToken.renew();
           }
           return String.format("Bearer %s", accessToken.getToken());
       }
   }
   ```
   
   Since the Elasticsearch RestClient will add the `defaultHeaders` on each outgoing request, it will invoke `getValue` on every request, giving the opportunity to check if the token has expired and if so, renew it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org