Skip to content

Commit

Permalink
add init by variable for non-sensitive fortigate config
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperlarson committed Sep 3, 2024
1 parent 9d5f4c6 commit 421412d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions include/forti_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,35 @@ inline static nlohmann::json convert_keys_to_underscores(const nlohmann::json& j


class FortiAuth {
std::string ca_cert_path, ssl_cert_path, cert_password, api_key, auth_header;
unsigned int admin_ssh_port;
std::string gateway_ip, ca_cert_path, ssl_cert_path, cert_password, api_key, auth_header;

friend class FortiAPI;

FortiAuth() : ca_cert_path(std::getenv("PATH_TO_FORTIGATE_CA_CERT")),
FortiAuth() : admin_ssh_port(std::stoi(std::getenv("FORTIGATE_ADMIN_SSH_PORT"))),
gateway_ip(std::getenv("FORTIGATE_GATEWAY_IP")),
ca_cert_path(std::getenv("PATH_TO_FORTIGATE_CA_CERT")),
ssl_cert_path(std::getenv("PATH_TO_FORTIGATE_SSL_CERT")),
cert_password(std::getenv("FORTIGATE_SSL_CERT_PASS")),
api_key(std::getenv("FORTIGATE_API_KEY")) {
auth_header = std::format("Authorization: Bearer {}", api_key);
assert_necessary_fields_exist();
}

FortiAuth(unsigned int admin_ssh_port,
const std::string& gateway_ip,
const std::string& ca_cert_path,
const std::string& ssl_cert_path) :
admin_ssh_port(admin_ssh_port),
gateway_ip(gateway_ip),
ca_cert_path(ca_cert_path),
ssl_cert_path(ssl_cert_path),
cert_password(std::getenv("FORTIGATE_SSL_CERT_PASS")),
api_key(std::getenv("FORTIGATE_API_KEY")) {
auth_header = std::format("Authorization: Bearer {}", api_key);
assert_necessary_fields_exist();
}

void assert_necessary_fields_exist() {
bool all_fields_present = true;

Expand Down

0 comments on commit 421412d

Please sign in to comment.