link config comp to upload files to endpoint
This commit is contained in:
parent
b631b0f271
commit
c7513199df
6 changed files with 105 additions and 31 deletions
|
@ -137,4 +137,5 @@ import config_endpoints.api.discovery
|
||||||
import config_endpoints.api.suconfig
|
import config_endpoints.api.suconfig
|
||||||
import config_endpoints.api.superuser
|
import config_endpoints.api.superuser
|
||||||
import config_endpoints.api.user
|
import config_endpoints.api.user
|
||||||
|
import config_endpoints.api.tar_config_loader
|
||||||
|
|
||||||
|
|
47
config_app/config_endpoints/api/tar_config_loader.py
Normal file
47
config_app/config_endpoints/api/tar_config_loader.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
import logging
|
||||||
|
from flask import abort, request
|
||||||
|
|
||||||
|
from config_app.config_endpoints.api import resource, ApiResource, nickname, validate_json_request
|
||||||
|
|
||||||
|
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!')
|
||||||
|
|
||||||
|
abort(418)
|
|
@ -34,7 +34,7 @@ angular.module('quay-config').directive('fileUploadBox', function () {
|
||||||
|
|
||||||
var conductUpload = function(file, url, fileId, mimeType, progressCb, doneCb) {
|
var conductUpload = function(file, url, fileId, mimeType, progressCb, doneCb) {
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
request.open('PUT', url, true);
|
request.open('POST', url, true);
|
||||||
request.setRequestHeader('Content-Type', mimeType);
|
request.setRequestHeader('Content-Type', mimeType);
|
||||||
request.onprogress = function(e) {
|
request.onprogress = function(e) {
|
||||||
$scope.$apply(function() {
|
$scope.$apply(function() {
|
||||||
|
@ -103,12 +103,13 @@ angular.module('quay-config').directive('fileUploadBox', function () {
|
||||||
$scope.currentlyUploadingFile = currentFile;
|
$scope.currentlyUploadingFile = currentFile;
|
||||||
$scope.uploadProgress = 0;
|
$scope.uploadProgress = 0;
|
||||||
|
|
||||||
ApiService.getFiledropUrl(data).then(function(resp) {
|
// ApiService.getFiledropUrl(data).then(function(resp) {
|
||||||
// Perform the upload.
|
// // Perform the upload.
|
||||||
conductUpload(currentFile, resp.url, resp.file_id, mimeType, progressCb, doneCb);
|
// conductUpload(currentFile, resp.url, resp.file_id, mimeType, progressCb, doneCb);
|
||||||
}, function() {
|
// }, function() {
|
||||||
callback(false, 'Could not retrieve upload URL');
|
// callback(false, 'Could not retrieve upload URL');
|
||||||
});
|
// });
|
||||||
|
conductUpload(currentFile, '/api/v1/configapp/tarconfig','fileIdIsUnused', mimeType, progressCb, doneCb);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start the uploading.
|
// Start the uploading.
|
||||||
|
|
|
@ -1,32 +1,47 @@
|
||||||
import { Input, Component, Inject } from 'ng-metadata/core';
|
import { Input, Component, Inject } from 'ng-metadata/core';
|
||||||
const templateUrl = require('./load-config.html');
|
const templateUrl = require('./load-config.html');
|
||||||
|
const styleUrl = require('./load-config.css');
|
||||||
|
|
||||||
|
declare let bootbox: any;
|
||||||
|
declare let window: any;
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'load-config',
|
selector: 'load-config',
|
||||||
templateUrl,
|
templateUrl,
|
||||||
|
styleUrls: [ styleUrl ],
|
||||||
})
|
})
|
||||||
export class LoadConfigComponent {
|
export class LoadConfigComponent {
|
||||||
private resetUpload: number = 0;
|
private isReady: boolean = false;
|
||||||
|
private uploadFunc: Function;
|
||||||
|
|
||||||
private handleTarballSelected(files, callback) {
|
private constructor(@Inject('ApiService') private apiService: any) {
|
||||||
console.log('hi world')
|
|
||||||
/*
|
|
||||||
$scope.certsUploading = true;
|
|
||||||
$upload.upload({
|
|
||||||
url: '/api/v1/superuser/customcerts/' + files[0].name,
|
|
||||||
method: 'POST',
|
|
||||||
data: {'_csrf_token': window.__token},
|
|
||||||
file: files[0]
|
|
||||||
}).success(function() {
|
|
||||||
callback(true);
|
|
||||||
$scope.resetUpload++;
|
|
||||||
loadCertificates();
|
|
||||||
}).error(function(r) {
|
|
||||||
bootbox.alert('Could not upload certificate')
|
|
||||||
callback(false);
|
|
||||||
$scope.resetUpload++;
|
|
||||||
loadCertificates();
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleTarballSelected(files: File[], callback: Function) {
|
||||||
|
this.isReady = true;
|
||||||
|
callback(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleTarballCleared() {
|
||||||
|
this.isReady = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private uploadTarball() {
|
||||||
|
this.uploadFunc(resp => {
|
||||||
|
console.log('hi')
|
||||||
|
console.log(resp)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When files are validated, this is called by the child to give us
|
||||||
|
* the callback function to upload
|
||||||
|
* @param files: files to upload
|
||||||
|
* @param uploadFiles: function to call to upload files
|
||||||
|
*/
|
||||||
|
private filesValidated(files, uploadFiles) {
|
||||||
|
this.uploadFunc = uploadFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
4
config_app/js/components/load-config/load-config.css
Normal file
4
config_app/js/components/load-config/load-config.css
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||
|
.load-config__body strong {
|
||||||
|
}
|
|
@ -8,14 +8,20 @@
|
||||||
<h4 class="modal-title"><span>Load Config</span></h4>
|
<h4 class="modal-title"><span>Load Config</span></h4>
|
||||||
</div>
|
</div>
|
||||||
<!-- Body -->
|
<!-- Body -->
|
||||||
<div>
|
<div class="modal-body">
|
||||||
Please upload a tarball
|
<span>Please upload the previous configuration</span>
|
||||||
<div class="file-upload-box"
|
<div class="file-upload-box"
|
||||||
select-message="Select a previous configuration to modify. Must be in tar.gz format"
|
select-message="Select a previous configuration to modify. Must be in tar.gz format"
|
||||||
files-selected="$ctrl.handleTarballSelected(files, callback)"
|
files-selected="$ctrl.handleTarballSelected(files, callback)"
|
||||||
reset="$ctrl.resetUpload"
|
files-cleared="$ctrl.handleFilesCleared()"
|
||||||
|
files-validated="$ctrl.filesValidated(files, uploadFiles)"
|
||||||
extensions="['application/gzip', '.gz']"></div>
|
extensions="['application/gzip', '.gz']"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-primary" ng-click="$ctrl.uploadTarball()" ng-disabled="!$ctrl.isReady">
|
||||||
|
Upload Configuration
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div><!-- /.modal-content -->
|
</div><!-- /.modal-content -->
|
||||||
</div><!-- /.modal-dialog -->
|
</div><!-- /.modal-dialog -->
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue