Skip to content

Commit

Permalink
samples: cellular: nrf_cloud_rest_*: make credentials check optional
Browse files Browse the repository at this point in the history
This patch makes it possible to build the nRF Cloud REST samples without
checking the credentials. Jira: IRIS-9758

Signed-off-by: Maximilian Deubel <[email protected]>
  • Loading branch information
maxd-nordic committed Nov 12, 2024
1 parent 27bf358 commit 4a70e91
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions samples/cellular/nrf_cloud_rest_cell_location/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ static void connect_to_network(void)

static void check_credentials(void)
{
#if defined(CONFIG_NRF_CLOUD_CHECK_CREDENTIALS)
int err = nrf_cloud_credentials_configured_check();

if ((err == -ENOTSUP) || (err == -ENOPROTOOPT)) {
Expand All @@ -589,6 +590,9 @@ static void check_credentials(void)
LOG_ERR("nrf_cloud_credentials_configured_check() failed, error: %d", err);
LOG_WRN("Continuing without verifying that credentials are installed");
}
#else
LOG_WRN("nRF Cloud credentials check not enabled");
#endif /* defined(CONFIG_NRF_CLOUD_CHECK_CREDENTIALS) */
}

int main(void)
Expand Down
27 changes: 17 additions & 10 deletions samples/cellular/nrf_cloud_rest_device_message/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ static int set_leds_off(void)

static bool cred_check(struct nrf_cloud_credentials_status *const cs)
{
#if defined(CONFIG_NRF_CLOUD_CHECK_CREDENTIALS)
int ret;

ret = nrf_cloud_credentials_check(cs);
Expand All @@ -248,24 +249,30 @@ static bool cred_check(struct nrf_cloud_credentials_status *const cs)
* - a CA for the TLS connections
* - a private key to sign the JWT
*/

if (!cs->ca || !cs.ca_aws || !cs->prv_key) {
LOG_WRN("Missing required nRF Cloud credential(s) in sec tag %u:",
cs.sec_tag);
}
if (!cs.ca || !cs.ca_aws) {
LOG_WRN("\t-CA Cert");
}
if (!cs.prv_key) {
LOG_WRN("\t-Private Key");
}

return (cs->ca && cs->ca_aws && cs->prv_key);
#else
LOG_WRN("nRF Cloud credentials check not enabled");
return true;
#endif /* defined(CONFIG_NRF_CLOUD_CHECK_CREDENTIALS) */
}

static void await_credentials(void)
{
struct nrf_cloud_credentials_status cs;

if (!cred_check(&cs)) {
LOG_WRN("Missing required nRF Cloud credential(s) in sec tag %u:",
cs.sec_tag);

if (!cs.ca) {
LOG_WRN("\t-CA Cert");
}

if (!cs.prv_key) {
LOG_WRN("\t-Private Key");
}

#if defined(CONFIG_NRF_PROVISIONING)
LOG_INF("Waiting for credentials to be remotely provisioned...");
Expand Down
4 changes: 4 additions & 0 deletions samples/cellular/nrf_cloud_rest_fota/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ static void sample_reboot(enum nrf_cloud_fota_reboot_status status)

static void check_credentials(void)
{
#if defined(CONFIG_NRF_CLOUD_CHECK_CREDENTIALS)
int err = nrf_cloud_credentials_configured_check();

if (err == -ENOTSUP) {
Expand All @@ -485,6 +486,9 @@ static void check_credentials(void)
LOG_ERR("nrf_cloud_credentials_configured_check() failed, error: %d", err);
LOG_WRN("Continuing without verifying that credentials are installed");
}
#else
LOG_WRN("nRF Cloud credentials check not enabled");
#endif /* defined(CONFIG_NRF_CLOUD_CHECK_CREDENTIALS) */
}

int main(void)
Expand Down

0 comments on commit 4a70e91

Please sign in to comment.