Skip to content

Commit ed884cc

Browse files
Added APIFirewallTrafficShaperRead model to read all configured traffic shapers
1 parent afa09c4 commit ed884cc

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

pfSense-pkg-API/files/etc/inc/api/endpoints/APIFirewallTrafficShaper.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class APIFirewallTrafficShaper extends APIEndpoint {
2020
$this->url = "/api/v1/firewall/traffic_shaper";
2121
}
2222

23+
protected function get() {
24+
return (new APIFirewallTrafficShaperRead())->call();
25+
}
26+
2327
protected function post() {
2428
return (new APIFirewallTrafficShaperCreate())->call();
2529
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
// Copyright 2021 Jared Hendrickson
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once("api/framework/APIModel.inc");
17+
require_once("api/framework/APIResponse.inc");
18+
19+
20+
class APIFirewallTrafficShaperRead extends APIModel {
21+
# Create our method constructor
22+
public function __construct() {
23+
parent::__construct();
24+
$this->privileges = ["page-all", "page-firewall-trafficshaper"];
25+
}
26+
27+
public function action() {
28+
# Check that we have a configuration
29+
if (!empty($this->config["shaper"]["queue"])) {
30+
$shaper_array = $this->config["shaper"]["queue"];
31+
} else {
32+
$shaper_array = [];
33+
}
34+
return APIResponse\get(0, $shaper_array);
35+
}
36+
}

tests/test_api_v1_firewall_traffic_shaper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
class APIUnitTestFirewallRule(unit_test_framework.APIUnitTest):
1818
url = "/api/v1/firewall/traffic_shaper"
19+
get_tests = [{"name": "Read all traffic shapers"}]
1920
post_tests = [
2021
{
2122
"name": "Create a traffic shaper",

0 commit comments

Comments
 (0)