Skip to content
API Documentation
BastionGuard™
IdentityLeakConfig Class Reference

#include <IdentityLeakConfig.hpp>

Static Public Member Functions

static std::string hibpApiKey ()
static void setHibpApiKey (const std::string &)
static std::string leakCheckApiKey ()
static void setLeakCheckApiKey (const std::string &)
static bool monitorEnabled ()
static void setMonitorEnabled (bool)

Static Private Member Functions

static std::string configPath ()
static nlohmann::json loadJson ()
static void saveJson (const nlohmann::json &j)

Detailed Description

Definition at line 26 of file IdentityLeakConfig.hpp.

Member Function Documentation

◆ configPath()

std::string IdentityLeakConfig::configPath ( )
staticprivate

Definition at line 34 of file IdentityLeakConfig.cpp.

35{
36 const char* home = std::getenv("HOME");
37 if (!home)
38 return {};
39
40 std::filesystem::path dir =
41 std::filesystem::path(home) / CONFIG_DIR;
42
43 std::filesystem::create_directories(dir);
44
45 return (dir / CONFIG_FILE).string();
46}
static const char * CONFIG_FILE
static const char * CONFIG_DIR

References CONFIG_DIR, and CONFIG_FILE.

Referenced by loadJson(), and saveJson().

◆ hibpApiKey()

std::string IdentityLeakConfig::hibpApiKey ( )
static

Definition at line 69 of file IdentityLeakConfig.cpp.

70{
71 auto j = loadJson();
72 return j.value("hibp_api_key", "");
73}
static nlohmann::json loadJson()

References loadJson().

Referenced by IdentityLeakPage::IdentityLeakPage(), LeakMonitor::loop(), and LeakCheckWorker::run().

◆ leakCheckApiKey()

std::string IdentityLeakConfig::leakCheckApiKey ( )
static

Definition at line 82 of file IdentityLeakConfig.cpp.

83{
84 auto j = loadJson();
85 return j.value("leakcheck_api_key", "");
86}

References loadJson().

Referenced by IdentityLeakPage::IdentityLeakPage().

◆ loadJson()

json IdentityLeakConfig::loadJson ( )
staticprivate

Definition at line 48 of file IdentityLeakConfig.cpp.

49{
50 std::ifstream in(configPath());
51 if (!in)
52 return json::object();
53
54 json j;
55 try {
56 in >> j;
57 } catch (...) {
58 return json::object();
59 }
60 return j;
61}
nlohmann::json json
Definition Backend.cpp:2908
static std::string configPath()

References configPath().

Referenced by hibpApiKey(), leakCheckApiKey(), monitorEnabled(), setHibpApiKey(), setLeakCheckApiKey(), and setMonitorEnabled().

◆ monitorEnabled()

bool IdentityLeakConfig::monitorEnabled ( )
static

Definition at line 96 of file IdentityLeakConfig.cpp.

97{
98 auto j = loadJson();
99 return j.value("monitor_enabled", false);
100}

References loadJson().

Referenced by IdentityLeakPage::IdentityLeakPage(), and IdentityLeakPage::onCheckClicked().

◆ saveJson()

void IdentityLeakConfig::saveJson ( const nlohmann::json & j)
staticprivate

Definition at line 63 of file IdentityLeakConfig.cpp.

64{
65 std::ofstream out(configPath());
66 out << j.dump(4);
67}

References configPath().

Referenced by setHibpApiKey(), setLeakCheckApiKey(), and setMonitorEnabled().

◆ setHibpApiKey()

void IdentityLeakConfig::setHibpApiKey ( const std::string & key)
static

Definition at line 75 of file IdentityLeakConfig.cpp.

76{
77 auto j = loadJson();
78 j["hibp_api_key"] = key;
79 saveJson(j);
80}
static void saveJson(const nlohmann::json &j)

References loadJson(), and saveJson().

Referenced by IdentityLeakPage::onSaveHibpApi().

◆ setLeakCheckApiKey()

void IdentityLeakConfig::setLeakCheckApiKey ( const std::string & key)
static

Definition at line 88 of file IdentityLeakConfig.cpp.

89{
90 auto j = loadJson();
91 j["leakcheck_api_key"] = key;
92 saveJson(j);
93}

References loadJson(), and saveJson().

Referenced by IdentityLeakPage::onSaveLeakCheckApi().

◆ setMonitorEnabled()

void IdentityLeakConfig::setMonitorEnabled ( bool enabled)
static

Definition at line 102 of file IdentityLeakConfig.cpp.

103{
104 auto j = loadJson();
105 j["monitor_enabled"] = enabled;
106 saveJson(j);
107}

References loadJson(), and saveJson().

Referenced by IdentityLeakPage::onMonitorToggled().


The documentation for this class was generated from the following files: