Commit 929b5263 authored by carignani's avatar carignani
Browse files

Prepare for release

parent 680e0ed8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
*.pyc
env
+8 −0
Original line number Diff line number Diff line
# Tosca Import/Export

## Create `env` file

   cp env_example env
   $EDITOR env # Customize SECRET

## Run with docker

@@ -20,3 +24,7 @@ Install prerequisites
Run the web_app

    python src/web_app.py

## Licensing

See LICENSE file.
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
#!/bin/bash
CNT=$(docker ps | grep tosca-ie | cut -d " " -f1)

if [ "$CNT" != "" ] ; then
@@ -10,5 +11,5 @@ fi

docker build -t tosca-ie-sample:latest .

docker run -d -t -p 5000:5000 tosca-ie-sample
docker run -d --restart unless-stopped -t -p 5000:5000 --env-file ./env tosca-ie-sample
+18 −0
Original line number Diff line number Diff line
'''
Configuration values
'''

import os

def env_or_false(key):
    '''
    Lookup environment key, returns False is not present
    '''
    try:
        return os.environ[key]
    except KeyError:
        return False

VERSION = "0.0.4"

SECRET = env_or_false("TOSCAIE_SECRET") or 'super_secret_key'
+32 −18
Original line number Diff line number Diff line
#!/bin/python3
'''
Web app to offer a frontend to the doc2tosca and tosca2doc tools

'''

import os
import shutil
@@ -15,8 +19,8 @@ import doc2tosca

class ReverseProxied(object):

    def __init__(self, app, script_name=None, scheme=None, server=None):
        self.app = app
    def __init__(self, the_app, script_name=None, scheme=None, server=None):
        self.app = the_app
        self.script_name = script_name
        self.scheme = scheme
        self.server = server
@@ -36,7 +40,6 @@ class ReverseProxied(object):
            environ['HTTP_HOST'] = server
        return self.app(environ, start_response)


app = Flask(__name__)
app.wsgi_app = ReverseProxied(app.wsgi_app, script_name='/tosca-ie')

@@ -45,11 +48,15 @@ UPLOAD_FOLDER = '/tmp/upload'
ALLOWED_EXTENSIONS = set(['txt', 'yaml', 'docx'])

app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.secret_key = 'super secret key'
app.secret_key = config.SECRET
app.config['SESSION_TYPE'] = 'filesystem'

TOSCA_DEFS = ['VNFD', 'NSD', 'PNFD']

MISSING_MODULE_ERR_MSG = \
    'Error: some TOSCA module missing. Make sure to \
    upload definitions for NSD, VNFD, PNFD.'

def allowed_file(filename):
    '''
    Check filename is in the list of allowed extensions
@@ -57,13 +64,16 @@ def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


@app.route("/")
def hello():
    '''
    Render home page
    '''
    return render_template("./home.html", VERSION=config.VERSION, doc_allowed_versions=doc2tosca.allowed_versions)
    return render_template(
        "./home.html", 
        VERSION=config.VERSION, 
        doc_allowed_versions=doc2tosca.allowed_versions
    )

@app.route("/doc2tosca-info")
def doc2tosca_info():
@@ -81,6 +91,9 @@ def tosca2doc_info():

@app.route("/tosca2doc", methods=['POST'])
def mk_tosca2doc():
    '''
    Execute tosca2doc on the uploaded files
    '''

    if 'file' not in request.files:
        flash('Error: No file uploaded.')
@@ -94,12 +107,8 @@ def mk_tosca2doc():
            if tosca_def in uploaded_file.filename or \
                tosca_def.lower() in uploaded_file.filename:
                found=True
                #if uploaded_file:
                #    print "-------------------"
                #    print uploaded_file.read()
                #    print "-------------------"
        if not found:
            flash('Error: some TOSCA module missing. Make sure to upload definitions for NSD, VNFD, PNFD.')
            flash(MISSING_MODULE_ERR_MSG)
            print('Error: TOSCA module missing.')
            return redirect("/tosca-ie")

@@ -133,27 +142,29 @@ def mk_tosca2doc():
    #return ("No content found")

def get_all_yaml_file_paths(directory): 
    '''
    Finds yaml files within a directory and sub directories and
    returns the list of paths
    '''

    # initializing empty file paths list
    file_paths = []

    # crawling through directory and subdirectories
    for root, directories, files in os.walk(directory):
    for root, _, files in os.walk(directory):
        for filename in files:
            if ".yaml" in filename:
                # join the two strings in order to form the full filepath.
                filepath = os.path.join(root, filename)
                file_paths.append(filepath)
                print(filepath)

    # returning all file paths
    return file_paths

@app.after_request
def after_request(response):
    '''
    Clean up files created by doc2tosca
    '''
    if request.path != '/doc2tosca':
        return response
    if g.get('tmp_dir') == None:
    if g.get('tmp_dir') is None:
        return response
    shutil.rmtree(g.tmp_dir, ignore_errors=True)
    print("Deleted {}\n\n".format(g.tmp_dir))
@@ -161,6 +172,9 @@ def after_request(response):

@app.route("/doc2tosca", methods=['POST'])
def mk_doc2tosca():
    '''
    Executes doc2tosca on the uploaded file
    '''

    zip_fn = "tosca_defs.zip"