mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 10:37:56 +00:00 
			
		
		
		
	 17d29f983c
			
		
	
	17d29f983c
	
	
	
		
			
			* upgrade ember-data 5.3.2, uninstall legacy compat, upgrade ember-cli, ember-source * use query instead of findAll for auth methods, update tests * set mutableId for kmip * show generated private key data before transitioning to details * update kv metadata test * remove deprecated methods from path help service * add changelog, update readme version matrix * remove toggle template helper
		
			
				
	
	
		
			89 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /**
 | |
|  * Copyright (c) HashiCorp, Inc.
 | |
|  * SPDX-License-Identifier: BUSL-1.1
 | |
|  */
 | |
| 
 | |
| import Component from '@ember/component';
 | |
| import { set } from '@ember/object';
 | |
| import { task } from 'ember-concurrency';
 | |
| import { waitFor } from '@ember/test-waiters';
 | |
| 
 | |
| const BASE_64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gi;
 | |
| 
 | |
| export default Component.extend({
 | |
|   'data-test-pgp-file': true,
 | |
|   attributeBindings: ['data-test-pgp-file'],
 | |
|   classNames: ['box', 'is-fullwidth', 'is-marginless', 'is-shadowless'],
 | |
|   key: null,
 | |
|   index: null,
 | |
|   onChange: () => {},
 | |
| 
 | |
|   /*
 | |
|    * @public
 | |
|    * @param String
 | |
|    * Text to use as the label for the file input
 | |
|    * If null, a default will be rendered
 | |
|    */
 | |
|   label: null,
 | |
| 
 | |
|   /*
 | |
|    * @public
 | |
|    * @param String
 | |
|    * Text to use as help under the file input
 | |
|    * If null, a default will be rendered
 | |
|    */
 | |
|   fileHelpText: null,
 | |
| 
 | |
|   /*
 | |
|    * @public
 | |
|    * @param String
 | |
|    * Text to use as help under the textarea in text-input mode
 | |
|    * If null, a default will be rendered
 | |
|    */
 | |
|   textareaHelpText: null,
 | |
| 
 | |
|   readFile(file) {
 | |
|     const reader = new FileReader();
 | |
|     reader.onload = () => this.setPGPKey.perform(reader.result, file.name);
 | |
|     // this gives us a base64-encoded string which is important in the onload
 | |
|     reader.readAsDataURL(file);
 | |
|   },
 | |
| 
 | |
|   setPGPKey: task(
 | |
|     waitFor(function* (dataURL, filename) {
 | |
|       const b64File = dataURL.split(',')[1].trim();
 | |
|       const decoded = atob(b64File).trim();
 | |
| 
 | |
|       // If a b64-encoded file was uploaded, then after decoding, it
 | |
|       // will still be b64.
 | |
|       // If after decoding it's not b64, we want
 | |
|       // the original as it was only encoded when we used `readAsDataURL`.
 | |
|       const fileData = decoded.match(BASE_64_REGEX) ? decoded : b64File;
 | |
|       yield this.onChange(this.index, { value: fileData, filename: filename });
 | |
|     })
 | |
|   ),
 | |
| 
 | |
|   actions: {
 | |
|     handleToggle(e) {
 | |
|       set(this.key, 'enterAsText', e.target.checked);
 | |
|     },
 | |
|     pickedFile(e) {
 | |
|       const { files } = e.target;
 | |
|       if (!files.length) {
 | |
|         return;
 | |
|       }
 | |
|       for (let i = 0, len = files.length; i < len; i++) {
 | |
|         this.readFile(files[i]);
 | |
|       }
 | |
|     },
 | |
|     updateData(e) {
 | |
|       const key = this.key;
 | |
|       set(key, 'value', e.target.value);
 | |
|       this.onChange(this.index, this.key);
 | |
|     },
 | |
|     clearKey() {
 | |
|       this.onChange(this.index, { value: '' });
 | |
|     },
 | |
|   },
 | |
| });
 |