From 8aa18a29a87574e1eb62f66f7d13bb7613a23c2a Mon Sep 17 00:00:00 2001 From: Sam Chow Date: Mon, 18 Jun 2018 11:01:14 -0400 Subject: [PATCH] Add writing config to file, modal for validation --- .../config_endpoints/api/tar_config_loader.py | 46 +++++-------------- .../load-config/load-config.component.ts | 19 ++++---- .../components/load-config/load-config.html | 21 ++++++++- .../config-certificates-field.html | 1 + 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/config_app/config_endpoints/api/tar_config_loader.py b/config_app/config_endpoints/api/tar_config_loader.py index 1891f1f09..d235dad3b 100644 --- a/config_app/config_endpoints/api/tar_config_loader.py +++ b/config_app/config_endpoints/api/tar_config_loader.py @@ -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') diff --git a/config_app/js/components/load-config/load-config.component.ts b/config_app/js/components/load-config/load-config.component.ts index 2279420c4..892958e03 100644 --- a/config_app/js/components/load-config/load-config.component.ts +++ b/config_app/js/components/load-config/load-config.component.ts @@ -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; } - - } \ No newline at end of file diff --git a/config_app/js/components/load-config/load-config.html b/config_app/js/components/load-config/load-config.html index 142c3f44f..3dd982f0d 100644 --- a/config_app/js/components/load-config/load-config.html +++ b/config_app/js/components/load-config/load-config.html @@ -1,4 +1,4 @@ -
+
+ +
+ +
diff --git a/config_app/js/config-field-templates/config-certificates-field.html b/config_app/js/config-field-templates/config-certificates-field.html index f20e4c459..1cbe5d569 100644 --- a/config_app/js/config-field-templates/config-certificates-field.html +++ b/config_app/js/config-field-templates/config-certificates-field.html @@ -19,6 +19,7 @@ Upload certificates: +