Skip to content

Commit

Permalink
Merge pull request #1 from coopsdev/FortiGate
Browse files Browse the repository at this point in the history
Begin adding basic firewall policy control
  • Loading branch information
cooperlarson authored Aug 31, 2024
2 parents e028f32 + 1b1d22e commit 93cc743
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 15 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,3 @@ jobs:
- name: Show ccache stats after build
run: ccache -s

- name: Run Tests
run: |
cd /home/gh-runner/actions-runner/_work/forti-api/forti-api
./build/meson/runTests
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Pkg(ConanFile):
name = "forti_api"
version = "0.1.6"
version = "0.1.7"
author = "Cooper Larson | [email protected]"
url = ""
description = "FortiGate API interface"
Expand Down
1 change: 1 addition & 0 deletions include/forti_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
#include "forti_api/threat_feed.hpp"
#include "forti_api/dns_filter.hpp"
#include "forti_api/system.hpp"
#include "forti_api/firewall.hpp"

#endif //FORTI_API_H
2 changes: 1 addition & 1 deletion include/forti_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef FORTI_API_API_HPP
#define FORTI_API_API_HPP

#include <cstring>
#include <string>
#include <nlohmann/json.hpp>
#include <iostream>
#include <format>
Expand Down
3 changes: 0 additions & 3 deletions include/forti_api/dns_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#ifndef FORTI_API_DNS_FILTER_HPP
#define FORTI_API_DNS_FILTER_HPP

#include <string>
#include <format>
#include <nlohmann/json.hpp>
#include <utility>
#include "api.hpp"

Expand Down
33 changes: 33 additions & 0 deletions include/forti_api/firewall.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Created by Cooper Larson on 8/31/24.
//

#ifndef FORTI_API_FIREWALL_HPP
#define FORTI_API_FIREWALL_HPP

#include "api.hpp"
#include "include/forti_api/types/policy.h"

namespace FortiGate {

class Policy {
inline static std::string endpoint = "/cmdb/firewall/policy";

public:
static std::vector<FirewallPolicy> get() { return FortiAPI::get<FirewallPoliciesResponse>(endpoint).results; }

static FirewallPolicy get(const std::string& name) {
auto policies = get();
for (const auto& policy : policies) if (policy.name == name) return policy;
throw std::runtime_error("Unable to locate firewall policy: " + name);
}

static void update(const FirewallPolicy& policy) {
FortiAPI::put(std::format("{}/{}", endpoint, policy.policyid), policy);
}
};

}


#endif //FORTI_API_FIREWALL_HPP
1 change: 0 additions & 1 deletion include/forti_api/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "api.hpp"
#include <string>
#include <nlohmann/json.hpp>


struct SystemResponse {
Expand Down
3 changes: 0 additions & 3 deletions include/forti_api/threat_feed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#define FORTI_API_THREAT_FEED_HPP

#include "dns_filter.hpp"
#include <cstring>
#include <format>
#include <nlohmann/json.hpp>
#include <utility>
#include <vector>
#include "api.hpp"
Expand Down
376 changes: 376 additions & 0 deletions include/forti_api/types/policy.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('forti_api', 'cpp',
version : '0.1.6',
version : '0.1.7',
default_options : ['warning_level=3', 'cpp_std=c++23'])

source_root = meson.source_root()
Expand Down

0 comments on commit 93cc743

Please sign in to comment.