Coverage Report

Created: 2025-06-24 08:09

/src/fluent-bit/plugins/out_td/td_config.c
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*  Fluent Bit
4
 *  ==========
5
 *  Copyright (C) 2015-2024 The Fluent Bit Authors
6
 *
7
 *  Licensed under the Apache License, Version 2.0 (the "License");
8
 *  you may not use this file except in compliance with the License.
9
 *  You may obtain a copy of the License at
10
 *
11
 *      http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 *  Unless required by applicable law or agreed to in writing, software
14
 *  distributed under the License is distributed on an "AS IS" BASIS,
15
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 *  See the License for the specific language governing permissions and
17
 *  limitations under the License.
18
 */
19
20
#include <fluent-bit/flb_output_plugin.h>
21
#include "td_config.h"
22
#include <stdlib.h>
23
24
struct flb_td *td_config_init(struct flb_output_instance *ins)
25
0
{
26
0
    int ret;
27
0
    struct flb_td *ctx;
28
29
    
30
    /* Allocate context */
31
0
    ctx = flb_calloc(1, sizeof(struct flb_td));
32
0
    if (!ctx) {
33
0
        flb_errno();
34
0
        return NULL;
35
0
    }
36
0
    ctx->ins      = ins;
37
0
    ctx->fd       = -1;
38
    
39
0
    ret = flb_output_config_map_set(ins, (void *)ctx);
40
0
    if (ret == -1) {
41
0
        flb_plg_error(ins, "unable to load configuration");
42
0
        flb_free(ctx);
43
0
        return NULL;
44
0
    }
45
    
46
0
    if (ctx->api == NULL) {
47
0
        flb_plg_error(ins, "error reading API key value");
48
0
        flb_free(ctx);
49
0
        return NULL;
50
0
    }
51
52
0
    if (ctx->db_name == NULL) {
53
0
        flb_plg_error(ins, "error reading Database name");
54
0
        flb_free(ctx);
55
0
        return NULL;
56
0
    }
57
58
0
    if (ctx->db_table == NULL) {
59
0
        flb_plg_error(ins, "error reading Table name");
60
0
        flb_free(ctx);
61
0
        return NULL;
62
0
    }
63
64
    /* Lookup desired region */
65
0
    if (ctx->region_str) {
66
0
        if (strcasecmp(ctx->region_str, "us") == 0) {
67
0
            ctx->region = FLB_TD_REGION_US;
68
0
        }
69
0
        else if (strcasecmp(ctx->region_str, "jp") == 0) {
70
0
            ctx->region = FLB_TD_REGION_JP;
71
0
        }
72
0
        else {
73
0
            flb_plg_error(ctx->ins, "invalid region in configuration");
74
0
            flb_free(ctx);
75
0
            return NULL;
76
0
        }
77
0
    }
78
0
    else {
79
0
        ctx->region = FLB_TD_REGION_US;
80
0
    }
81
82
0
    flb_plg_info(ctx->ins, "Treasure Data / database='%s' table='%s'",
83
0
                 ctx->db_name, ctx->db_table);
84
85
0
    return ctx;
86
0
}