Skip to content

Commit

Permalink
Add page for updating tosca templates and parameters from git repo (#50)
Browse files Browse the repository at this point in the history
* Add page for updating templates and parameters from git repo

* Add checkbox to enable/disable notifications

* Add support for private git repos

* Add comment area and improve error message

* Moving settings page under Admin menu

* Remove unused import

* Clean and format

* Fix config parameters

* Update flask and other dependencies

* Update flask and other dependencies

* Use local js and css

* Fix summernote folder

* Call iam userinfo endpoint when really needed

* Save tosca config in redis

* Fix bug in directory path manipulation

* Fix settings management

* Save last configuration info

* Add last configuration info

* Fix user info setting and update

* Remove unused import

* Add cache per slas

* Fix last configuration info

* Fix inputs in case of dep update

* Fix form for dep update

* Fix update

* Fix cancel action
  • Loading branch information
maricaantonacci authored Oct 18, 2023
1 parent ed3982c commit 559e874
Show file tree
Hide file tree
Showing 441 changed files with 155,621 additions and 225 deletions.
25 changes: 15 additions & 10 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import sys
import socket

Expand All @@ -24,6 +24,8 @@
from flask_mail import Mail
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, upgrade
from flask_caching import Cache
from flask_redis import FlaskRedis
from app.lib.ToscaInfo import ToscaInfo
from app.lib.Vault import Vault

Expand All @@ -38,23 +40,20 @@
# Intialize Alembic
alembic: Alembic = Alembic()

# initialize ToscaInfo
tosca: ToscaInfo = ToscaInfo()

# initialize Vault
vaultservice: Vault = Vault()

app = Flask(__name__, instance_relative_config=True)
app.wsgi_app = ProxyFix(app.wsgi_app)
app.secret_key = "30bb7cf2-1fef-4d26-83f0-8096b6dcc7a3"
app.config.from_object('config.default')
app.config.from_json('config.json')
app.config.from_file('config.json', json.load)

if app.config.get("FEATURE_VAULT_INTEGRATION") == "yes":
app.config.from_json('vault-config.json')
app.config.from_file('vault-config.json', json.load)

if app.config.get("FEATURE_S3CREDS_MENU") == "yes":
app.config.from_json('s3-config.json')
app.config.from_file('s3-config.json', json.load)

profile = app.config.get('CONFIGURATION_PROFILE')
if profile is not None and profile != 'default':
Expand Down Expand Up @@ -95,13 +94,21 @@ def inject_settings():
db.init_app(app)
migrate.init_app(app, db)
alembic.init_app(app, run_mkdir=False)
tosca.init_app(app)

app.config['CACHE_TYPE'] = 'RedisCache'
app.config['CACHE_REDIS_URL'] = app.config.get('REDIS_URL')
redis_client = FlaskRedis(app)
cache = Cache(app)

if app.config.get("FEATURE_VAULT_INTEGRATION") == "yes":
vaultservice.init_app(app)

mail = Mail(app)

# initialize ToscaInfo
tosca: ToscaInfo = ToscaInfo(redis_client, app.config.get("TOSCA_TEMPLATES_DIR"),
app.config.get("SETTINGS_DIR"))

from app.errors.routes import errors_bp
app.register_blueprint(errors_bp)

Expand Down Expand Up @@ -152,8 +159,6 @@ def inject_settings():

logging.basicConfig(level=numeric_level)

from app import models

# check if database exists
engine = db.get_engine(app)
if not database_exists(engine.url): # Checks for the first time
Expand Down
26 changes: 13 additions & 13 deletions app/deployments/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def deptemplate(depid=None):
template = orchestrator.get_template(access_token, depid)
except Exception as e:
flash("Error getting template: ".format(str(e)), 'danger')
return redirect(url_for('home_bp.home'))
return redirect(url_for('deployments_bp.showdeployments'))

return render_template('deptemplate.html', template=template)

Expand Down Expand Up @@ -223,7 +223,7 @@ def depoutput(depid=None):
# retrieve deployment from DB
dep = dbhelpers.get_deployment(depid)
if dep is None:
return redirect(url_for('home_bp.home'))
return redirect(url_for('deployments_bp.showdeployments'))
else:
i = json.loads(dep.inputs.strip('\"')) if dep.inputs else {}
stinputs = json.loads(dep.stinputs.strip('\"')) if dep.stinputs else {}
Expand Down Expand Up @@ -299,7 +299,7 @@ def deptemplatedb(depid):
# retrieve deployment from DB
dep = dbhelpers.get_deployment(depid)
if dep is None:
return redirect(url_for('home_bp.home'))
return redirect(url_for('deployments_bp.showdeployments'))
else:
template = dep.template
return render_template('deptemplate.html', template=template)
Expand Down Expand Up @@ -460,12 +460,9 @@ def updatedep():
else:
remove_sla_from_template(template)

inputs = {k: v for (k, v) in form_data.items() if not k.startswith("extra_opts.") and not k == '_depid'}

additionaldescription = form_data['additional_description']

if additionaldescription is not None:
inputs['additional_description'] = additionaldescription
stinputs = json.loads(dep.stinputs.strip('\"')) if dep.stinputs else {}
inputs = {k: v for (k, v) in form_data.items() if not k.startswith("extra_opts.") and not k == '_depid' and (
k in stinputs and 'updatable' in stinputs[k] and stinputs[k]['updatable'] == True)}

app.logger.debug("Parameters: " + json.dumps(inputs))

Expand All @@ -488,7 +485,6 @@ def updatedep():
# store data into database
dep.keep_last_attempt = keep_last_attempt
dep.feedback_required = feedback_required
dep.description = additionaldescription
dep.template = template_text
oldinputs = json.loads(dep.inputs.strip('\"')) if dep.inputs else {}
updatedinputs = {**oldinputs, **inputs}
Expand All @@ -506,6 +502,8 @@ def updatedep():
def configure():
access_token = iam_blueprint.session.token['access_token']

tosca_info, tosca_templates, tosca_gmetadata = tosca.get()

selected_tosca = None

if request.method == 'POST':
Expand All @@ -515,15 +513,15 @@ def configure():
selected_tosca = request.args['selected_tosca']

if 'selected_group' in request.args:
templates = tosca.tosca_gmetadata[request.args['selected_group']]['templates']
templates = tosca_gmetadata[request.args['selected_group']]['templates']
if len(templates) == 1:
selected_tosca = templates[0]['name']
else:
return render_template('choosedep.html', templates=templates)

if selected_tosca:

template = copy.deepcopy(tosca.tosca_info[selected_tosca])
template = copy.deepcopy(tosca_info[selected_tosca])
# Manage eventual overrides
for k, v in template['inputs'].items():
if 'group_overrides' in v and session['active_usergroup'] in v['group_overrides']:
Expand Down Expand Up @@ -583,9 +581,11 @@ def add_sla_to_template(template, sla_id):
@deployments_bp.route('/submit', methods=['POST'])
@auth.authorized_with_valid_token
def createdep():
tosca_info, tosca_templates, tosca_gmetadata = tosca.get()

access_token = iam_blueprint.session.token['access_token']
selected_template = request.args.get('template')
source_template = tosca.tosca_info[selected_template]
source_template = tosca_info[selected_template]

app.logger.debug("Form data: " + json.dumps(request.form.to_dict()))

Expand Down
2 changes: 1 addition & 1 deletion app/deployments/templates/choosedep.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h4 class="font-weight-bold text-primary">Select</h4>
{% endfor %}
<br>
<button type="submit" class="btn btn-success submitBtn">Submit</button>
<button id="cancelBtn" type=button class="btn btn-small btn-primary" onclick="location.href='{{ url_for('home_bp.home') }}'">
<button id="cancelBtn" type=button class="btn btn-small btn-primary" onclick="location.href='{{ url_for('home_bp.portfolio') }}'">
<span class="fas fa-ban mr-2"></span>Cancel</button>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/deployments/templates/createdep.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h4 class="font-weight-bold text-primary">
<strong>Warning!</strong> You have not filled some mandatory fields. Please check the red boxes in each tab.
</div>
<button type="submit" class="btn btn-success submitBtn">Submit</button>
<button id="cancelBtn" type=button class="btn btn-small btn-primary" onclick="location.href='{{ url_for('home_bp.home') }}'">
<button id="cancelBtn" type=button class="btn btn-small btn-primary" onclick="location.href='{{ url_for('home_bp.portfolio') }}'">
<span class="fas fa-ban mr-2"></span>Cancel</button>
</form>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/deployments/templates/input_types.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@

<!-- list text type -->
{% elif value.type == "list" and value.entry_schema.type|lower == "string" %}
<fieldset class="border p-2">
<fieldset class="border p-2" {{mode}}>
<!--legend class="w-auto">{{key}}</legend-->
{% include 'inputs/list.html' %}
</fieldset>
<!-- end list text type -->

<!-- list text type -->
{% elif value.type == "list" and value.entry_schema.type|lower == "map" %}
<fieldset class="border p-2">
<fieldset class="border p-2" {{mode}}>
<!--legend class="w-auto">{{key}}</legend-->
{% include 'inputs/list_map_string.html' %}
</fieldset>
Expand Down Expand Up @@ -177,15 +177,15 @@ <h5 class="modal-title">Storage encryption alert</h5>

<!-- List of map of strings -->
{% elif value.type == "map" and value.entry_schema.type == "string" %}
<fieldset class="border p-2">
<fieldset class="border p-2" {{mode}}>
{% include 'inputs/map_string.html' %}
</fieldset>
<!-- end Port field -->

<!-- Port field -->
{% elif value.type == "map" and (value.entry_schema.type == "tosca.datatypes.network.PortSpec" or value.entry_schema.type == "tosca.datatypes.indigo.network.PortSpec") %}
{% set ports_type = "indigo" if 'indigo' in value.entry_schema.type else "" %}
<fieldset class="border p-2">
<fieldset class="border p-2" {{mode}}>
{% include 'inputs/ports.html' %}
</fieldset>
<!-- end Port field -->
Expand Down
2 changes: 1 addition & 1 deletion app/deployments/templates/inputs/combined.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<select class="js-example-basic-single js-states form-control" id="{{key}}" name="{{key}}" data-action="removeOnSubmit" onchange="setfields(this)" required>
<select class="js-example-basic-single js-states form-control" id="{{key}}" name="{{key}}" data-action="removeOnSubmit" onchange="setfields(this)" {{mode}} required>
<option value="" disabled selected>--Select--</option>
{% for constraint in value.constraints %}
<option value="{{constraint['value']}}" data-values="{{constraint['set']}}">{{constraint['label']}}</option>
Expand Down
2 changes: 1 addition & 1 deletion app/deployments/templates/inputs/dependent_select.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<select class="js-example-basic-single js-states form-control" id="{{key}}" name="{{key}}" data-parent-id="{{value.parent}}">
<select class="js-example-basic-single js-states form-control" id="{{key}}" name="{{key}}" data-parent-id="{{value.parent}}" {{mode}}>
{% for constraint in value.constraints %}
<option data-parent-value="{{constraint['parent_value']}}" value="{{constraint['value']}}" {% if constraint['value'] in value.default %}selected="selected"{% endif %}>{{constraint['label']}}</option>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion app/deployments/templates/inputs/list.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="mt-2">
<div id="{{key}}-container"></div>
<button type="button" class="btn btn-sm btn-outline-info" id="add-new-item" class="add-new" data-tag-name="{{key}}">Add</button>
<input id="id-{{key}}" type="hidden" data-output-type="json" name="{{key}}" value""/>
<input id="id-{{key}}" type="hidden" data-output-type="json" name="{{key}}" value=""/>
</div>


Expand Down
2 changes: 1 addition & 1 deletion app/deployments/templates/inputs/list_map_string.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="mt-2">
<div id="{{key}}-container"></div>
<button type="button" class="btn btn-sm btn-outline-info" id="add-new-item" class="add-new" data-tag-name="{{key}}" onclick="addItem(this)">Add</button>
<input id="id-{{key}}" type="hidden" data-output-type="json" name="{{key}}" value""/>
<input id="id-{{key}}" type="hidden" data-output-type="json" name="{{key}}" value=""/>
</div>


Expand Down
2 changes: 1 addition & 1 deletion app/deployments/templates/inputs/map_string.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="mt-2">
<div id="{{key}}-container"></div>
<button type="button" class="btn btn-sm btn-outline-info" id="add-new-item" class="add-new" data-tag-name="{{key}}">Add</button>
<input id="id-{{key}}" type="hidden" data-output-type="json" name="{{key}}" value""/>
<input id="id-{{key}}" type="hidden" data-output-type="json" name="{{key}}" value=""/>
</div>


Expand Down
12 changes: 4 additions & 8 deletions app/deployments/templates/updatedep.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
{% extends "base.html" %}

{% block content %}

<br>
<div class="container">

<div class="card shadow mb-4">
<div class="card-header py-3">
<h4 class="font-weight-bold text-primary">
Update deployment{% if template['metadata']['display_name'] is defined %}: {{template['metadata']['display_name']}}{% else %}{{selectedTemplate}}{% endif %}
Update deployment {{ depid }}
</h4>
</div>

<div class="card-body">
<div class="alert alert-info">
<strong>Description:</strong> {{template['description']}}
</div>

<form id="depSubmit" action="{{ url_for('deployments_bp.updatedep', template=template) }}" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="additional_description">Deployment description</label>
<input type="text" class="form-control" id="additional_description" name="additional_description" placeholder="description" value="{{instance_description}}" required>
<input type="text" class="form-control" id="additional_description" name="additional_description" placeholder="description" value="{{instance_description}}" disabled required>
</div>
{% include 'config_form.html' %}
<input type="hidden" name="_depid" id="_depid" value="{{depid}}"/>
<button type="submit" class="btn btn-success submitBtn">Submit</button>
<button id="cancelBtn" type=button class="btn btn-small btn-primary" onclick="location.href='{{ url_for('home_bp.home') }}'">
<button id="cancelBtn" type=button class="btn btn-small btn-primary" onclick="location.href='{{ url_for('deployments_bp.showdeployments') }}'">
<span class="fas fa-ban mr-2"></span>Cancel</button>
</form>
</div>
Expand Down
Loading

0 comments on commit 559e874

Please sign in to comment.