Commit 4dd0e4db authored by Pelayo Torres's avatar Pelayo Torres
Browse files

First commit OpenCAPIF Provider GW

parent 1a9bbf30
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+8 −0
Original line number Diff line number Diff line
provider_gw_sample/provider_gw/*
provider_gw_sample/logs
provider_gw/__pycache__
.flake8
dist
build
provider_gw.egg-info
pyproject.toml
 No newline at end of file
+194 −58
Original line number Diff line number Diff line
# provider-gateway
# PROVIDER_GW
[![PyPI version](https://img.shields.io/pypi/v/provider-gw.svg)](https://pypi.org/project/provider-gw/) ![Python](https://img.shields.io/badge/python-v3.12+-blue.svg) 


PROVIDER_GW is a gateway component designed to bridge legacy systems with the **Common API Framework (CAPIF)**. It simplifies the integration process, enabling legacy systems to interact seamlessly with CAPIF and adopt modern APIs without extensive modifications.

## Getting started
The component leverages the [Opencapif_sdk](https://labs.etsi.org/rep/ocf/sdk) to manage the interactions between systems and CAPIF effectively.

To make it easy for you to get started with GitLab, here's a list of recommended next steps.
---

Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Overview of PROVIDER_GW

## Add your files
PROVIDER_GW acts as an intermediary, translating and exposing APIs from legacy systems in a format compatible with CAPIF. It manages communication between the **Southbound interface** (legacy systems) and the **Northbound interface** (CAPIF), ensuring secure, reliable, and flexible API interaction.

- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
![PROVIDER_GW Schema](./docs/provider_gw_schema.png)

```
cd existing_repo
git remote add origin https://labs.etsi.org/rep/ocf/provider-gateway.git
git branch -M main
git push -uf origin main
```
---

## Integrate with your tools
## Getting Started

- [ ] [Set up project integrations](https://labs.etsi.org/rep/ocf/provider-gateway/-/settings/integrations)
### Prerequisites

## Collaborate with your team
To use PROVIDER_GW, you need:
1. A registered user account in the CAPIF instance.
   - Contact your CAPIF administrator to obtain the necessary credentials (CAPIF username and password).
2. The following software dependencies:
   - Python 3.12+
   - `pipenv` or `virtualenv` for managing Python environments.

- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
### Installation Steps

## Test and Deploy
1. **Set up a virtual environment:**
   ```bash
   python -m venv venv
   source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
   ```

Use the built-in continuous integration in GitLab.
2. **Install PROVIDER_GW:**
   ```bash
   pip install provider_gw
   ```

- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
---

## Configuration

PROVIDER_GW requires two YAML configuration files:
1. **Northbound (`northbound.yaml`)**: Defines interaction with CAPIF. [**EXAMPLE**](./example_files/northbound.yaml)
2. **Southbound (`southbound.yaml`)**: Specifies communication with legacy systems. [**EXAMPLE**](./example_files/southbound.yaml)

### 1. Northbound Configuration

The `northbound.yaml` file defines the integration with CAPIF, including API specifications and OpenCapif SDK settings.

#### Key Fields

- **`ip`**: The IP address to expose.
- **`port`**: The port to expose.
- **`opencapif_sdk_configuration`**: Configures the OpenCapif SDK.
- **`openapi`**: Specifies the API exposed to CAPIF.

#### OpenCapif SDK Configuration

Here are the required fields for the `opencapif_sdk_configuration`:

- `capif_host`: CAPIF server domain.
- `register_host`: Registration server domain.
- `capif_https_port`: CAPIF server HTTPS port.
- `capif_register_port`: Registration server port.
- `capif_username`: CAPIF username.
- `capif_password`: CAPIF password.
- `debug_mode`: Enables detailed logs (`True` or `False`).
- `provider`: Specific fields of the provider(`cert_generation`,`supported_features`,`apiSuppFeats`)

**Example of a opencapif_sdk_configuration settings:**

```yaml
opencapif_sdk_configuration:
  capif_host: "capifcore"
  register_host: "register.capif"
  capif_https_port: "443"
  capif_register_port: "8004"
  capif_username: "echeva_0"
  capif_password: "excalibur"
  debug_mode: "True"
  provider:
    cert_generation:
      csr_common_name: "provider"
      csr_organizational_unit: "discovery"
      csr_organization: "telefonica"
      csr_locality: "madrid"
      csr_state_or_province_name: "madrid"
      csr_country_name: "ES"
      csr_email_address: "hola@gmail.com"
    supported_features: "0"
    apiSuppFeats: "0"
```

***
#### OpenAPI Configuration

The `openapi` field must adhere to the [OpenAPI Specification](https://spec.openapis.org/oas/v3.0.3). Use tools like [Swagger Editor](https://editor.swagger.io/) to validate the configuration.

**Example Configuration:**

```yaml
openapi:
  openapi: 3.0.0
  info:
    title: My API
    description: Example API for demonstration
    version: 1.0.0
  paths:
    /greet:
      get:
        summary: Say hello
        description: Returns a greeting message.
        responses:
          '200':
            description: Success
            content:
              application/json:
                schema:
                  type: object
                  properties:
                    message:
                      type: string
                      example: "Hello!"
```

---

# Editing this README
### 2. Southbound Configuration

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
The `southbound.yaml` file defines how PROVIDER_GW interacts with legacy systems.

## Suggestions for a good README
#### Key Fields

- **`ip`**: The IP address to expose.
- **`port`**: The port to expose.
- **`type`**: The type of endpoint (`REST` is currently supported).
- **`authentication_method`**: Authentication options:
  - `HTTP Basic Authentication`
  - `JWT Bearer Token`
- **`credentials`**:
  - For HTTP Basic Authentication:
    ```yaml
    username: "admin"
    password: "password123"
    ```
  - For JWT Bearer Token:
    ```yaml
    jwt: "your-token"
    ```
- **`paths`**: Maps Northbound API paths to Southbound API paths, including HTTP methods and parameter mappings.

**Example Configuration:**

```yaml
southbound:
  ip: 0.0.0.0
  port: 8000
  type: REST
  authentication_method: "JWT Bearer Token"
  credentials:
    jwt: "example-token"
  paths:
    - northbound_path: "/greet"
      southbound_path: "/hello"
      method: GET
    - northbound_path: "/greet/{name}"
      southbound_path: "/hello/{person}"
      method: GET
      parameters:
        - name: person
```

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
---

## Name
Choose a self-explaining name for your project.
## Usage

## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
1. Place the `northbound.yaml` and `southbound.yaml` configuration files in a working directory.
2. Use the following commands to interact with PROVIDER_GW:

## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
- **Start the gateway (first-time setup):**
  ```bash
  cd ./directory/with/configuration/files
  provider_gw start
  ```

## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
- **Run the gateway (after initial setup):**
  ```bash
  cd ./directory/with/configuration/files
  provider_gw run
  ```

## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
- **Remove the gateway interface:**
  ```bash
  cd ./directory/with/configuration/files
  provider_gw remove
  ```

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
---

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
### Adding a New Endpoint

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
To add a new API endpoint:

## Contributing
State if you are open to contributions and what your requirements are for accepting them.
1. Update `northbound.yaml` to define the endpoint.
2. Map the corresponding route in `southbound.yaml`.
3. Start the gateway with:
   ```bash
   cd ./directory/with/configuration/files
   provider_gw start
   ```

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
---

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
### Refreshing the Southbound JWT Token

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
To refresh the Southbound JWT token:

## License
For open source projects, say how it is licensed.
1. Update the `jwt` field in the `southbound.yaml` file.
2. Apply the changes with:
   ```bash
   cd ./directory/with/configuration/files
   provider_gw refresh
   ```

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
This ensures the new token is applied seamlessly.
+0 −0

Empty file added.

+0 −0

Empty file added.

+155 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading