|
26 | 26 | #include "azure_logs_ingestion.h" |
27 | 27 | #include "azure_logs_ingestion_conf.h" |
28 | 28 |
|
| 29 | +static int validate_auth_url_override(struct flb_output_instance *ins, |
| 30 | + flb_sds_t auth_url_override) |
| 31 | +{ |
| 32 | + int ret; |
| 33 | + int result; |
| 34 | + char *protocol = NULL; |
| 35 | + char *host = NULL; |
| 36 | + char *port = NULL; |
| 37 | + char *uri = NULL; |
| 38 | + |
| 39 | + result = -1; |
| 40 | + |
| 41 | + ret = flb_utils_url_split(auth_url_override, &protocol, &host, &port, &uri); |
| 42 | + if (ret == -1 || protocol == NULL || host == NULL) { |
| 43 | + flb_plg_error(ins, "property 'auth_url' has an invalid URL"); |
| 44 | + goto cleanup; |
| 45 | + } |
| 46 | + |
| 47 | + if (strcasecmp(protocol, "https") == 0) { |
| 48 | + result = 0; |
| 49 | + goto cleanup; |
| 50 | + } |
| 51 | + |
| 52 | + if (strcasecmp(protocol, "http") != 0) { |
| 53 | + flb_plg_error(ins, "property 'auth_url' must use http or https"); |
| 54 | + goto cleanup; |
| 55 | + } |
| 56 | + |
| 57 | + if (strcmp(host, "localhost") == 0 || strcmp(host, "127.0.0.1") == 0) { |
| 58 | + result = 0; |
| 59 | + goto cleanup; |
| 60 | + } |
| 61 | + |
| 62 | + flb_plg_error(ins, |
| 63 | + "property 'auth_url' must use https or an explicit loopback " |
| 64 | + "http endpoint"); |
| 65 | + |
| 66 | +cleanup: |
| 67 | + if (protocol != NULL) { |
| 68 | + flb_free(protocol); |
| 69 | + } |
| 70 | + if (host != NULL) { |
| 71 | + flb_free(host); |
| 72 | + } |
| 73 | + if (port != NULL) { |
| 74 | + flb_free(port); |
| 75 | + } |
| 76 | + if (uri != NULL) { |
| 77 | + flb_free(uri); |
| 78 | + } |
| 79 | + |
| 80 | + return result; |
| 81 | +} |
| 82 | + |
29 | 83 | struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins, |
30 | 84 | struct flb_config *config) |
31 | 85 | { |
@@ -92,6 +146,12 @@ struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins, |
92 | 146 | } |
93 | 147 |
|
94 | 148 | if (ctx->auth_url_override) { |
| 149 | + ret = validate_auth_url_override(ins, ctx->auth_url_override); |
| 150 | + if (ret == -1) { |
| 151 | + flb_az_li_ctx_destroy(ctx); |
| 152 | + return NULL; |
| 153 | + } |
| 154 | + |
95 | 155 | ctx->auth_url = flb_sds_create(ctx->auth_url_override); |
96 | 156 | if (!ctx->auth_url) { |
97 | 157 | flb_errno(); |
|
0 commit comments