Add "NO_LOGGING" flavors for CONFIG_REQUIRED and CONFIG_OPTIONAL (#196)

* WIP

* Magic

* UTs pass

* Address CR comment
This commit is contained in:
Dan Cristoloveanu 2024-06-03 14:50:49 -07:00 коммит произвёл GitHub
Родитель 18457be5b0
Коммит d5206dd1ec
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 148 добавлений и 45 удалений

Просмотреть файл

@ -13,9 +13,11 @@ The following types are supported:
- `char*` (`char_ptr`)
- `wchar_t*` (`wchar_ptr`)
- `THANDLE(RC_STRING)` (`thandle_rc_string`)
Any of the string types may be required (must be present in the config or create will fail) or optional (`NULL` or empty strings are allowed). Integer and bool types do not behave differently for optional and required.
By default configs do get logged for debugging purposes. In order to avoid logging a certain config, the macros `CONFIG_REQUIRED_NO_LOGGING` and `CONFIG_OPTIONAL_NO_LOGGING` are available. Secrets (like keys, passwords, connection strings) should be configured using these options.
## Example Usage
```c
@ -23,13 +25,16 @@ Any of the string types may be required (must be present in the config or create
#define MY_CONFIGURATION_PARAMETER_NAME_parameter_1 L"ParameterName1"
#define MY_CONFIGURATION_PARAMETER_NAME_parameter_2 L"ParameterName2"
#define MY_CONFIGURATION_PARAMETER_NAME_other_option L"OtherOption"
#define MY_CONFIGURATION_PARAMETER_NAME_connection_string L"ConnectionString"
#define MY_CONFIGURATION_PARAMETER_NAME_foo L"FooNameInXML"
#define MY_CONFIGURATION_PARAMETER_NAME_bar_hidden L"BarHidden"
#define MY_CONFIGURATION_VALUES \
CONFIG_REQUIRED(uint64_t, parameter_1), \
CONFIG_REQUIRED(bool, parameter_2), \
CONFIG_REQUIRED(thandle_rc_string, other_option), \
CONFIG_OPTIONAL(thandle_rc_string, foo) \
CONFIG_REQUIRED_NO_LOGGING(thandle_rc_string, connection_string), \
CONFIG_OPTIONAL(thandle_rc_string, foo), \
CONFIG_OPTIONAL_NO_LOGGING(thandle_rc_string, bar_hidden) \
DECLARE_SF_SERVICE_CONFIG(MY, MY_CONFIGURATION_VALUES)
@ -46,7 +51,9 @@ SF Application Manifest
<Parameter Name="ParameterName1Value" DefaultValue="42" />
<Parameter Name="ParameterName2Value" DefaultValue="True" />
<Parameter Name="OtherOptionValue" DefaultValue="some string" />
<Parameter Name="ConnectionString" DefaultValue="some hidden secret" />
<Parameter Name="FooNameInXMLValue" DefaultValue="" />
<Parameter Name="BarHidden" DefaultValue="hide me" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="MyServiceManifestName" ServiceManifestVersion="1.42" />
@ -57,7 +64,9 @@ SF Application Manifest
<Parameter Name="ParameterName1" Value="[ParameterName1Value]" />
<Parameter Name="ParameterName2" Value="[ParameterName2Value]" />
<Parameter Name="OtherOption" Value="[OtherOptionValueValue]" />
<Parameter Name="ConnectionString" Value="[ConnectionStringValue]" />
<Parameter Name="FooNameInXML" Value="[FooNameInXMLValue]" />
<Parameter Name="BarHidden" Value="[BarHiddenValue]" />
</Section>
</Settings>
</ConfigOverride>
@ -75,7 +84,9 @@ SF Config XML
<Parameter Name="ParameterName1" Value="42" />
<Parameter Name="ParameterName2" Value="True" />
<Parameter Name="OtherOption" Value="some string" />
<Parameter Name="ConnectionString" Value="some hidden secret" />
<Parameter Name="FooNameInXML" Value="" />
<Parameter Name="BarHidden" Value="hide me" />
</Section>
</Settings>
```
@ -118,7 +129,7 @@ Creates all declarations for the configuration type `SF_SERVICE_CONFIG(name)`. T
Creates all declarations for the configuration type `SF_SERVICE_CONFIG(name)` mockable getters for the parameters specified.
Each parameter must be in the form `CONFIG_REQUIRED(type, config_name)` or `CONFIG_OPTIONAL(type, config_name)`, for configurations that are required or optional, respectively. Required configs must be found in the SF configuration or the configuration create will fail, optional configs may be absent and a default (e.g. empty string) will be used.
Each parameter must be in the form `CONFIG_REQUIRED(type, config_name)`, `CONFIG_OPTIONAL(type, config_name)`, `CONFIG_REQUIRED_NO_LOGGING(type, config_name)` or `CONFIG_OPTIONAL_NO_LOGGING(type, config_name)`, for configurations that are required or optional, respectively. Required configs must be found in the SF configuration or the configuration create will fail, optional configs may be absent and a default (e.g. empty string) will be used.
Each of these parameters with name `config_name` must also have a corresponding `SF_SERVICE_CONFIG_PARAMETER_NAME_config_name` defined with a wide string for the name of the config value as specified in the SF XML.
@ -222,7 +233,7 @@ THANDLE(SF_SERVICE_CONFIG(name)) SF_SERVICE_CONFIG_CREATE(name)(IFabricCodePacka
- **SRS_SF_SERVICE_CONFIG_42_024: [** If the value is an empty string then `SF_SERVICE_CONFIG_CREATE(name)` shall free the string and set it to `NULL`. **]**
- **SRS_SF_SERVICE_CONFIG_42_025: [** If the configuration value is `CONFIG_REQUIRED` and the value is `NULL` then `SF_SERVICE_CONFIG_CREATE(name)` shall fail and return `NULL`. **]**
- **SRS_SF_SERVICE_CONFIG_42_025: [** If the configuration value is `CONFIG_REQUIRED` or `CONFIG_REQUIRED_NO_LOGGING` and the value is `NULL` then `SF_SERVICE_CONFIG_CREATE(name)` shall fail and return `NULL`. **]**
- **SRS_SF_SERVICE_CONFIG_42_026: [** If the type is `wchar_ptr` then: **]**
@ -230,7 +241,7 @@ THANDLE(SF_SERVICE_CONFIG(name)) SF_SERVICE_CONFIG_CREATE(name)(IFabricCodePacka
- **SRS_SF_SERVICE_CONFIG_42_028: [** If the value is an empty string then `SF_SERVICE_CONFIG_CREATE(name)` shall free the string and set it to `NULL`. **]**
- **SRS_SF_SERVICE_CONFIG_42_029: [** If the configuration value is `CONFIG_REQUIRED` and the value is `NULL` then `SF_SERVICE_CONFIG_CREATE(name)` shall fail and return `NULL`. **]**
- **SRS_SF_SERVICE_CONFIG_42_029: [** If the configuration value is `CONFIG_REQUIRED` or `CONFIG_REQUIRED_NO_LOGGING` and the value is `NULL` then `SF_SERVICE_CONFIG_CREATE(name)` shall fail and return `NULL`. **]**
- **SRS_SF_SERVICE_CONFIG_42_030: [** If the type is `thandle_rc_string` then: **]**
@ -238,7 +249,7 @@ THANDLE(SF_SERVICE_CONFIG(name)) SF_SERVICE_CONFIG_CREATE(name)(IFabricCodePacka
- **SRS_SF_SERVICE_CONFIG_42_032: [** If the value is an empty string then `SF_SERVICE_CONFIG_CREATE(name)` shall free the string and set it to `NULL`. **]**
- **SRS_SF_SERVICE_CONFIG_42_033: [** If the configuration value is `CONFIG_REQUIRED` and the value is `NULL` then `SF_SERVICE_CONFIG_CREATE(name)` shall fail and return `NULL`. **]**
- **SRS_SF_SERVICE_CONFIG_42_033: [** If the configuration value is `CONFIG_REQUIRED` or `CONFIG_REQUIRED_NO_LOGGING` and the value is `NULL` then `SF_SERVICE_CONFIG_CREATE(name)` shall fail and return `NULL`. **]**
**SRS_SF_SERVICE_CONFIG_42_034: [** If there are any errors then `SF_SERVICE_CONFIG_CREATE(name)` shall fail and return `NULL`. **]**

Просмотреть файл

@ -106,10 +106,16 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
#define SF_SERVICE_CONFIG_EXPAND_PARAM_CONFIG_OPTIONAL(field_type, field_name) field_type, field_name
#define SF_SERVICE_CONFIG_EXPAND_PARAM_CONFIG_REQUIRED(field_type, field_name) field_type, field_name
// No logging flavors
#define SF_SERVICE_CONFIG_EXPAND_PARAM_CONFIG_REQUIRED_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_EXPAND_PARAM_CONFIG_REQUIRED(field_type, field_name)
#define SF_SERVICE_CONFIG_EXPAND_PARAM_CONFIG_OPTIONAL_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_EXPAND_PARAM_CONFIG_OPTIONAL(field_type, field_name)
#define SF_SERVICE_CONFIG_EXPAND_PARAM(count, field) MU_C2(SF_SERVICE_CONFIG_EXPAND_PARAM_, field) MU_IFCOMMALOGIC(MU_DEC(count))
#define SF_SERVICE_CONFIG_EXPAND_PARAM_WITH_REQUIRED_FLAG_CONFIG_OPTIONAL(field_type, field_name) field_type, field_name, 0
#define SF_SERVICE_CONFIG_EXPAND_PARAM_WITH_REQUIRED_FLAG_CONFIG_REQUIRED(field_type, field_name) field_type, field_name, 1
#define SF_SERVICE_CONFIG_EXPAND_PARAM_WITH_REQUIRED_FLAG_CONFIG_OPTIONAL(field_type, field_name) field_type, field_name, 0, 0
#define SF_SERVICE_CONFIG_EXPAND_PARAM_WITH_REQUIRED_FLAG_CONFIG_REQUIRED(field_type, field_name) field_type, field_name, 1, 0
// No logging flavors, the last param is "no logging", set to 1 to not log the value when reading it
#define SF_SERVICE_CONFIG_EXPAND_PARAM_WITH_REQUIRED_FLAG_CONFIG_OPTIONAL_NO_LOGGING(field_type, field_name) field_type, field_name, 0, 1
#define SF_SERVICE_CONFIG_EXPAND_PARAM_WITH_REQUIRED_FLAG_CONFIG_REQUIRED_NO_LOGGING(field_type, field_name) field_type, field_name, 1, 1
#define SF_SERVICE_CONFIG_EXPAND_PARAM_WITH_REQUIRED_FLAG(field) MU_C2(SF_SERVICE_CONFIG_EXPAND_PARAM_WITH_REQUIRED_FLAG_, field)
// This will strip the REQUIRED and OPTIONAL parts of the fields
@ -129,12 +135,16 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
#define SF_SERVICE_CONFIG_EXPAND_REQUIRED_CONFIG_OPTIONAL(field_type, field_name) SKIP , SKIP
#define SF_SERVICE_CONFIG_EXPAND_REQUIRED_CONFIG_REQUIRED(field_type, field_name) field_type, field_name
#define SF_SERVICE_CONFIG_EXPAND_REQUIRED_CONFIG_OPTIONAL_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_EXPAND_REQUIRED_CONFIG_OPTIONAL(field_type, field_name)
#define SF_SERVICE_CONFIG_EXPAND_REQUIRED_CONFIG_REQUIRED_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_EXPAND_REQUIRED_CONFIG_REQUIRED(field_type, field_name)
#define SF_SERVICE_CONFIG_EXPAND_REQUIRED(count, field) MU_C2(SF_SERVICE_CONFIG_EXPAND_REQUIRED_,field) MU_IFCOMMALOGIC(MU_DEC(count))
#define SF_SERVICE_CONFIG_EXPAND_REQUIRED_ONLY(...) MU_FOR_EACH_1_COUNTED(SF_SERVICE_CONFIG_EXPAND_REQUIRED, __VA_ARGS__)
#define SF_SERVICE_CONFIG_EXPAND_OPTIONAL_CONFIG_OPTIONAL(field_type, field_name) field_type, field_name
#define SF_SERVICE_CONFIG_EXPAND_OPTIONAL_CONFIG_REQUIRED(field_type, field_name) SKIP , SKIP
#define SF_SERVICE_CONFIG_EXPAND_OPTIONAL_CONFIG_OPTIONAL_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_EXPAND_OPTIONAL_CONFIG_OPTIONAL(field_type, field_name)
#define SF_SERVICE_CONFIG_EXPAND_OPTIONAL_CONFIG_REQUIRED_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_EXPAND_OPTIONAL_CONFIG_REQUIRED(field_type, field_name)
#define SF_SERVICE_CONFIG_EXPAND_OPTIONAL(count, field) MU_C2(SF_SERVICE_CONFIG_EXPAND_OPTIONAL_,field) MU_IFCOMMALOGIC(MU_DEC(count))
#define SF_SERVICE_CONFIG_EXPAND_OPTIONAL_ONLY(...) MU_FOR_EACH_1_COUNTED(SF_SERVICE_CONFIG_EXPAND_OPTIONAL, __VA_ARGS__)
@ -153,6 +163,8 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
#define SF_SERVICE_CONFIG_STRUCT_FIELD_CONFIG_OPTIONAL(field_type, field_name) field_type field_name;
#define SF_SERVICE_CONFIG_STRUCT_FIELD_CONFIG_REQUIRED(field_type, field_name) field_type field_name;
#define SF_SERVICE_CONFIG_STRUCT_FIELD_CONFIG_OPTIONAL_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_STRUCT_FIELD_CONFIG_OPTIONAL(field_type, field_name)
#define SF_SERVICE_CONFIG_STRUCT_FIELD_CONFIG_REQUIRED_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_STRUCT_FIELD_CONFIG_REQUIRED(field_type, field_name)
#define SF_SERVICE_CONFIG_STRUCT_FIELD(field) MU_C2(SF_SERVICE_CONFIG_STRUCT_FIELD_, field)
// Need extra layer of indirection so the SF_SERVICE_CONFIG_EXPAND_PARAMS() macro expands first
@ -203,7 +215,7 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
// Note that "error_occurred" is defined below "by convention"
/*Codes_SRS_SF_SERVICE_CONFIG_42_014: [ If the type is bool then: ]*/
#define SF_SERVICE_CONFIG_DO_READ__Bool(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null) \
#define SF_SERVICE_CONFIG_DO_READ__Bool(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging) \
result_value = false; \
if (!error_occurred_flag) \
{ \
@ -217,12 +229,19 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
} \
else \
{ \
LogVerbose("Config loaded: %ls = %" PRI_BOOL, parameter_string, MU_BOOL_VALUE(result_value)); \
if (no_logging) \
{ \
LogVerbose("Config loaded: %ls = ***", parameter_string); \
} \
else \
{ \
LogVerbose("Config loaded: %ls = %" PRI_BOOL "", parameter_string, MU_BOOL_VALUE(result_value)); \
} \
} \
}
/*Codes_SRS_SF_SERVICE_CONFIG_22_001: [ If the type is double then: ]*/
#define SF_SERVICE_CONFIG_DO_READ_double(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null) \
#define SF_SERVICE_CONFIG_DO_READ_double(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging) \
if (!error_occurred_flag) \
{ \
/*Codes_SRS_SF_SERVICE_CONFIG_22_002: [ SF_SERVICE_CONFIG_CREATE(name) shall call configuration_reader_get_double with the activation_context, sf_config_name, sf_parameters_section_name, and SF_SERVICE_CONFIG_PARAMETER_NAME_config_name. ]*/ \
@ -241,11 +260,18 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
} \
else \
{ \
LogVerbose("Config loaded: %ls = %lf", parameter_string, result_value); \
if (no_logging) \
{ \
LogVerbose("Config loaded: %ls = ***", parameter_string); \
} \
else \
{ \
LogVerbose("Config loaded: %ls = %lf", parameter_string, result_value); \
} \
} \
}
#define SF_SERVICE_CONFIG_DO_READ_integer_type(type, max_value, config, parameter_string, result_value, error_occurred_flag) \
#define SF_SERVICE_CONFIG_DO_READ_integer_type(type, max_value, config, parameter_string, result_value, error_occurred_flag, no_logging) \
if (!error_occurred_flag) \
{ \
/*Codes_SRS_SF_SERVICE_CONFIG_01_002: [ SF_SERVICE_CONFIG_CREATE(name) shall call configuration_reader_get_uint8_t with the activation_context, sf_config_name, sf_parameters_section_name, and SF_SERVICE_CONFIG_PARAMETER_NAME_config_name. ]*/ \
@ -268,23 +294,30 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
} \
else \
{ \
LogVerbose("Config loaded: %ls = %" MU_C2(PRI_, type), parameter_string, result_value); \
if (no_logging) \
{ \
LogVerbose("Config loaded: %ls = ***", parameter_string); \
} \
else \
{ \
LogVerbose("Config loaded: %ls = %" MU_C2(PRI_, type), parameter_string, result_value); \
} \
} \
}
/*Codes_SRS_SF_SERVICE_CONFIG_01_001: [ If the type is uint8_t then: ]*/
#define SF_SERVICE_CONFIG_DO_READ_uint8_t(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null) \
SF_SERVICE_CONFIG_DO_READ_integer_type(uint8_t, UINT8_MAX, config, parameter_string, result_value, error_occurred_flag)
#define SF_SERVICE_CONFIG_DO_READ_uint8_t(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging) \
SF_SERVICE_CONFIG_DO_READ_integer_type(uint8_t, UINT8_MAX, config, parameter_string, result_value, error_occurred_flag, no_logging)
/*Codes_SRS_SF_SERVICE_CONFIG_42_016: [ If the type is uint32_t then: ]*/
#define SF_SERVICE_CONFIG_DO_READ_uint32_t(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null) \
SF_SERVICE_CONFIG_DO_READ_integer_type(uint32_t, UINT32_MAX, config, parameter_string, result_value, error_occurred_flag)
#define SF_SERVICE_CONFIG_DO_READ_uint32_t(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging) \
SF_SERVICE_CONFIG_DO_READ_integer_type(uint32_t, UINT32_MAX, config, parameter_string, result_value, error_occurred_flag, no_logging)
/*Codes_SRS_SF_SERVICE_CONFIG_42_019: [ If the type is uint64_t then: ]*/
#define SF_SERVICE_CONFIG_DO_READ_uint64_t(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null) \
SF_SERVICE_CONFIG_DO_READ_integer_type(uint64_t, UINT64_MAX, config, parameter_string, result_value, error_occurred_flag)
#define SF_SERVICE_CONFIG_DO_READ_uint64_t(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging) \
SF_SERVICE_CONFIG_DO_READ_integer_type(uint64_t, UINT64_MAX, config, parameter_string, result_value, error_occurred_flag, no_logging)
#define SF_SERVICE_CONFIG_DO_READ_any_char_ptr(config, type, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null) \
#define SF_SERVICE_CONFIG_DO_READ_any_char_ptr(config, type, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging) \
result_value = NULL; \
if (!error_occurred_flag) \
{ \
@ -309,8 +342,8 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
MU_IF(fail_if_null, \
if (result_value == NULL) \
{ \
/*Codes_SRS_SF_SERVICE_CONFIG_42_025: [ If the configuration value is CONFIG_REQUIRED and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/ \
/*Codes_SRS_SF_SERVICE_CONFIG_42_029: [ If the configuration value is CONFIG_REQUIRED and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/ \
/*Codes_SRS_SF_SERVICE_CONFIG_42_025: [ If the configuration value is CONFIG_REQUIRED or CONFIG_REQUIRED_NO_LOGGING and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/ \
/*Codes_SRS_SF_SERVICE_CONFIG_42_029: [ If the configuration value is CONFIG_REQUIRED or CONFIG_REQUIRED_NO_LOGGING and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/ \
LogError("Invalid %ls=%" MU_C2(PRI_, type), parameter_string, SF_SERVICE_CONFIG_P_OR_NULL(type, result_value)); \
error_occurred_flag = true; \
} \
@ -318,21 +351,28 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
, \
) \
{ \
LogVerbose("Config loaded: %ls = %" MU_C2(PRI_, type), parameter_string, SF_SERVICE_CONFIG_P_OR_NULL(type, result_value)); \
if (no_logging) \
{ \
LogVerbose("Config loaded: %ls = ***", parameter_string); \
} \
else \
{ \
LogVerbose("Config loaded: %ls = %" MU_C2(PRI_, type), parameter_string, SF_SERVICE_CONFIG_P_OR_NULL(type, result_value)); \
} \
} \
} \
}
/*Codes_SRS_SF_SERVICE_CONFIG_42_022: [ If the type is char_ptr then: ]*/
#define SF_SERVICE_CONFIG_DO_READ_char_ptr(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null) \
SF_SERVICE_CONFIG_DO_READ_any_char_ptr(config, char_ptr, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null)
#define SF_SERVICE_CONFIG_DO_READ_char_ptr(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging) \
SF_SERVICE_CONFIG_DO_READ_any_char_ptr(config, char_ptr, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging)
/*Codes_SRS_SF_SERVICE_CONFIG_42_026: [ If the type is wchar_ptr then: ]*/
#define SF_SERVICE_CONFIG_DO_READ_wchar_ptr(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null) \
SF_SERVICE_CONFIG_DO_READ_any_char_ptr(config, wchar_ptr, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null)
#define SF_SERVICE_CONFIG_DO_READ_wchar_ptr(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging) \
SF_SERVICE_CONFIG_DO_READ_any_char_ptr(config, wchar_ptr, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging)
/*Codes_SRS_SF_SERVICE_CONFIG_42_030: [ If the type is thandle_rc_string then: ]*/
#define SF_SERVICE_CONFIG_DO_READ_thandle_rc_string(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null) \
#define SF_SERVICE_CONFIG_DO_READ_thandle_rc_string(config, field_name, parameter_string, result_value, error_occurred_flag, fail_if_null, no_logging) \
THANDLE_INITIALIZE(RC_STRING)(&result_value, NULL); \
if (!error_occurred_flag) \
{ \
@ -354,7 +394,7 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
MU_IF(fail_if_null, \
if (result_value == NULL) \
{ \
/*Codes_SRS_SF_SERVICE_CONFIG_42_033: [ If the configuration value is CONFIG_REQUIRED and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/ \
/*Codes_SRS_SF_SERVICE_CONFIG_42_033: [ If the configuration value is CONFIG_REQUIRED or CONFIG_REQUIRED_NO_LOGGING and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/ \
LogError("Invalid %ls=%" PRI_RC_STRING, parameter_string, RC_STRING_VALUE_OR_NULL(result_value)); \
error_occurred_flag = true; \
} \
@ -362,10 +402,14 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
, \
) \
{ \
/* We should not be logging some very important configs like connection strings, this is an emergency disable of logging for all THANDLE(RC_STRING) */ \
/* and the follow up will be with this task: https://msazure.visualstudio.com/One/_workitems/edit/28237410 */ \
LogVerbose("Config loaded: %ls = *** not logging due to credential leak ***", parameter_string); \
/* LogVerbose("Config loaded: %ls = %" PRI_RC_STRING, parameter_string, RC_STRING_VALUE_OR_NULL(result_value));*/ \
if (no_logging) \
{ \
LogVerbose("Config loaded: %ls = ***", parameter_string); \
} \
else \
{ \
LogVerbose("Config loaded: %ls = %" PRI_RC_STRING, parameter_string, RC_STRING_VALUE_OR_NULL(result_value)); \
} \
} \
} \
}
@ -381,9 +425,9 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
MU_IF(SF_SERVICE_CONFIG_IS_TYPE_SKIP(field_type),, \
MU_C2(SF_SERVICE_CONFIG_DO_READ_, field_type)(handle, field_name, SF_SERVICE_CONFIG_PARAMETER_NAME(field_name), handle->field_name, error_occurred, 0) \
)
#define SF_SERVICE_CONFIG_DO_READ_EITHER(handle, field_type, field_name, is_required) \
#define SF_SERVICE_CONFIG_DO_READ_EITHER(handle, field_type, field_name, is_required, no_logging) \
MU_IF(SF_SERVICE_CONFIG_IS_TYPE_SKIP(field_type),, \
MU_C2(SF_SERVICE_CONFIG_DO_READ_, field_type)(handle, field_name, SF_SERVICE_CONFIG_PARAMETER_NAME(field_name), handle->field_name, error_occurred, is_required) \
MU_C2(SF_SERVICE_CONFIG_DO_READ_, field_type)(handle, field_name, SF_SERVICE_CONFIG_PARAMETER_NAME(field_name), handle->field_name, error_occurred, is_required, no_logging) \
)
#define SF_SERVICE_CONFIG_DO_READ(handle, config) SF_SERVICE_CONFIG_EXPAND_MACRO_HELPER(SF_SERVICE_CONFIG_DO_READ_EITHER, handle, SF_SERVICE_CONFIG_EXPAND_PARAM_WITH_REQUIRED_FLAG(config))
@ -465,10 +509,14 @@ typedef THANDLE(RC_STRING) thandle_rc_string;
#define SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_OPTIONAL(field_type, field_name) field_type
#define SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_REQUIRED(field_type, field_name) field_type
#define SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_OPTIONAL_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_OPTIONAL(field_type, field_name)
#define SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_REQUIRED_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_REQUIRED(field_type, field_name)
#define SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD(field) MU_C2(SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_, field)
#define SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_OPTIONAL(field_type, field_name) field_name
#define SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_REQUIRED(field_type, field_name) field_name
#define SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_OPTIONAL_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_OPTIONAL(field_type, field_name)
#define SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_REQUIRED_NO_LOGGING(field_type, field_name) SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_REQUIRED(field_type, field_name)
#define SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD(field) MU_C2(SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_, field)
#define DO_CLEANUP_IF_NEEDED(handle, field) \

Просмотреть файл

@ -76,6 +76,16 @@ TEST_SF_SERVICE_CONFIG_DEFINE_EXPECTED_CALL_HELPERS(my_config, expected_config_p
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_string_option_optional L"OptionalStringOption"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_wide_string_option_optional L"OptionalWideStringOption"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_another_flag L"AnotherFlag"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_a_secret L"ASecret"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_a_secret_uint8_t L"ASecretUInt8"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_a_secret_char_ptr L"ASecretCharPtr"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_a_secret_double L"ASecretDouble"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_a_secret_bool L"ASecretBool"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_another_secret L"AnotherSecret"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_another_secret_uint8_t L"AnotherSecretUInt8"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_another_secret_char_ptr L"AnotherSecretCharPtr"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_another_secret_double L"AnotherSecretDouble"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_mocked_another_secret_bool L"AnotherSecretBool"
#define MY_MOCKED_CONFIG_TEST_PARAMS \
CONFIG_REQUIRED(uint64_t, mocked_parameter_1), \
@ -90,7 +100,17 @@ TEST_SF_SERVICE_CONFIG_DEFINE_EXPECTED_CALL_HELPERS(my_config, expected_config_p
CONFIG_OPTIONAL(thandle_rc_string, mocked_string_option_in_thandle_optional), \
CONFIG_OPTIONAL(char_ptr, mocked_string_option_optional), \
CONFIG_OPTIONAL(wchar_ptr, mocked_wide_string_option_optional), \
CONFIG_REQUIRED(bool, mocked_another_flag) \
CONFIG_REQUIRED(bool, mocked_another_flag), \
CONFIG_REQUIRED_NO_LOGGING(thandle_rc_string, a_secret), \
CONFIG_REQUIRED_NO_LOGGING(uint8_t, a_secret_uint8_t), \
CONFIG_REQUIRED_NO_LOGGING(char_ptr, a_secret_char_ptr), \
CONFIG_REQUIRED_NO_LOGGING(double, a_secret_double), \
CONFIG_REQUIRED_NO_LOGGING(bool, a_secret_bool), \
CONFIG_OPTIONAL_NO_LOGGING(thandle_rc_string, another_secret), \
CONFIG_OPTIONAL_NO_LOGGING(uint8_t, another_secret_uint8_t), \
CONFIG_OPTIONAL_NO_LOGGING(char_ptr, another_secret_char_ptr), \
CONFIG_OPTIONAL_NO_LOGGING(double, another_secret_double), \
CONFIG_OPTIONAL_NO_LOGGING(bool, another_secret_bool) \
DECLARE_SF_SERVICE_CONFIG(my_mocked_config, MY_MOCKED_CONFIG_TEST_PARAMS)
@ -423,7 +443,7 @@ TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_empty_optional_thandle_rc_string_suc
/*Tests_SRS_SF_SERVICE_CONFIG_42_022: [ If the type is char_ptr then: ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_023: [ SF_SERVICE_CONFIG_CREATE(name) shall call configuration_reader_get_char_string with the activation_context, sf_config_name, sf_parameters_section_name, and SF_SERVICE_CONFIG_PARAMETER_NAME_config_name. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_024: [ If the value is an empty string then SF_SERVICE_CONFIG_CREATE(name) shall free the string and set it to NULL. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_025: [ If the configuration value is CONFIG_REQUIRED and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_025: [ If the configuration value is CONFIG_REQUIRED or CONFIG_REQUIRED_NO_LOGGING and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_empty_required_string_fails)
{
// arrange
@ -440,7 +460,7 @@ TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_empty_required_string_fails)
/*Tests_SRS_SF_SERVICE_CONFIG_42_022: [ If the type is char_ptr then: ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_023: [ SF_SERVICE_CONFIG_CREATE(name) shall call configuration_reader_get_char_string with the activation_context, sf_config_name, sf_parameters_section_name, and SF_SERVICE_CONFIG_PARAMETER_NAME_config_name. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_025: [ If the configuration value is CONFIG_REQUIRED and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_025: [ If the configuration value is CONFIG_REQUIRED or CONFIG_REQUIRED_NO_LOGGING and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_NULL_required_string_fails)
{
// arrange
@ -458,7 +478,7 @@ TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_NULL_required_string_fails)
/*Tests_SRS_SF_SERVICE_CONFIG_42_026: [ If the type is wchar_ptr then: ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_027: [ SF_SERVICE_CONFIG_CREATE(name) shall call configuration_reader_get_wchar_string with the activation_context, sf_config_name, sf_parameters_section_name, and SF_SERVICE_CONFIG_PARAMETER_NAME_config_name. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_028: [ If the value is an empty string then SF_SERVICE_CONFIG_CREATE(name) shall free the string and set it to NULL. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_029: [ If the configuration value is CONFIG_REQUIRED and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_029: [ If the configuration value is CONFIG_REQUIRED or CONFIG_REQUIRED_NO_LOGGING and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_empty_required_wide_string_fails)
{
// arrange
@ -475,7 +495,7 @@ TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_empty_required_wide_string_fails)
/*Tests_SRS_SF_SERVICE_CONFIG_42_026: [ If the type is wchar_ptr then: ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_027: [ SF_SERVICE_CONFIG_CREATE(name) shall call configuration_reader_get_wchar_string with the activation_context, sf_config_name, sf_parameters_section_name, and SF_SERVICE_CONFIG_PARAMETER_NAME_config_name. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_029: [ If the configuration value is CONFIG_REQUIRED and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_029: [ If the configuration value is CONFIG_REQUIRED or CONFIG_REQUIRED_NO_LOGGING and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_NULL_required_wide_string_fails)
{
// arrange
@ -493,7 +513,7 @@ TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_NULL_required_wide_string_fails)
/*Tests_SRS_SF_SERVICE_CONFIG_42_030: [ If the type is thandle_rc_string then: ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_031: [ SF_SERVICE_CONFIG_CREATE(name) shall call configuration_reader_get_thandle_rc_string with the activation_context, sf_config_name, sf_parameters_section_name, and SF_SERVICE_CONFIG_PARAMETER_NAME_config_name. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_032: [ If the value is an empty string then SF_SERVICE_CONFIG_CREATE(name) shall free the string and set it to NULL. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_033: [ If the configuration value is CONFIG_REQUIRED and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_033: [ If the configuration value is CONFIG_REQUIRED or CONFIG_REQUIRED_NO_LOGGING and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_empty_required_thandle_rcstring_fails)
{
// arrange
@ -510,7 +530,7 @@ TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_empty_required_thandle_rcstring_fail
/*Tests_SRS_SF_SERVICE_CONFIG_42_030: [ If the type is thandle_rc_string then: ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_031: [ SF_SERVICE_CONFIG_CREATE(name) shall call configuration_reader_get_thandle_rc_string with the activation_context, sf_config_name, sf_parameters_section_name, and SF_SERVICE_CONFIG_PARAMETER_NAME_config_name. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_033: [ If the configuration value is CONFIG_REQUIRED and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
/*Tests_SRS_SF_SERVICE_CONFIG_42_033: [ If the configuration value is CONFIG_REQUIRED or CONFIG_REQUIRED_NO_LOGGING and the value is NULL then SF_SERVICE_CONFIG_CREATE(name) shall fail and return NULL. ]*/
TEST_FUNCTION(SF_SERVICE_CONFIG_CREATE_with_NULL_required_thandle_rcstring_fails)
{
// arrange

Просмотреть файл

@ -29,10 +29,14 @@
#define TEST_SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_OPTIONAL(field_type, field_name) field_type
#define TEST_SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_REQUIRED(field_type, field_name) field_type
#define TEST_SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_OPTIONAL_NO_LOGGING(field_type, field_name) TEST_SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_OPTIONAL(field_type, field_name)
#define TEST_SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_REQUIRED_NO_LOGGING(field_type, field_name) TEST_SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_CONFIG_REQUIRED(field_type, field_name)
#define TEST_SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD(field) MU_C2(TEST_SF_SERVICE_CONFIG_FIELD_TYPE_FROM_FIELD_, field)
#define TEST_SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_OPTIONAL(field_type, field_name) field_name
#define TEST_SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_REQUIRED(field_type, field_name) field_name
#define TEST_SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_OPTIONAL_NO_LOGGING(field_type, field_name) TEST_SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_OPTIONAL(field_type, field_name)
#define TEST_SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_REQUIRED_NO_LOGGING(field_type, field_name) TEST_SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_CONFIG_REQUIRED(field_type, field_name)
#define TEST_SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD(field) MU_C2(TEST_SF_SERVICE_CONFIG_FIELD_NAME_FROM_FIELD_, field)
// Setup the test hooks for configuration_reader to return configured values

Просмотреть файл

@ -26,6 +26,16 @@
#define SF_SERVICE_CONFIG_PARAMETER_NAME_string_option_optional L"OptionalStringOption"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_wide_string_option_optional L"OptionalWideStringOption"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_another_flag L"AnotherFlag"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_a_secret L"ASecret"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_a_secret_uint8_t L"ASecretUint8t"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_a_secret_char_ptr L"ASecretCharPtr"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_a_secret_double L"ASecretDouble"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_a_secret_bool L"ASecretBool"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_another_secret L"AnotherSecret"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_another_secret_uint8_t L"AnotherSecretUint8t"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_another_secret_char_ptr L"AnotherSecretCharPtr"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_another_secret_double L"AnotherSecretDouble"
#define SF_SERVICE_CONFIG_PARAMETER_NAME_another_secret_bool L"AnotherSecretBool"
#define MY_CONFIG_TEST_PARAMS \
CONFIG_REQUIRED(uint64_t, parameter_1), \
@ -40,7 +50,17 @@
CONFIG_OPTIONAL(thandle_rc_string, string_option_in_thandle_optional), \
CONFIG_OPTIONAL(char_ptr, string_option_optional), \
CONFIG_OPTIONAL(wchar_ptr, wide_string_option_optional), \
CONFIG_REQUIRED(bool, another_flag) \
CONFIG_REQUIRED(bool, another_flag), \
CONFIG_REQUIRED_NO_LOGGING(thandle_rc_string, a_secret), \
CONFIG_REQUIRED_NO_LOGGING(uint8_t, a_secret_uint8_t), \
CONFIG_REQUIRED_NO_LOGGING(char_ptr, a_secret_char_ptr), \
CONFIG_REQUIRED_NO_LOGGING(double, a_secret_double), \
CONFIG_REQUIRED_NO_LOGGING(bool, a_secret_bool), \
CONFIG_OPTIONAL_NO_LOGGING(thandle_rc_string, another_secret), \
CONFIG_OPTIONAL_NO_LOGGING(uint8_t, another_secret_uint8_t), \
CONFIG_OPTIONAL_NO_LOGGING(char_ptr, another_secret_char_ptr), \
CONFIG_OPTIONAL_NO_LOGGING(double, another_secret_double), \
CONFIG_OPTIONAL_NO_LOGGING(bool, another_secret_bool) \
DECLARE_SF_SERVICE_CONFIG(my_config, MY_CONFIG_TEST_PARAMS)