Re: Revamping googleapis bindings; overloading `[] ?
"Stephen R. van den Berg" <[email protected]> Tue, 21 May 2019 17:09:05 +0200
| Newsgroups | gmane.comp.lang.pike.devel,gmane.comp.lang.pike.user |
|---|---|
| Message-ID | <[email protected]> |
I now have an API that works roughly like this:
#define TOKENTIME 3600
#define PROJECT "mylittleproject"
#define ZONE "eu-west1-c"
string jwt_secret = Stdio.File("googleserviceaccount.json", "r").read();
//
// This hot-fetches the Google Compute API from the discovery file
// provided by Google:
//
Web.Api.Google.Base api = Web.Api.Google.discover("compute", "v1");
void authenticated() {
if (!api->auth->is_authenticated()
|| api->auth->expires->unix_time() - time(1) < TOKENTIME / 2)
api->auth->get_token_from_jwt(jwt_secret);
}
int main(int argc, array(string) argv) {
api->auth->set_scope(api->valid_scopes[1]);
authenticated();
// Lists all compute engine instances in this project/zone
write("%O\n", api->resrc->instances->list(
([
"project":PROJECT,
"zone":ZONE
])
));
return 0;
}
Suggestions? Complaints? Wishes?
--
Stephen.