| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "api_v3_calls.h" |
| 4 | |
| 5 | int api_v3_me(RRDHOST *host __maybe_unused, struct web_client *w, char *url __maybe_unused) { |
| 6 | BUFFER *wb = w->response.data; |
| 7 | buffer_reset(wb); |
| 8 | buffer_json_initialize(wb, "\"", "\"", 0, true, BUFFER_JSON_OPTIONS_MINIFY); |
| 9 | |
| 10 | const char *auth; |
| 11 | switch(w->user_auth.method) { |
| 12 | case USER_AUTH_METHOD_CLOUD: |
| 13 | auth = "cloud"; |
| 14 | break; |
| 15 | |
| 16 | case USER_AUTH_METHOD_BEARER: |
| 17 | auth = "bearer"; |
| 18 | break; |
| 19 | |
| 20 | case USER_AUTH_METHOD_GOD: |
| 21 | auth = "god"; |
| 22 | break; |
| 23 | |
| 24 | default: |
| 25 | case USER_AUTH_METHOD_NONE: |
| 26 | auth = "none"; |
| 27 | break; |
| 28 | } |
| 29 | buffer_json_member_add_string(wb, "auth", auth); |
| 30 | |
| 31 | buffer_json_member_add_uuid(wb, "cloud_account_id", w->user_auth.cloud_account_id.uuid); |
| 32 | buffer_json_member_add_string(wb, "client_name", w->user_auth.client_name); |
| 33 | http_access2buffer_json_array(wb, "access", w->user_auth.access); |
| 34 | buffer_json_member_add_string(wb, "user_role", http_id2user_role(w->user_auth.user_role)); |
| 35 | |
| 36 | buffer_json_finalize(wb); |
| 37 | return HTTP_RESP_OK; |
| 38 | } |