Skip to content

Commit

Permalink
Add env. manager
Browse files Browse the repository at this point in the history
  • Loading branch information
irfanghat committed Nov 13, 2024
1 parent 2b9de27 commit 351deb2
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions librender_cdk/extern/dotenv-cpp
Submodule dotenv-cpp added at 432def
24 changes: 24 additions & 0 deletions librender_cdk/src/environment_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "../../librender_cdk/extern/dotenv-cpp/include/laserpants/dotenv/dotenv.h"
#include <cstdlib>
#include <iostream>
#include <string>

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;
}
13 changes: 13 additions & 0 deletions librender_cdk/src/environment_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef ENVIRONMENT_MANAGER_H
#define ENVIRONMENT_MANAGER_H

#include <string>

struct Config {
std::string api_key;
std::string owner_credentials;
};

Config load_config();

#endif // ENVIRONMENT_MANAGER_H
28 changes: 21 additions & 7 deletions librender_cdk/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
#include "../cpp-httplib/httplib.h"
#include "environment_manager.h"
#include <iostream>

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 <iostream>

// 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;
// }
// }

0 comments on commit 351deb2

Please sign in to comment.