Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add command line/environment flag for commonConfig #486

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/c/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@

#define DS_PARAMLIST { DS_PUSH, DS_RETURN }

/* Path segments */

#define ALL_SVCS_NODE "all-services"
#define DEV_SVCS_NODE "device-services"

#endif
3 changes: 0 additions & 3 deletions src/c/consul.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

#define CONF_PREFIX "edgex/v3/"

#define ALL_SVCS_NODE "all-services"
#define DEV_SVCS_NODE "device-services"

typedef struct consul_impl_t
{
iot_logger_t *lc;
Expand Down
105 changes: 105 additions & 0 deletions src/c/examples/commonconfiguration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
all-services:
Writable:
InsecureSecrets:
DB:
path: "redisdb"
Secrets:
username: ""
password: ""
SecretName: "redisdb"
SecretData:
username: ""
password: ""

Telemetry:
Interval: "30s"
Metrics:
# Common Security Service Metrics
SecuritySecretsRequested: false
SecuritySecretsStored: false
SecurityConsulTokensRequested: false
SecurityConsulTokenDuration: false
# Tags: # Contains the service level tags to be attached to all the service's metrics
# Gateway: "my-iot-gateway" # Tag must be added here or via Consul Env Override can only change existing value, not added new ones.

Service:
HealthCheckInterval: "10s"
Host: "localhost"
ServerBindAddr: "" # Leave blank so default to Host value unless different value is needed.
MaxResultCount: 1024
MaxRequestSize: 0 # Not currently used. Defines the maximum size of http request body in bytes
RequestTimeout: "5s"
CORSConfiguration:
EnableCORS: false
CORSAllowCredentials: false
CORSAllowedOrigin: "https://localhost"
CORSAllowedMethods: "GET, POST, PUT, PATCH, DELETE"
CORSAllowedHeaders: "Authorization, Accept, Accept-Language, Content-Language, Content-Type, X-Correlation-ID"
CORSExposeHeaders: "Cache-Control, Content-Language, Content-Length, Content-Type, Expires, Last-Modified, Pragma, X-Correlation-ID"
CORSMaxAge: 3600

Registry:
Host: "localhost"
Port: 8500
Type: "consul"

Database:
Host: "localhost"
Port: 6379
Timeout: 5000
Type: "redisdb"

MessageBus:
Protocol: "redis"
Host: "localhost"
Port: 6379
Type: "redis"
AuthMode: "usernamepassword" # required for redis MessageBus (secure or insecure).
SecretName: "redisdb"
BaseTopicPrefix: "edgex" # prepended to all topics as "edgex/<additional topic levels>
Optional:
# Default MQTT Specific options that need to be here to enable environment variable overrides of them
Qos: "0" # Quality of Service values are 0 (At most once), 1 (At least once) or 2 (Exactly once)
KeepAlive: "10" # Seconds (must be 2 or greater)
Retained: "false"
AutoReconnect: "true"
ConnectTimeout: "5" # Seconds
SkipCertVerify: "false"
# Additional Default NATS Specific options that need to be here to enable environment variable overrides of them
Format: "nats"
RetryOnFailedConnect: "true"
QueueGroup: ""
Durable: ""
AutoProvision: "true"
Deliver: "new"
DefaultPubRetryAttempts: "2"
Subject: "edgex/#" # Required for NATS JetStream only for stream auto-provisioning

device-services:
MaxEventSize: 0 # value 0 represents unlimited maximum event size that can be sent to message bus or core-data
Writable:
Reading:
ReadingUnits: true
Telemetry:
Metrics:
EventsSent: false
ReadingsSent: false
Clients:
core-metadata:
Protocol: "http"
Host: "localhost"
Port: 59881
Device:
DataTransform: true
MaxCmdOps: 128
MaxCmdValueLen: 256
ProfilesDir: "./res/profiles"
DevicesDir: "./res/devices"
# ProvisionWatchersDir is omitted here since most Device Services don't use it.
# Those that do will have it in their private config
EnableAsyncReadings: true
AsyncBufferSize: 16
Labels: []
Discovery:
Enabled: false
Interval: "30s"
36 changes: 31 additions & 5 deletions src/c/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void devsdk_usage ()
{
printf (" -cp, --configProvider=<url>\tIndicates to use Configuration Provider service at specified URL.\n"
" \tURL Format: {type}.{protocol}://{host}:{port} ex: consul.http://localhost:8500\n");
printf (" -cc, --commonConfig \tTakes the location where the common configuration is loaded from when not using the Configuration Provider\n");
printf (" -o, --overwrite \tOverwrite configuration in provider with local configuration.\n"
" \t*** Use with cation *** Use will clobber existing settings in provider,\n"
" \tproblematic if those settings were edited by hand intentionally\n");
Expand Down Expand Up @@ -148,6 +149,7 @@ static bool processCmdLine (int *argc_p, char **argv, devsdk_service_t *svc)
if
(
testArg (arg, val, "-cp", "--configProvider", &svc->regURL, &result) ||
testArg (arg, val, "-cc", "--commonConfig", &svc->commonconffile, &result) ||
testArg (arg, val, "-i", "--instance", (const char **)&svc->name, &result) ||
testArg (arg, val, "-p", "--profile", &svc->profile, &result) ||
testArg (arg, val, "-cd", "--configDir", &svc->confdir, &result) ||
Expand Down Expand Up @@ -176,6 +178,7 @@ static bool processCmdLine (int *argc_p, char **argv, devsdk_service_t *svc)
*argc_p = argc;

checkEnv (&svc->regURL, "EDGEX_CONFIG_PROVIDER");
checkEnv (&svc->commonconffile, "EDGEX_COMMON_CONFIG");
checkEnv (&svc->profile, "EDGEX_PROFILE");
checkEnv (&svc->confdir, "EDGEX_CONFIG_DIR");
checkEnv (&svc->conffile, "EDGEX_CONFIG_FILE");
Expand Down Expand Up @@ -830,9 +833,9 @@ static void startConfigured (devsdk_service_t *svc, const devsdk_timeout *deadli

void devsdk_service_start (devsdk_service_t *svc, iot_data_t *driverdfls, devsdk_error *err)
{
iot_data_t *config_file = NULL;
iot_data_t *config_file, *common_config_file = NULL;
bool uploadConfig = false;
iot_data_t *common_config_map, *private_config_map, *configmap;
iot_data_t *common_config_map, *private_config_map, *configmap, *deviceservices_config;

if (svc->starttime)
{
Expand All @@ -854,7 +857,29 @@ void devsdk_service_start (devsdk_service_t *svc, iot_data_t *driverdfls, devsdk
iot_log_error (svc->logger, "Unable to load config file: %s", err->reason);
return;
}

common_config_map = edgex_common_config_defaults (svc->name);

if (!svc->regURL)
{
common_config_file = edgex_device_loadConfig (svc->logger, svc->commonconffile, err);
if (err->code)
{
iot_log_error (svc->logger, "Unable to load common config file: %s", err->reason);
return;
}
iot_data_t *allservices_config = iot_data_string_map_get_map(common_config_file, ALL_SVCS_NODE);
deviceservices_config = iot_data_string_map_get_map(common_config_file, DEV_SVCS_NODE);
if (allservices_config)
{
edgex_device_overrideConfig_map(common_config_map, allservices_config);
}
if (deviceservices_config)
{
edgex_device_overrideConfig_map(common_config_map, deviceservices_config);
}
}

private_config_map = edgex_private_config_defaults(driverdfls);
edgex_device_overrideConfig_map (common_config_map, config_file);
edgex_device_overrideConfig_map (private_config_map, config_file);
Expand All @@ -864,7 +889,6 @@ void devsdk_service_start (devsdk_service_t *svc, iot_data_t *driverdfls, devsdk
configmap = iot_data_alloc_map (IOT_DATA_STRING);
iot_data_map_merge(configmap, common_config_map);
iot_data_map_merge(configmap, private_config_map);
iot_data_free(common_config_map);

/* Set up SecretStore */

Expand Down Expand Up @@ -999,11 +1023,13 @@ void devsdk_service_start (devsdk_service_t *svc, iot_data_t *driverdfls, devsdk
}
else
{
edgex_device_parseClients (svc->logger, iot_data_string_map_get (config_file, "Clients"), &svc->config.endpoints);
edgex_device_parseClients (svc->logger, iot_data_string_map_get (deviceservices_config, "Clients"), &svc->config.endpoints);
}

iot_data_free (config_file);
iot_data_free(private_config_map);
iot_data_free (common_config_file);
iot_data_free (common_config_map);
iot_data_free (private_config_map);

iot_log_info (svc->logger, "Starting %s device service, version %s", svc->name, svc->version);
iot_log_info (svc->logger, "EdgeX device SDK for C, version " CSDK_VERSION_STR);
Expand Down
1 change: 1 addition & 0 deletions src/c/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct devsdk_service_t
const char *profile;
const char *confdir;
const char *conffile;
const char *commonconffile;
char *confpath;
void *userdata;
devsdk_callbacks userfns;
Expand Down