How to generate OAUTH2 token and use REST API to pull logs from Cloud?

That very much depends where you need the Authorization header. For example, if you are using an http_poller input then the short answer is no, there is no way to do this. If you need it in a http output, then it might be doable.

But you are going to have to do it in ruby. Basically, add a ruby filter than checks if it has a valid header stashed in an instance variable. If so, add it to the event. If not, generate one, stash it in an instance variable, and add it to the event. Then in the output you should be able to reference the field on the event.

Oh, and going back to http_poller input. If you implement the HTTP request in the ruby filter and just use the http_poller for scheduling you could make it work that way.

But this use case just is not a good fit with logstash. You might be better off doing the authenticated REST call externally to logstash, using /bin/sh and curl (and maybe cron) and then POST it into an HTTP input in logstash.