Skip to content

Commit

Permalink
deploy python package
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay288 committed Oct 25, 2022
1 parent 0683f92 commit c8d9bf8
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 157 deletions.
8 changes: 8 additions & 0 deletions ingestors/python/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
env:
virtualenv env

build:
rm -rf dist && python -m build

release:
twine upload dist/*
63 changes: 63 additions & 0 deletions ingestors/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<p align="center">
<img alt="logo" src="https://storage.googleapis.com/metlo-security-public-images/metlo_logo_horiz%404x.png" height="80">
<h1 align="center">Metlo API Security</h1>
<p align="center">Secure Your API.</p>
</p>

## Installation

Currently Metlo's Python Agent supports 2 servers:

- Django
- Flask

It can be installed from `pypi` by running :

```shell
pip install metlo
```

## Configuration

### Django

Once installed, Metlo's middleware can be added by modifying middlewares list (in the projects `settings.py`) like so:

```python
MIDDLEWARE = [
...,
"metlo.django.MetloDjango",
]
```

and configuring a `METLO_CONFIG` attribute in the projects `settings.py` like this :

```python
METLO_CONFIG = {
"API_KEY": "<YOUR_METLO_API_KEY>",
"METLO_HOST": "<YOUR_METLO_COLLECTOR_URL>"
}
```

`METLO_CONFIG` can take an optional key-value pair representing the max number of workers for communicating with METLO.

### Flask

Once installed, METLO middleware can be added simply like :

```python
from flask import Flask

...
from metlo.flask import MetloFlask

app = Flask(__name__)
MetloFlask(app, "<YOUR_METLO_COLLECTOR_URL>", "<YOUR_METLO_API_KEY>")
```

The Flask Middleware takes the flask app, METLO collector url, and the METLO API Key as parameters. As an optional
parameter, a named value can be passed for max number of workers for communicating with METLO.

```python
MetloFlask(app, "<YOUR_METLO_COLLECTOR_URL>", "<YOUR_METLO_API_KEY>", workers="<WORKER-COUNT>")
```
88 changes: 88 additions & 0 deletions ingestors/python/metlo.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Metadata-Version: 2.1
Name: metlo
Version: 0.0.14
Summary: The Python Agent for Metlo
Home-page: https://www.metlo.com
License: MIT
Project-URL: Documentation, https://docs.metlo.com/docs/python
Project-URL: Source Code, https://github.com/metlo-labs/metlo/
Project-URL: Issue Tracker, https://github.com/metlo-labs/metlo/issues/
Project-URL: Twitter, https://mobile.twitter.com/metlohq
Project-URL: Chat, https://discord.gg/gasqPDKEAC
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3.4
Description-Content-Type: text/markdown

<p align="center">
<img alt="logo" src="https://storage.googleapis.com/metlo-security-public-images/metlo_logo_horiz%404x.png" height="80">
<h1 align="center">Metlo API Security</h1>
<p align="center">Secure Your API.</p>
</p>

## Installation

Currently Metlo's Python Agent supports 2 servers:

- Django
- Flask

It can be installed from `pypi` by running :

```shell
pip install metlo
```

## Configuration

### Django

Once installed, Metlo's middleware can be added by modifying middlewares list (in the projects `settings.py`) like so:

```python
MIDDLEWARE = [
...,
"metlo.django.MetloDjango",
]
```

and configuring a `METLO_CONFIG` attribute in the projects `settings.py` like this :

```python
METLO_CONFIG = {
"API_KEY": "<YOUR_METLO_API_KEY>",
"METLO_HOST": "<YOUR_METLO_COLLECTOR_URL>"
}
```

`METLO_CONFIG` can take an optional key-value pair representing the max number of workers for communicating with METLO.

### Flask

Once installed, METLO middleware can be added simply like :

```python
from flask import Flask

...
from metlo.flask import MetloFlask

app = Flask(__name__)
MetloFlask(app, "<YOUR_METLO_COLLECTOR_URL>", "<YOUR_METLO_API_KEY>")
```

The Flask Middleware takes the flask app, METLO collector url, and the METLO API Key as parameters. As an optional
parameter, a named value can be passed for max number of workers for communicating with METLO.

```python
MetloFlask(app, "<YOUR_METLO_COLLECTOR_URL>", "<YOUR_METLO_API_KEY>", workers="<WORKER-COUNT>")
```
10 changes: 10 additions & 0 deletions ingestors/python/metlo.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
README.md
pyproject.toml
setup.cfg
metlo/__init__.py
metlo/django.py
metlo/flask.py
metlo.egg-info/PKG-INFO
metlo.egg-info/SOURCES.txt
metlo.egg-info/dependency_links.txt
metlo.egg-info/top_level.txt
1 change: 1 addition & 0 deletions ingestors/python/metlo.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions ingestors/python/metlo.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
metlo
108 changes: 0 additions & 108 deletions ingestors/python/metlo/README.md

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings


class Middleware(object):
class MetloDjango(object):

def perform_request(self, data):
urlopen(
Expand Down Expand Up @@ -51,14 +51,14 @@ def __call__(self, request):
"path": request.path,
"parameters": list(map(lambda x: {"name": x[0], "value": x[1]}, params.items())),
},
"headers": dict(request.headers),
"headers": list(map(lambda x: {"name": x[0], "value": x[1]}, request.headers.items())),
"body": request.body.decode("utf-8"),
"method": request.method,
},
"response": {
"url": f"{dest_ip}:{request.META.get('SERVER_PORT')}",
"status": response.status_code,
"headers": dict(response.headers),
"headers": list(map(lambda x: {"name": x[0], "value": x[1]}, response.headers.items())),
"body": res_body,
},
"meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask import request


class Middleware:
class MetloFlask:
def perform_request(self, data):
urlopen(
url=self.saved_request,
Expand Down Expand Up @@ -47,14 +47,14 @@ def function(response, *args, **kwargs):
"path": request.path,
"parameters": list(map(lambda x: {"name": x[0], "value": x[1]}, request.args.items())),
},
"headers": dict(request.headers),
"headers": list(map(lambda x: {"name": x[0], "value": x[1]}, (request.headers).items())),
"body": request.data.decode("utf-8"),
"method": request.method,
},
"response": {
"url": f"{request.environ.get('SERVER_NAME')}:{request.environ.get('SERVER_PORT')}",
"status": response.status_code,
"headers": dict(response.headers),
"headers": list(map(lambda x: {"name": x[0], "value": x[1]}, (response.headers).items())),
"body": response.data.decode("utf-8"),
},
"meta": {
Expand Down
41 changes: 0 additions & 41 deletions ingestors/python/metlo/setup.cfg

This file was deleted.

2 changes: 0 additions & 2 deletions ingestors/python/metlo/src/__init__.py

This file was deleted.

Loading

0 comments on commit c8d9bf8

Please sign in to comment.