From 351deb2ce1898f94a1bf1a10a90608f875c99cba Mon Sep 17 00:00:00 2001 From: lexara-prime-ai Date: Wed, 13 Nov 2024 18:02:11 +0000 Subject: [PATCH] Add env. manager --- .gitmodules | 3 +++ Makefile | 2 +- librender_cdk/extern/dotenv-cpp | 1 + librender_cdk/src/environment_manager.cpp | 24 +++++++++++++++++++ librender_cdk/src/environment_manager.h | 13 +++++++++++ librender_cdk/src/main.cpp | 28 +++++++++++++++++------ 6 files changed, 63 insertions(+), 8 deletions(-) create mode 160000 librender_cdk/extern/dotenv-cpp create mode 100644 librender_cdk/src/environment_manager.cpp create mode 100644 librender_cdk/src/environment_manager.h diff --git a/.gitmodules b/.gitmodules index 5323526..d28d526 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "librender_cdk/extern/cpp-httplib"] path = librender_cdk/extern/cpp-httplib url = https://github.com/lexara-prime-ai/cpp-httplib +[submodule "librender_cdk/extern/dotenv-cpp"] + path = librender_cdk/extern/dotenv-cpp + url = https://github.com/lexara-prime-ai/dotenv-cpp diff --git a/Makefile b/Makefile index d475df9..ebb36fc 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ test: CPP_SRC_DIR = ./librender_cdk/src CPP_BUILD_DIR = build CPP_LIBRARY_DIR = librender_cdk -CPP_INCLUDE_DIRS = -I./librender_cdk/extern/cpp-httplib -I./librender_cdk/include +CPP_INCLUDE_DIRS = -I./librender_cdk/extern/dotenv-cpp/include -I./librender_cdk/extern/cpp-httplib -I./librender_cdk/include CPP_FLAGS = -std=c++17 -Wall CPP_LIBS = -lssl -lcrypto # OpenSSL for HTTPS diff --git a/librender_cdk/extern/dotenv-cpp b/librender_cdk/extern/dotenv-cpp new file mode 160000 index 0000000..432def2 --- /dev/null +++ b/librender_cdk/extern/dotenv-cpp @@ -0,0 +1 @@ +Subproject commit 432def2fb9c2a5e51e6d491f35f2e8f35fa900b0 diff --git a/librender_cdk/src/environment_manager.cpp b/librender_cdk/src/environment_manager.cpp new file mode 100644 index 0000000..3a79c88 --- /dev/null +++ b/librender_cdk/src/environment_manager.cpp @@ -0,0 +1,24 @@ +#include "../../librender_cdk/extern/dotenv-cpp/include/laserpants/dotenv/dotenv.h" +#include +#include +#include + +struct Config { + std::string api_key; + std::string owner_credentials; +}; + +Config load_config() { + dotenv::init(".env"); + + const char *api_key = std::getenv("API_KEY"); + const char *owner_credentials = std::getenv("OWNER_CREDENTIALS"); + + Config config; + if (api_key) + config.api_key = api_key; + if (owner_credentials) + config.owner_credentials = owner_credentials; + + return config; +} \ No newline at end of file diff --git a/librender_cdk/src/environment_manager.h b/librender_cdk/src/environment_manager.h new file mode 100644 index 0000000..0f402f0 --- /dev/null +++ b/librender_cdk/src/environment_manager.h @@ -0,0 +1,13 @@ +#ifndef ENVIRONMENT_MANAGER_H +#define ENVIRONMENT_MANAGER_H + +#include + +struct Config { + std::string api_key; + std::string owner_credentials; +}; + +Config load_config(); + +#endif // ENVIRONMENT_MANAGER_H diff --git a/librender_cdk/src/main.cpp b/librender_cdk/src/main.cpp index 47017d0..f8b96fa 100644 --- a/librender_cdk/src/main.cpp +++ b/librender_cdk/src/main.cpp @@ -1,12 +1,26 @@ -#include "../cpp-httplib/httplib.h" +#include "environment_manager.h" #include int main() { - httplib::Client cli("http://example.com"); - auto res = cli.Get("/api/v1/resource"); + // Call the load_config function to load environment variables + Config config = load_config(); - if (res) { - std::cout << "Status: " << res->status << std::endl; - std::cout << "Response Body: " << res->body << std::endl; - } + // Print the loaded configuration values + std::cout << "API_KEY: " << config.api_key << std::endl; + std::cout << "OWNER_CREDENTIALS: " << config.owner_credentials << std::endl; + + return 0; } + +// #include "../cpp-httplib/httplib.h" +// #include + +// int main() { +// httplib::Client cli("http://example.com"); +// auto res = cli.Get("/api/v1/resource"); + +// if (res) { +// std::cout << "Status: " << res->status << std::endl; +// std::cout << "Response Body: " << res->body << std::endl; +// } +// }