data_lake_configuration.c
Go to the documentation of this file.
1 
11 #include "mcl_core/mcl_memory.h"
13 
14 // Endpoint for generating a signed url to upload data to.
15 static const char _upload_url_generation_endpoint[] = "/api/datalake/v3/generateUploadObjectUrls";
16 
17 // This function sets core parameter of data lake configuration.
19 
21 {
22  mcl_error_t code = MCL_OK;
23 
24  MCL_DEBUG_ENTRY("mcl_data_lake_configuration_t **configuration = <%p>", configuration);
25 
26  // Null check.
27  MCL_ASSERT_NOT_NULL(configuration, code);
28 
29  // Allocate memory for configuration data structure.
30  MCL_NEW(*configuration);
31 
32  if (MCL_NULL == *configuration)
33  {
34  code = MCL_OUT_OF_MEMORY;
35  }
36  else
37  {
38  // Set default values of configuration parameters.
39  (*configuration)->core = MCL_NULL;
40  (*configuration)->upload_url_generation_url = MCL_NULL;
41  (*configuration)->certificate = MCL_NULL;
42  (*configuration)->certificate_is_file = MCL_FALSE;
43  }
44 
46  MCL_DEBUG_LEAVE("retVal = <%d>", code);
47  return code;
48 }
49 
51  E_MCL_DATA_LAKE_CONFIGURATION_PARAMETER parameter, const void *value)
52 {
53  mcl_error_t code = MCL_OK;
54 
55  MCL_DEBUG_ENTRY("mcl_data_lake_configuration_t *configuration = <%p>, E_MCL_DATA_LAKE_CONFIGURATION_PARAMETER parameter = <%d>, const void *value = <%p>",
56  configuration, parameter, value);
57 
58  MCL_ASSERT_NOT_NULL(configuration, code);
59  MCL_ASSERT_NOT_NULL(value, code);
60 
61  switch (parameter)
62  {
64  code = _set_data_lake_configuration_core_parameter(configuration, (mcl_core_t *) value);
65  break;
66 
68  code = mcl_string_util_reset(value, &configuration->certificate);
69  configuration->certificate_is_file = MCL_FALSE;
70  break;
71 
73 #if HAVE_FILE_SYSTEM_
74  code = mcl_string_util_reset(value, &configuration->certificate);
75  configuration->certificate_is_file = MCL_TRUE;
76 #else
77  code = MCL_NO_FILE_SUPPORT;
78 #endif
79  break;
80 
81  default:
82  code = MCL_INVALID_PARAMETER;
83  break;
84  }
85 
87  MCL_DEBUG_LEAVE("retVal = <%d>", code);
88  return code;
89 }
90 
92 {
93  mcl_error_t code = MCL_OK;
94 
95  MCL_DEBUG_ENTRY("data_lake_configuration_t *configuration = <%p>", configuration);
96 
97  // Checks whether core parameter of configuration is set or not.
98  if (MCL_NULL == configuration->core)
99  {
100  code = MCL_INVALID_PARAMETER;
101  }
102 
103  MCL_DEBUG_LEAVE("retVal = <%d>", code);
104  return code;
105 }
106 
108 {
109  MCL_DEBUG_ENTRY("mcl_data_lake_configuration_t **configuration = <%p>", configuration);
110 
111  if ((MCL_NULL != configuration) && (MCL_NULL != *configuration))
112  {
113  MCL_FREE((*configuration)->upload_url_generation_url);
114  MCL_FREE((*configuration)->certificate);
115  MCL_FREE(*configuration);
116  }
117 
118  MCL_DEBUG_LEAVE("retVal = void");
119 }
120 
122 {
123  mcl_error_t code = MCL_OK;
124  const char *hostname;
125 
126  MCL_DEBUG_ENTRY("mcl_data_lake_configuration_t *configuration = <%p>, mcl_core_t *core = <%p>", configuration, core);
127 
128  // Set core.
129  configuration->core = core;
130 
131  // Get hostname.
132  hostname = mcl_core_get_host_name(configuration->core);
133 
134  if (MCL_NULL != hostname)
135  {
136  // Calculate hostname length.
137  mcl_size_t hostname_length = mcl_string_util_strlen(hostname);
138 
139  // Allocate buffer for data lake upload url.
140  configuration->upload_url_generation_url = MCL_MALLOC(hostname_length + sizeof(_upload_url_generation_endpoint));
141 
142  if (MCL_NULL == configuration->upload_url_generation_url)
143  {
144  code = MCL_OUT_OF_MEMORY;
145  }
146  else
147  {
148  // Concatenate host name with the constant endpoint for data lake upload url.
149  mcl_string_util_memcpy(configuration->upload_url_generation_url, hostname, hostname_length);
150  mcl_string_util_memcpy(configuration->upload_url_generation_url + hostname_length, _upload_url_generation_endpoint,
152  }
153  }
154  else
155  {
156  code = MCL_INVALID_PARAMETER;
157  }
158 
159  MCL_DEBUG_LEAVE("retVal = <%d>", code);
160  return code;
161 }
#define MCL_FUNCTION_LEAVE_LABEL
size_t mcl_size_t
MCL_NO_FILE_SUPPORT
MCL_OK
struct mcl_data_lake_configuration_t mcl_data_lake_configuration_t
MCL_CORE_EXPORT mcl_error_t mcl_string_util_reset(const void *value, char **target)
mcl_int32_t mcl_error_t
Certificate file parameter as char* for the server of the pre-signed url (e.g. AWS certificate if the...
Data lake configuration module header file.
#define MCL_DEBUG_ENTRY(...)
MCL_CORE_EXPORT const char * mcl_core_get_host_name(mcl_core_t *core)
#define MCL_FALSE
Certificate parameter as char* for the server of the pre-signed url (e.g. AWS certificate if the pre-...
MCL_CORE_EXPORT mcl_size_t mcl_string_util_strlen(const char *buffer)
#define MCL_NEW(p)
#define MCL_NULL
struct mcl_core_t mcl_core_t
#define MCL_FREE(p)
#define MCL_ASSERT_NOT_NULL(argument, return_variable)
MCL_CORE_EXPORT void mcl_string_util_memcpy(void *destination, const void *source, mcl_size_t count)
static const char _upload_url_generation_endpoint[]
E_MCL_DATA_LAKE_CONFIGURATION_PARAMETER
Data lake configuration module header file.
static mcl_error_t _set_data_lake_configuration_core_parameter(mcl_data_lake_configuration_t *configuration, mcl_core_t *core)
mcl_error_t data_lake_configuration_validate(data_lake_configuration_t *configuration)
MCL_OUT_OF_MEMORY
mcl_error_t mcl_data_lake_configuration_initialize(mcl_data_lake_configuration_t **configuration)
#define MCL_MALLOC(bytes)
void mcl_data_lake_configuration_destroy(mcl_data_lake_configuration_t **configuration)
mcl_error_t mcl_data_lake_configuration_set_parameter(mcl_data_lake_configuration_t *configuration, E_MCL_DATA_LAKE_CONFIGURATION_PARAMETER parameter, const void *value)
MCL_INVALID_PARAMETER
#define MCL_DEBUG_LEAVE(...)
#define MCL_TRUE