Add writing config to file, modal for validation

This commit is contained in:
Sam Chow 2018-06-18 11:01:14 -04:00
parent c7513199df
commit 8aa18a29a8
4 changed files with 43 additions and 44 deletions

View file

@ -1,6 +1,8 @@
import logging
from flask import abort, request
from flask import request, make_response
from config_app.c_app import config_provider
from config_app.config_endpoints.api import resource, ApiResource, nickname, validate_json_request
logger = logging.getLogger(__name__)
@ -8,40 +10,16 @@ logger = logging.getLogger(__name__)
@resource('/v1/configapp/tarconfig')
class TarConfigLoader(ApiResource):
""" Resource for validating a block of configuration against an external service. """
schemas = {
'ValidateUploadConfig': {
'type': 'object',
'description': '',
'required': [
'config'
],
'properties': {
'config': {
'type': 'object'
},
},
},
}
@nickname('uploadTarballConfig')
# @validate_json_request('ValidateUploadConfig')
def post(self):
""" Extracts and validates all configuration from """
logger.debug('hello world!')
logger.debug(request)
logger.debug('hello world!')
logger.debug(request.files)
# logger.debug('hello world!')
# logger.debug(request.body)
# logger.debug(request.data)
logger.debug('hello world!')
logger.debug(request.files)
logger.debug('hello world!')
logger.debug(request.mimetype)
logger.debug('hello world!')
logger.debug(request.get_data())
logger.debug('hello world!')
logger.debug(request.get_json())
logger.debug('hello world!')
""" Loads tarball config into the config provider """
input_stream = request.stream
abort(418)
# since we're working with a tar file, shouldn't be larger than ~20KB, so just read the whole thing into mem
buf = input_stream.read(-1)
# TODO(sam): refactor config provider to accept a stream write to avoid loading into memory
config_provider.write_volume_file('test_tar.tar.gz', buf)
return make_response('OK')

View file

@ -1,10 +1,7 @@
import { Input, Component, Inject } from 'ng-metadata/core';
import { Component, Inject } from 'ng-metadata/core';
const templateUrl = require('./load-config.html');
const styleUrl = require('./load-config.css');
declare let bootbox: any;
declare let window: any;
@Component({
selector: 'load-config',
templateUrl,
@ -13,6 +10,7 @@ declare let window: any;
export class LoadConfigComponent {
private isReady: boolean = false;
private uploadFunc: Function;
private state: 'load' | 'validate' = 'load';
private constructor(@Inject('ApiService') private apiService: any) {
}
@ -27,9 +25,14 @@ export class LoadConfigComponent {
}
private uploadTarball() {
this.uploadFunc(resp => {
console.log('hi')
console.log(resp)
this.uploadFunc(success => {
if (success) {
this.state = 'validate';
}
else {
this.apiService.errorDisplay('Could not upload configuration. Please reload the page and try again.\n' +
'If this problem persists, please contact support')();
}
});
}
@ -42,6 +45,4 @@ export class LoadConfigComponent {
private filesValidated(files, uploadFiles) {
this.uploadFunc = uploadFiles;
}
}

View file

@ -1,4 +1,4 @@
<div>
<div ng-if="$ctrl.state === 'load'">
<div class="co-dialog modal fade initial-setup-modal in" id="setupModal" style="display: block;">
<div class="modal-backdrop fade in" style="height: 1000px;"></div>
<div class="modal-dialog fade in">
@ -26,3 +26,22 @@
</div><!-- /.modal-dialog -->
</div>
</div>
<div ng-if="$ctrl.state === 'validate'">
<div class="co-dialog modal fade initial-setup-modal in" id="validateModal" style="display: block;">
<div class="modal-backdrop fade in" style="height: 1000px;"></div>
<div class="modal-dialog fade in">
<div class="modal-content">
<!-- Header -->
<div class="modal-header">
<h4 class="modal-title"><span>Validate Config</span></h4>
</div>
<!-- Body -->
<div class="modal-body">
<span>Validating Config...</span>
spinner here...
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
</div>

View file

@ -19,6 +19,7 @@
<tr>
<td>Upload certificates:</td>
<td>
<!--TODO(sam): fix this upload box to pass in the url it needs for custom certs (file-upload-box hardcodes right now)-->
<div class="file-upload-box"
select-message="Select custom certificate to add to configuration. Must be in PEM format and end extension '.crt'"
files-selected="handleCertsSelected(files, callback)"