Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
[new] version 0.7.2
[info] rewrite code to be more flexible
  • Loading branch information
jirivrany committed Jul 13, 2023
2 parents 52dd517 + 9af2ec9 commit 4893aaa
Show file tree
Hide file tree
Showing 60 changed files with 3,369 additions and 2,358 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
config.py
run.py

# PyCharm
.idea/
Expand Down
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include flowapp/static/*
include flowapp/static/js/*

include flowapp/templates/*
include flowapp/templates/errors/*
include flowapp/templates/forms/*
include flowapp/templates/layouts/*
include flowapp/templates/pages/*
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Last part of the system is Guarda service. This systemctl service is running in
* [Local database instalation notes](./docs/DB_LOCAL.md)

## Change Log
- 0.7.2 - Dashboard and Main menu are now customizable in config. App is ready to be packaged using setup.py.
- 0.7.0 - ExaAPI now have two options - HTTP or RabbitMQ. ExaAPI process has been renamed, update of ExaBGP process value is needed for this version.
- 0.6.2 - External config for ExaAPI
- 0.6.0 - Bootstrap 5 in UI
Expand Down
55 changes: 32 additions & 23 deletions config.example.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,72 @@
class Config(object):
class Config():
"""
Default config options
"""

# Flask debugging
DEBUG = True
# Flask testing
TESTING = False
# SSO auth enabled
SSO_AUTH = False
# SSO LOGOUT
LOGOUT_URL = 'https://flowspec.example.com/Shibboleth.sso/Logout?return=https://shibbo.example.com/idp/profile/Logout'
LOGOUT_URL = "https://flowspec.example.com/Shibboleth.sso/Logout"
# SQL Alchemy config
SQLALCHEMY_TRACK_MODIFICATIONS = False
# URL of the ExaAPI
EXA_API_URL = 'http://localhost:5000/'

# ExaApi configuration
# possible values HTTP, RABBIT
EXA_API = "HTTP"
# for HTTP EXA_API_URL must be specified
EXA_API_URL = "http://localhost:5000/"
# for RABBITMQ EXA_API_RABBIT_* must be specified
EXA_API_RABBIT_HOST = "your rabbit host"
EXA_API_RABBIT_PORT = "rabit port (5672)"
EXA_API_RABBIT_PASS = "some secret password"
EXA_API_RABBIT_USER = "rabbit user"
EXA_API_RABBIT_VHOST = "rabbit vhost"
EXA_API_RABBIT_QUEUE = "exa_api"

# Secret keys for Flask Session and JWT (API and CSRF protection)
JWT_SECRET = 'GenerateSomeLongRandomSequence'
SECRET_KEY = 'GenerateSomeLongRandomSequence'
JWT_SECRET = "GenerateSomeLongRandomSequence"
SECRET_KEY = "GenerateSomeLongRandomSequence"

# LOCAL user parameters - when the app is used without SSO_AUTH
# Defined in User model
LOCAL_USER_UUID = 'admin@example.com'
LOCAL_USER_UUID = "admin@example.com"
# Defined in User model
LOCAL_USER_ID = 1
# Defined in Role model / default 1 - view, 2 - normal user, 3 - admin
LOCAL_USER_ROLES = ['admin']
LOCAL_USER_ROLES = ["admin"]
# Defined in Organization model
# List of organizations for the local user. There can be many of them.
# Define the name and the adress range. The range is then used for first data insert
# after the tables are created with db-init.py script.
LOCAL_USER_ORGS = [
{
'name': 'Example Org.',
'arange': '192.168.0.0/16\n2121:414:1a0b::/48'
},
{"name": "Example Org.", "arange": "192.168.0.0/16\n2121:414:1a0b::/48"},
]
# Defined in Role model / default 1 - view, 2 - normal user, 3 - admin
LOCAL_USER_ROLE_IDS = [3]
# Defined in Organization model
LOCAL_USER_ORG_IDS = [1]
# APP Name - display in main toolbar
APP_NAME = 'ExaFS'
APP_NAME = "ExaFS"
# Route Distinguisher for VRF
# When True set your rd string and label to be used in messages
USE_RD = True
RD_STRING = '7654:3210'
RD_LABEL = 'label for RD'

# When True set your rd string and label to be used in messages
USE_RD = True
RD_STRING = "7654:3210"
RD_LABEL = "label for RD"


class ProductionConfig(Config):
"""
Production config options
"""

# SQL Alchemy config string - mustl include user and pwd
SQLALCHEMY_DATABASE_URI = 'mysql://user:password@localhost/exafs?charset=utf8'
SQLALCHEMY_DATABASE_URI = "Your Productionl Database URI"
# Public IP of the production machine
LOCAL_IP = '127.0.0.1'
LOCAL_IP = "127.0.0.1"
# SSO AUTH enabled in produciion
SSO_AUTH = True
# Set true if you need debug in production
Expand All @@ -68,11 +77,11 @@ class DevelopmentConfig(Config):
"""
Development config options - usually for localhost development and debugging process
"""
SQLALCHEMY_DATABASE_URI = 'mysql://root:my-secret-pw@127.0.0.1:3306/exafs?host=127.0.0.1?port=3306?charset=utf8'
LOCAL_IP = '127.0.0.1'

SQLALCHEMY_DATABASE_URI = "Your Local Database URI"
LOCAL_IP = "127.0.0.1"
DEBUG = True


class TestingConfig(Config):

TESTING = True
2 changes: 1 addition & 1 deletion db-init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

from flask import Flask
from flowapp import app, db
from flowapp import db
from flowapp.models import *

import config
Expand Down
18 changes: 9 additions & 9 deletions exaapi/config.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
Add your log settings and rename to config.py
"""

LOG_FILE = '/var/log/exafs/exa_api.log'
LOG_FORMAT = '%(asctime)s: %(message)s'
LOG_FILE = "/var/log/exafs/exa_api.log"
LOG_FORMAT = "%(asctime)s: %(message)s"


# rabbit mq
# rabbit mq
# note - rabbit mq must be enabled in main app config
# credentials and queue must be set here for the same values
EXA_API_RABBIT_HOST = 'localhost'
EXA_API_RABBIT_PORT = '5672'
EXA_API_RABBIT_PASS = 'mysecurepassword'
EXA_API_RABBIT_USER = 'myexaapiuser'
EXA_API_RABBIT_VHOST = '/'
EXA_API_RABBIT_QUEUE = 'my_exa_api_queue'
EXA_API_RABBIT_HOST = "localhost"
EXA_API_RABBIT_PORT = "5672"
EXA_API_RABBIT_PASS = "mysecurepassword"
EXA_API_RABBIT_USER = "myexaapiuser"
EXA_API_RABBIT_VHOST = "/"
EXA_API_RABBIT_QUEUE = "my_exa_api_queue"
12 changes: 6 additions & 6 deletions exaapi/exa_api_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Each command received in the POST request is send to stdout and captured by ExaBGP.
"""

from flask import Flask, request, abort
from flask import Flask, request
from sys import stdout

import exa_api_logger
Expand All @@ -17,15 +17,15 @@
logger = exa_api_logger.create()


@app.route('/', methods=['POST'])
@app.route("/", methods=["POST"])
def command():
cmd = request.form['command']
cmd = request.form["command"]
logger.info(cmd)
stdout.write('%s\n' % cmd)
stdout.write("%s\n" % cmd)
stdout.flush()

return '%s\n' % cmd
return "%s\n" % cmd


if __name__ == '__main__':
if __name__ == "__main__":
app.run()
3 changes: 2 additions & 1 deletion exaapi/exa_api_logger.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging
import config


def create():
logger = logging.getLogger(__name__)
f_format = logging.Formatter(config.LOG_FORMAT)
f_handler = logging.FileHandler(config.LOG_FILE)
f_handler.setFormatter(f_format)
logger.setLevel(logging.INFO)
logger.addHandler(f_handler)
return logger
return logger
29 changes: 17 additions & 12 deletions exaapi/exa_api_rabbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
Each command received from the queue is send to stdout and captured by ExaBGP.
"""
import pika, sys, os
import pika
import sys
import os
from time import sleep

import config
import exa_api_logger

logger = exa_api_logger.create()


def callback(ch, method, properties, body):
body = body.decode("utf-8")
body = body.decode("utf-8")
logger.info(body)
sys.stdout.write('%s\n' % body)
sys.stdout.write("%s\n" % body)
sys.stdout.flush()


Expand All @@ -27,24 +30,26 @@ def main():
passwd = config.EXA_API_RABBIT_PASS
queue = config.EXA_API_RABBIT_QUEUE
credentials = pika.PlainCredentials(user, passwd)
parameters = pika.ConnectionParameters(config.EXA_API_RABBIT_HOST,
config.EXA_API_RABBIT_PORT,
config.EXA_API_RABBIT_VHOST,
credentials)
parameters = pika.ConnectionParameters(
config.EXA_API_RABBIT_HOST,
config.EXA_API_RABBIT_PORT,
config.EXA_API_RABBIT_VHOST,
credentials,
)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()

channel.queue_declare(queue=queue)
channel.queue_declare(queue=queue)

channel.basic_consume(queue=queue, on_message_callback=callback, auto_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
print(" [*] Waiting for messages. To exit press CTRL+C")
try:
channel.start_consuming()
except KeyboardInterrupt:
channel.stop_consuming()
connection.close()
print('\nInterrupted')
print("\nInterrupted")
try:
sys.exit(0)
except SystemExit:
Expand All @@ -53,6 +58,6 @@ def main():
sleep(15)
continue

if __name__ == '__main__':

if __name__ == "__main__":
main()

16 changes: 8 additions & 8 deletions exaapi/rabbit_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
passwd = config.EXA_API_RABBIT_PASS
queue = config.EXA_API_RABBIT_QUEUE
credentials = pika.PlainCredentials(user, passwd)
parameters = pika.ConnectionParameters(config.EXA_API_RABBIT_HOST,
config.EXA_API_RABBIT_PORT,
config.EXA_API_RABBIT_VHOST,
credentials)
parameters = pika.ConnectionParameters(
config.EXA_API_RABBIT_HOST,
config.EXA_API_RABBIT_PORT,
config.EXA_API_RABBIT_VHOST,
credentials,
)

connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue=queue)
channel.queue_declare(queue=queue)
route = sys.argv[1]

print("got :", route)

channel.basic_publish(exchange='',
routing_key=queue,
body=route)
channel.basic_publish(exchange="", routing_key=queue, body=route)
1 change: 1 addition & 0 deletions flowapp/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.7.2"
Loading

0 comments on commit 4893aaa

Please sign in to comment.