# 2. Run

## Classes

| Framework              | `rasp_class` | Note                                                                                                        |
| ---------------------- | ------------ | ----------------------------------------------------------------------------------------------------------- |
| Flask                  | FaskRASP     |                                                                                                             |
| FastAPI                | FastApiRASP  | **IMPORTANT** Requires starlette >= 0.28.0                                                                  |
| Django                 | DjangoRASP   |                                                                                                             |
| AWS Lambda             | LambdaRASP   | See [Addendum](https://paracyberbellum.gitbook.io/pyrasp/a1.-addendum-aws-lambda-specificities)             |
| Google Cloud Functions | GcpRASP      | See [Addendum](https://paracyberbellum.gitbook.io/pyrasp/a2.-addendum-google-cloud-functions-specificities) |
| Azure Functions        | AzureRASP    | See [Addendum](https://paracyberbellum.gitbook.io/pyrasp/a3.-addendum-azure-function-specificities)         |
| MCP Tools              | McpToolRASP  | See [Addendum](https://paracyberbellum.gitbook.io/pyrasp/a4.-addendum-mcp-security)                         |

## Flask & FastAPI

### Guidelines

`pyrasp` requires 2 lines of code to run.

`from pyrasp.pyrasp import <rasp_class>`

*Local Agent*

`<rasp_class>(<framework_instance>, conf = <configuration_file>)`

*Cloud Agent*

> See [Cloud Operations](https://paracyberbellum.gitbook.io/pyrasp/5.-cloud-operations) section for details

`<rasp_class>(<framework_instance>, cloud_url = <configuration_url>, key = <agent_key>)`

### Examples

```python
from pyrasp.pyrasp import FlaskRASP

app = Flask(__name__)
FlaskRASP(app, conf = 'rasp.json')
```

```python
from pyrasp.pyrasp import FastApiRASP
app = FastAPI()
rasp = FastApiRASP(app, cloud_url = 'https://pyrasp.my.org/config', key = '000000-1111-2222-3333-44444444')
```

## Django

### Guidelines

The `pyrasp` class must be added to the `MIDDLEWARE` variable in the `settings.py` file of the Django application. A `PYRASP_CONF` variable must be added to the same file. It contains the path of the configuration file.

For cloud deployment `PYRASP_CLOUD_URL` and `PYRASP_KEY` variables must be set. (See [Cloud Operations](https://paracyberbellum.gitbook.io/pyrasp/5.-cloud-operations) section for details)

### Examples

```python
PYRASP_CONF = 'rasp.json'

MIDDLEWARE = [
    'pyrasp.pyrasp.DjangoRASP',
    ...
]
```

```python
PYRASP_CLOUD_URL = 'https://pyrasp.my.org/config'
PYRASP_KEY = '000000-1111-2222-3333-44444444'

MIDDLEWARE = [
    'pyrasp.pyrasp.DjangoRASP',
    ...
]
```

## Google Cloud Functions

### Guidelines

The `pyrasp` module must be imported `from pyrasp.pyrasp import GcpRASP`.

A decorator must be added on top of the Google function handler.

*Local Agent*

`@GcpRASP(conf = <configuration_file>).register`

A configuration file must be added to the function files.

*Cloud Agent*

> See [Cloud Operations](https://paracyberbellum.gitbook.io/pyrasp/5.-cloud-operations) section for details

`@GcpRASP(cloud_url = <configuration_url>, key = <agent_key>).register`

### Examples

```python
@GcpRASP(conf = 'rasp.json').register
def hello_http(event, context):
...
```

```python
@GcpRASP(cloud_url = 'https://pyrasp.my.org/config', key = '000000-1111-2222-3333-44444444').register
def hello_http(event, context):
...
```

## Azure Functions

### Guidelines

The `pyrasp` module must be imported `from pyrasp.pyrasp import AzureRASP`.

A decorator must be added after the `@app.route()` decorator.

*Local Agent*

`@AzureRASP(conf = <configuration_file>).register`

A configuration file must be added to the function files.

*Cloud Agent*

> See [Cloud Operations](https://paracyberbellum.gitbook.io/pyrasp/5.-cloud-operations) section for details

`@AzureRASP(cloud_url = <configuration_url>, key = <agent_key>).register`

### Examples

```python
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.route(route="helloworld")
@AzureRASP(conf = 'rasp.json').register
def helloworld(req):
...
```

```python
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.route(route="helloworld")
@AzureRASP(cloud_url = 'https://pyrasp.my.org/config', key = '000000-1111-2222-3333-44444444').register
def helloworld(req):
...
```

## AWS Lambda (Discontinued)

### Guidelines

The `pyrasp` module must be imported `from pyrasp.pyrasp import LambdaRASP`.

A decorator must be added on top of the lambda function handler.

*Local Agent*

`@LambdaRASP(conf = <configuration_file>)`

A configuration file must be added to the function files.

*Cloud Agent*

> See [Cloud Operations](https://paracyberbellum.gitbook.io/pyrasp/5.-cloud-operations) section for details

`@LambdaRASP(cloud_url = <configuration_url>, key = <agent_key>)`

### Examples

```python
@LambdaRASP(conf = 'rasp.json').register
def lambda_handler(event, context):
...
```

```python
@LambdaRASP(cloud_url = 'https://pyrasp.my.org/config', key = '000000-1111-2222-3333-44444444').register
def lambda_handler(event, context):
...
```

## MCP Tools

### Guidelines

The `pyrasp` module must be imported `from pyrasp.pyrasp import McpToolRASP`.

An instance of McpToolRASP must be created first.

*Local Agent*

`mcp_rasp = McpToolRASP(conf = <configuration_file>)`

A configuration file must be added to the function files.

*Cloud Agent*

> See [Cloud Operations](https://paracyberbellum.gitbook.io/pyrasp/5.-cloud-operations) section for details

`mcp_rasp = McpToolRASP(cloud_url = <configuration_url>, key = <agent_key>)`

A decorator must be added after the `@mcp.tool()` decorator of the tool function.

### Examples

```python
mcp = FastMCP(name="mcp-server",)
mcp_rasp = McpToolRASP(mcp, conf = 'rasp.json')

@mcp.tool()
@mcp_rasp.register
def ipinfo(ip_address: str) -> dict:
...
```

```python
mcp = FastMCP(name="mcp-server",)
mcp_rasp = McpToolRASP(mcp, cloud_url = 'https://pyrasp.my.org/config', key = '000000-1111-2222-3333-44444444').register

@mcp.tool()
@mcp_rasp.register
def ipinfo(ip_address: str) -> dict:
...
```

## Environment Variables

`cloud_url`, `key` and `conf` values can be set as environment variables:

* `PYRASP_CLOUD_URL`: URL to retrieve agent configuration from
* `PYRASP_KEY`: unique key to identify the agent
* `PYRASP_CONF`: configuration file path

## Startup

At startup of the application `pyrasp` loading information is displayed.

```
### PyRASP v0.9.2 ##########
[+] Starting PyRASP
[+] Loading template configuration: default
[+] Loading configuration from rasp.json
[+] XSS model loaded
[+] SQLI model loaded
[+] Prompt Injection model loaded
[+] Starting logging process
[+] PyRASP succesfully started
############################
```
