Skip to content

Commit

Permalink
Add cli generator
Browse files Browse the repository at this point in the history
  • Loading branch information
soroshsabz authored Oct 21, 2023
1 parent 8b0d07d commit 5c6b503
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 303 deletions.
8 changes: 8 additions & 0 deletions Document/how-to-generate-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# How-To

This document describes how to develop for `BSN.IpTables.Cli`

## Some considration

* warning | PreCheck/AllOfWhenYouMeantRef _is using an 'allOf' instead of a $ref. This creates a wasteful anonymous type when generating code._
* Resolve warning: as you can see in <https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1488> and <https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/issues/13> we must to do not use `options.UseAllOfToExtendReferenceSchemas();` in my code.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# IpTables.Api

API for local iptables management

IpTables.Api is the RESTful server which applies iptables rules to block or allow IP addresses on request from a remote client.
Expand All @@ -9,10 +10,10 @@ This project is powered on [IPTables.Net](https://github.com/splitice/IPTables.N

## How iptables Work

**Note: This below article is just copy from https://phoenixnap.com/kb/iptables-tutorial-linux-firewall**
**Note: This below article is just copy from <https://phoenixnap.com/kb/iptables-tutorial-linux-firewall>**

![IpTablesFlow](Document/IpTablesWorkFlow.webp "IpTables Work Flow")
*Source: https://www.booleanworld.com/depth-guide-iptables-linux-firewall/*
*Source: <https://www.booleanworld.com/depth-guide-iptables-linux-firewall/>*

Network traffic is made up of packets. Data is broken up into smaller pieces (called packets), sent over a network, then put back together. Iptables identifies the packets received and then uses a set of rules to decide what to do with them.

Expand All @@ -36,7 +37,7 @@ The Filter table is the most frequently used one. It acts as a bouncer, deciding
* Input: the rules in this chain control the packets received by the server.
* Output: this chain controls the packets for outbound traffic.
* Forward: this set of rules controls the packets that are routed through the server.

#### 2. Network Address Translation (NAT)

This table contains NAT (Network Address Translation) rules for routing packets to networks that cannot be accessed directly. When the destination or source of the packet has to be altered, the NAT table is used. It includes the following chains:
Expand Down Expand Up @@ -78,6 +79,7 @@ To run, follow below steps
1. simply run web service with `Source/BSN.IpTables.Api/bin/Release/net6.0/BSN.IpTables.Api --urls=http://localhost:8002`

### Kamailio Example

```kamailio
loadmodule "http_client.so"
loadmodule "htable.so"
Expand Down
17 changes: 16 additions & 1 deletion Source/BSN.IpTables.Api/ConfigureSwaggerOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
Expand Down Expand Up @@ -40,7 +41,21 @@ public void Configure(SwaggerGenOptions options)
Type = "string",
Example = new OpenApiString("00:00:00")
});
options.UseAllOfToExtendReferenceSchemas();

// Because capable to use autorest we must to diable AllOf
// for more information please see https://stackoverflow.com/q/59788412/1539100
// and https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/issues/13
// options.UseAllOfToExtendReferenceSchemas();

// operationId is an optional unique string used to identify an operation.
// If provided, these IDs must be unique among all operations described in your API.
//
// However, AutoRest seems to use that to identify each method.
// I found a Github question / issue: <see href:https://github.com/Azure/autorest/issues/2647/>
// where people addressed this by configuring AutoRest to use tags instead of operation ID to identify method.
//
// <see href:https://stackoverflow.com/a/60875558/1539100/>
options.CustomOperationIds(description => (description.ActionDescriptor as ControllerActionDescriptor)?.ActionName);
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion Source/BSN.IpTables.Api/Controllers/V1/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public async Task<ActionResult<Response>> Append([FromQuery] RulesCommandService

[HttpDelete]
[Route("Delete")]
[Route("")]
[ProducesResponseType(typeof(Response), (int)HttpStatusCode.OK)]
public async Task<ActionResult<Response>> Delete([FromQuery] RulesCommandServiceDeleteRequest request)
{
Expand Down
Loading

0 comments on commit 5c6b503

Please sign in to comment.