Skip to content

Commit

Permalink
Make secrets.h more immune to changes from secrets.example.h
Browse files Browse the repository at this point in the history
When new fields are added in the example file, add a test in the
file that uses the real file to be sure the fields are present. This
is to solve the case where a developer has a checked-out, working tree
with a working secrets.h, syncs to head or another branch that adds
fields in secrets, and then incurs weird compilation errors when those
new fields aren't found.

This change leads the developer to the correct file and the doc
describing it for a better experience.
  • Loading branch information
robertlipe committed Dec 24, 2023
1 parent e7fa318 commit 9c05269
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion include/deviceconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,46 @@
#include <tuple>
#include <algorithm>
#include "jsonserializer.h"

#if !__has_include("secrets.h")
#error Copy include/secrets-example.h to include/secrets.h, edit to taste, and retry. Please see README.md
#endif

#include "secrets.h"

#if !defined(cszSSID)
#error A definition for cszSSID is missing from secrets.h
#endif

#if !defined(cszPassword)
#error A definition for cszSSID is missing from secrets.h
#endif

#if !defined(cszHostname)
#error A definition for cszHostname is missing from secrets.h
#endif

#if !defined(cszOpenWeatherAPIKey)
#error A definition for cszOpenWeatherAPIKey is missing from secrets.h
#endif

#if !defined(cszLocation)
#error A definition for cszLocation is missing from secrets.h
#endif

#if !defined(bLocationIsZip)
#error A definition for bLocationIsZip is missing from secrets.h
#endif

#if !defined(cszCountryCode)
#error A definition for cszCountryCode is missing from secrets.h
#endif

#if !defined(cszTimeZone)
#error A definition for cszTimeZone is missing from secrets.h
#endif


#define DEVICE_CONFIG_FILE "/device.cfg"
#define NTP_SERVER_DEFAULT "0.pool.ntp.org"
#define BRIGHTNESS_MIN uint8_t(10)
Expand All @@ -56,6 +94,8 @@
// (in deviceconfig.cpp)
// 5. Adding (de)serialization logic for the setting to the SerializeToJSON()/DeserializeFromJSON() methods
// 6. Adding a Get/Set method for the setting (and, where applicable, their implementation in deviceconfig.cpp)
// 7. If you've added an entry to secrets.example.h add a test at the top of this file to confirm that the new #defines were found. This prevents drift when developers have an existing tree and don't know to refresh their modified version of secrets.h

//
// For the first 5 points, a comment has been added to the respective place in the existing code.
// Generally speaking, one will also want to add logic to the webserver to retrieve and set the setting.
Expand Down Expand Up @@ -543,4 +583,4 @@ class DeviceConfig : public IJSONSerializable

void SetColorSettings(const CRGB& globalColor, const CRGB& secondColor);
void ApplyColorSettings(std::optional<CRGB> globalColor, std::optional<CRGB> secondColor, bool clearGlobalColor, bool applyGlobalColor);
};
};

0 comments on commit 9c05269

Please sign in to comment.