Skip to content

Commit

Permalink
Merge pull request #23 from martin-olivier/version/3.0.0
Browse files Browse the repository at this point in the history
Version/3.0.0
  • Loading branch information
dhbrojas authored Feb 8, 2022
2 parents c62740e + 5c15839 commit c8bd09c
Show file tree
Hide file tree
Showing 26 changed files with 327 additions and 231 deletions.
9 changes: 3 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
title: 'My Bug Report'
labels: 'bug'

---

## [BUG] [Subject of the issue]

### Description

Describe your issue in as much detail as possible here.
Expand Down Expand Up @@ -38,4 +35,4 @@ Please paste any logs here that demonstrate the issue, if they exist

### Proposed solution

If you have an idea of how to fix this issue, please write it down here, so we can begin discussing it
If you have an idea of how to fix this issue, please write it down here, so we can begin discussing it
28 changes: 4 additions & 24 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
---
name: Feature report
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
title: 'My Feature'
labels: 'enhancement'

---

## [FEATURES] [Subject of the issue]

### Description

Describe your issue in as much detail as possible here.

### Your environment

* OS and version
* branch that causes this issue

### Is your feature request related to a problem? Please describe.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Expand All @@ -26,18 +18,6 @@ A clear and concise description of what the problem is. Ex. I'm always frustrate

A clear and concise description of what you want to happen.

### Expected behaviour

Tell us what should happen

### Actual behaviour

Tell us what happens instead

### Logs

Please paste any logs here that demonstrate the issue, if they exist

### Additional context

Add any other context or screenshots about the feature request here.
Add any other context or screenshots about the feature request here.
12 changes: 4 additions & 8 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@

Please provide a detailed description of what was done in this PR.

# Changes include

- [ ] Bugfix (non-breaking change that solves an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (change that is not backwards-compatible and/or changes current functionality)

# Breaking changes

Please complete this section if any breaking changes have been made, otherwise delete it.

# Additional Changes

# Checklist

- [ ] I have assigned this PR to myself
- [ ] I have added at least 1 reviewer
- [ ] I have tested this code
- [ ] I have added sufficient documentation in the code
- [ ] I have added sufficient documentation and/or updated documentation to reflect my changes

# Additional comments

Please post additional comments in this section if you have them, otherwise delete it.
Please post additional comments in this section if you have them, otherwise delete it.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "include/dylib"]
path = include/dylib
url = https://github.com/martin-olivier/dylib
branch = v1.7.1
branch = v1.8.1
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Banner](docs/assets/project_banner.png)

[![ZiAPI](https://img.shields.io/badge/ZiAPI-v2.2.0-blue.svg)](https://github.com/martin-olivier/ZiAPI/releases/tag/v2.2.0)
[![ZiAPI](https://img.shields.io/badge/ZiAPI-v3.0.0-blue.svg)](https://github.com/martin-olivier/ZiAPI/releases/tag/v3.0.0)
[![CPP Version](https://img.shields.io/badge/C++-17_and_above-darkgreen.svg)](https://isocpp.org/)
[![Discord](https://img.shields.io/discord/934852777136513075)](https://discord.gg/CzKv6dGXmf)
[![workflow](https://github.com/martin-olivier/ZiAPI/actions/workflows/CI.yml/badge.svg)](https://github.com/martin-olivier/ZiAPI/actions/workflows/CI.yml)
Expand Down Expand Up @@ -38,7 +38,7 @@ include(ExternalProject)
ExternalProject_Add(
ziapi
GIT_REPOSITORY https://github.com/martin-olivier/ZiAPI.git
GIT_TAG v2.2.0
GIT_TAG v3.0.0
INSTALL_COMMAND ""
TEST_COMMAND ""
)
Expand Down
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ General documentation pages will help you understand the general concepts of the
- [Getting started](general/GETTING_STARTED.md)
- [Why choose ZIAPI](general/WHY_US.md)
- [Modules](general/MODULES.md)
- [ZIAPI Standards](general/STANDARDS.md)
- [Contributing](general/CONTRIBUTING.md)

## Guides
Expand All @@ -19,6 +20,7 @@ Guides are step by step instructions on how to do pretty much anything with the

- [Install and build](guides/INSTALL_AND_BUILD.md)
- [Module 101](guides/MODULES_101.md)
- [The config object](guides/CONFIG.md)
- [Implementing a handler module](guides/IMPLEMENT_HANDLER.md)
- [Implementing a pre-processor module](guides/IMPLEMENT_PREPROCESSOR.md)
- [Implementing a post-processor module](guides/IMPLEMENT_POSTPROCESSOR.md)
Expand All @@ -30,3 +32,4 @@ Module examples are code tutorials on how to build a variety of modules.

- [Logger Module Tutorial](examples/LOGGER.md)
- [Directory Listing Module Tutorial](examples/DIRECTORY_LISTING.md)
- [Redirection Module Tutorial](examples/REDIRECTION.md)
6 changes: 3 additions & 3 deletions docs/examples/DIRECTORY_LISTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class DirectoryListingModule : public ziapi::IHandlerModule {
public:
void Init(const ziapi::config::Node &cfg) override {}

[[nodiscard]] ziapi::Version GetVersion() const noexcept override { return {1, 0}; }
[[nodiscard]] ziapi::Version GetVersion() const noexcept override { return {3, 0, 0}; }

[[nodiscard]] ziapi::Version GetCompatibleApiVersion() const noexcept override { return {1, 0}; }
[[nodiscard]] ziapi::Version GetCompatibleApiVersion() const noexcept override { return {3, 0, 0}; }

[[nodiscard]] const char *GetName() const noexcept override { return "DirectoryListing"; }

Expand Down Expand Up @@ -60,7 +60,7 @@ Well, we can add the path to this directory as a variable of our config file and
void Init(const ziapi::config::Node &cfg) override
{
/// In our config, we can specify which folder our module serves.
root_ = cfg.AsDict()["modules"]->AsDict()["directoryListing"]->AsDict()["root"]->AsString();
root_ = cfg["modules"]["directoryListing"]["root"].AsString();
}

...
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/REDIRECTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class PhpCgiModule : public ziapi::IHandlerModule {
public:
void Init(const ziapi::config::Node &cfg) override {}

[[nodiscard]] Version GetVersion() const noexcept { return {0, 1}; }
[[nodiscard]] Version GetVersion() const noexcept { return {3, 0, 0}; }

[[nodiscard]] Version GetCompatibleApiVersion() const noexcept { return {0, 1}; }
[[nodiscard]] Version GetCompatibleApiVersion() const noexcept { return {3, 0, 0}; }

[[nodiscard]] const char *GetName() const noexcept { return "Redirection Module"; }

Expand All @@ -55,7 +55,7 @@ Let's load from the config the route to which we will redirect requests. We'll s
void Init(const Config &cfg)
{
/// We'll load from the configuration where to redirect to!
redirection_route_ = cfg.AsDict()["modules"]->AsDict()["redirection"]->AsDict()["route"]->AsString();
redirection_route_ = cfg["modules"]["redirection"]["route"];
}

...
Expand Down
94 changes: 94 additions & 0 deletions docs/general/STANDARDS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# ZIAPI Standards

A set of rules that define a standard implementation of a ZIAPI module to make it easier to share modules between groups.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC 2119](https://datatracker.ietf.org/doc/html/rfc2119).

## `Z0` - Module Documentation

Each module **MUST** be shipped with a `README.md` providing basic documentation for the module.

## `Z1` - Module Configuration Documentation

ZIAPI doesn't impose a norm for configuration files. However modules **MUST** be shipped with sufficient documentation regarding the configuration fields they expect.

#### Example

If the module `tls` depends on the following configuration:

```c++
void Init(const ziapi::config::Node &cfg) override {
auto enable_tls = cfg["modules"]["tls"]["enableTls"].AsBool();
auto certificate_path = cfg["modules"]["tls"]["certficiatePath"].AsString();
}
```
Then the `tls` module's documentation should explicitly state that the module expects:
- `modules.tls.enableTls` to be defined as a boolean
- `modules.tls.certificatePath` to be defined as a string
## `Z2` - Configuration File Layout
To limit friction when sharing modules, all groups **MAY** implement the following configuration file layout where:
- The top level node is a `ziapi::config::Dict`
- It contains a `modules` key which is a `ziapi::config::Dict` too.
- Each module which requires a configuration fetches its configuration information from `modules.<module_name>*`
#### Example
To illustrate this, let's look at a YAML configuration file example.
Let's say we have two modules respectively named `tls` and `directoryListing`. By applying rule Z2 we get the following configuration.
```yaml
modules:
tls:
foo: bar
directoryListing:
foo: bar
```

Therefore it is **NOT RECOMMENDED** to depend on configuration fields outside of the `modules.<module_name>` scope like so:

```c++
void MyModule::Init(const ziapi::config::Node &cfg) override {
/// Not C2 compliant, the module depends on a node outside of "modules.<module_name>".
auto enable_tls = cfg["enableTls"].AsBool();
auto certificate_path = cfg["certficiatePath"].AsString();
}
```
## `Z3` - Request/Response Context Documentation
ZIAPI doesn't impose a norm for the request/response context. However, modules **MUST** be shipped with sufficient documentation regarding the context fields they write to and read from.
Modules **SHOULD** try to populate the context with primitive types only or basic `std` types (Like `std::string`).
#### Example
If the `MyPreProcessor` module depends on the following context:
```c++
void MyPreProcessor::PreProcess(http::Context &ctx, http::Request &req)
{
auto client_address = std::any_cast<std::string>(ctx["client.socket.address"]);
ctx["php_cgi.user.is_authenticated"] = (client_address == "127.0.0.1");
}
```

Then the `MyPreProcessor` module's documentation must explicitly state that it expects:
- `ctx["client.socket.address"]` to be defined as a `std::string`

The documentation must also state that the module plans to:
- Write a boolean value inside `ctx["user.is_authenticated"]`

## `Z4` - Standard Request/Response Context Fields

Each request/response is associated with a `ziapi::http::Context` to allow modules to communicate data.

The following fields are standard fields and **SHOULD** be populated according to the following specification.

| Key | Type | Description |
|-------------------------|-----------------|----------------------------------------------------------------------------|
| `client.socket.address` | `std::string` | The IP address of the client. May only be mutated by `INetworkModule`s |
| `client.socket.port` | `std::uint16_t` | The port of the client's socket. May only be mutated by `INetworkModule`s |
Loading

0 comments on commit c8bd09c

Please sign in to comment.