virt: Fetch block info stats from libvirt only if needed
[collectd.git] / src / utils_oauth.h
1 /**
2  * collectd - src/utils_oauth.h
3  * ISC license
4  *
5  * Copyright (C) 2017  Florian Forster
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  *
19  * Authors:
20  *   Florian Forster <octo at collectd.org>
21  **/
22
23 #ifndef UTILS_OAUTH_H
24 #define UTILS_OAUTH_H
25
26 #include "collectd.h"
27 #include "utils_time.h"
28
29 #ifndef GOOGLE_OAUTH_URL
30 #define GOOGLE_OAUTH_URL "https://www.googleapis.com/oauth2/v3/token"
31 #endif
32
33 struct oauth_s;
34 typedef struct oauth_s oauth_t;
35
36 int oauth_parse_json_token(char const *json, char *out_access_token,
37                            size_t access_token_size, cdtime_t *expires_in);
38
39 typedef struct {
40   char *project_id;
41   oauth_t *oauth;
42 } oauth_google_t;
43
44 /* oauth_create_google_json creates an OAuth object from JSON encoded
45  * credentials. */
46 oauth_google_t oauth_create_google_json(char const *json, char const *scope);
47
48 /* oauth_create_google_file reads path, which contains JSON encoded service
49  * account credentials, and returns an OAuth object. */
50 oauth_google_t oauth_create_google_file(char const *path, char const *scope);
51
52 /* oauth_create_google_default looks for service account credentials in a couple
53  * of well-known places and returns an OAuth object if found. The well known
54  * locations are:
55  *
56  *   - ${GOOGLE_APPLICATION_CREDENTIALS}
57  *   - ${HOME}/.config/gcloud/application_default_credentials.json
58  */
59 oauth_google_t oauth_create_google_default(char const *scope);
60
61 /* oauth_destroy frees all resources associated with an OAuth object. */
62 void oauth_destroy(oauth_t *auth);
63
64 int oauth_access_token(oauth_t *auth, char *buffer, size_t buffer_size);
65
66 #endif