Question

I have a java cron job that needs permanent access to a google storage bucket. All of the documentation I've seen require OAUTH user login for that. I've read about the refresh tokens, are there any code samples that show specifically how to get a permanent access token for a given cron job?

thanks

Was it helpful?

Solution

Google Cloud Storage supports both OAuth 2.0 and access key/secret key authentication (details here). A simple way to solve your problem would be to write an application using a Java library (e.g. Jets3t) that makes it easy to upload files using a configured set of authentication credentials. You could then invoke your Java app from a cron job.

Note that a refresh token is valid until revoked, so once you have a valid refresh token, your cron job can use it to obtain access tokens (which are short-lived) indefinitely, without needing to use the web flow again.

Even simpler, you could use the gsutil command in a cron job, which can also perform uploads based on stored credentials without requiring human intervention. If you go that route, be sure to set the BOTO_CONFIG environment variable so that the cron job can find your .boto file containing your stored authentication credentials and other configuration settings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top