mobiletto 1.1.10 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -0
- package/docs/README.md +113 -0
- package/docs/af/README.md +455 -0
- package/docs/am/README.md +455 -0
- package/docs/ar/README.md +455 -0
- package/docs/az/README.md +455 -0
- package/docs/be/README.md +455 -0
- package/docs/bg/README.md +455 -0
- package/docs/bn/README.md +455 -0
- package/docs/bs/README.md +455 -0
- package/docs/ca/README.md +455 -0
- package/docs/ceb/README.md +455 -0
- package/docs/co/README.md +455 -0
- package/docs/cs/README.md +455 -0
- package/docs/cy/README.md +455 -0
- package/docs/da/README.md +455 -0
- package/docs/de/README.md +455 -0
- package/docs/el/README.md +455 -0
- package/docs/eo/README.md +455 -0
- package/docs/es/README.md +455 -0
- package/docs/et/README.md +455 -0
- package/docs/eu/README.md +455 -0
- package/docs/fa/README.md +455 -0
- package/docs/fi/README.md +455 -0
- package/docs/fr/README.md +455 -0
- package/docs/fy/README.md +455 -0
- package/docs/ga/README.md +455 -0
- package/docs/gd/README.md +455 -0
- package/docs/gl/README.md +455 -0
- package/docs/gu/README.md +455 -0
- package/docs/ha/README.md +455 -0
- package/docs/haw/README.md +455 -0
- package/docs/he/README.md +455 -0
- package/docs/hi/README.md +455 -0
- package/docs/hmn/README.md +455 -0
- package/docs/hr/README.md +455 -0
- package/docs/ht/README.md +455 -0
- package/docs/hu/README.md +455 -0
- package/docs/hy/README.md +455 -0
- package/docs/id/README.md +455 -0
- package/docs/ig/README.md +455 -0
- package/docs/is/README.md +455 -0
- package/docs/it/README.md +455 -0
- package/docs/iw/README.md +455 -0
- package/docs/ja/README.md +455 -0
- package/docs/jv/README.md +455 -0
- package/docs/ka/README.md +455 -0
- package/docs/kk/README.md +455 -0
- package/docs/km/README.md +455 -0
- package/docs/kn/README.md +455 -0
- package/docs/ko/README.md +455 -0
- package/docs/ku/README.md +455 -0
- package/docs/ky/README.md +455 -0
- package/docs/la/README.md +455 -0
- package/docs/lb/README.md +455 -0
- package/docs/lo/README.md +455 -0
- package/docs/lt/README.md +455 -0
- package/docs/lv/README.md +455 -0
- package/docs/mg/README.md +455 -0
- package/docs/mi/README.md +455 -0
- package/docs/mk/README.md +455 -0
- package/docs/ml/README.md +455 -0
- package/docs/mn/README.md +455 -0
- package/docs/mr/README.md +455 -0
- package/docs/ms/README.md +455 -0
- package/docs/mt/README.md +455 -0
- package/docs/my/README.md +455 -0
- package/docs/ne/README.md +455 -0
- package/docs/nl/README.md +455 -0
- package/docs/no/README.md +455 -0
- package/docs/ny/README.md +455 -0
- package/docs/or/README.md +455 -0
- package/docs/pa/README.md +455 -0
- package/docs/pl/README.md +455 -0
- package/docs/ps/README.md +455 -0
- package/docs/pt/README.md +455 -0
- package/docs/ro/README.md +455 -0
- package/docs/ru/README.md +455 -0
- package/docs/rw/README.md +455 -0
- package/docs/sd/README.md +455 -0
- package/docs/si/README.md +455 -0
- package/docs/sk/README.md +455 -0
- package/docs/sl/README.md +455 -0
- package/docs/sm/README.md +455 -0
- package/docs/sn/README.md +455 -0
- package/docs/so/README.md +455 -0
- package/docs/sq/README.md +455 -0
- package/docs/sr/README.md +455 -0
- package/docs/st/README.md +455 -0
- package/docs/su/README.md +455 -0
- package/docs/sv/README.md +455 -0
- package/docs/sw/README.md +455 -0
- package/docs/ta/README.md +455 -0
- package/docs/te/README.md +455 -0
- package/docs/tg/README.md +455 -0
- package/docs/th/README.md +455 -0
- package/docs/tk/README.md +455 -0
- package/docs/tl/README.md +455 -0
- package/docs/tr/README.md +455 -0
- package/docs/tt/README.md +455 -0
- package/docs/ug/README.md +455 -0
- package/docs/uk/README.md +455 -0
- package/docs/ur/README.md +455 -0
- package/docs/uz/README.md +455 -0
- package/docs/vi/README.md +455 -0
- package/docs/xh/README.md +455 -0
- package/docs/yi/README.md +455 -0
- package/docs/yo/README.md +455 -0
- package/docs/zh/README.md +455 -0
- package/docs/zu/README.md +455 -0
- package/drivers/b2/index.js +24 -6
- package/hokey.json +16 -0
- package/index.js +7 -2
- package/package.json +1 -1
- package/test/api.spec.js +12 -9
- package/util/redis.js +1 -1
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
móvil
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
Mobiletto es una capa de abstracción de almacenamiento de JavaScript, con cifrado transparente opcional del lado del cliente.
|
|
5
|
+
|
|
6
|
+
# Contenidos
|
|
7
|
+
* [¿Por qué Mobiletto?](#¿Por qué-Mobiletto?)
|
|
8
|
+
* [Inicio rápido](#Inicio rápido)
|
|
9
|
+
* [CLI de Mobiletto](#mobiletto-cli)
|
|
10
|
+
* [Fuente](#Fuente)
|
|
11
|
+
* [Uso básico](#Uso-básico)
|
|
12
|
+
* [Metadatos](#Metadatos)
|
|
13
|
+
* [Estilo de importación alternativo](#Estilo de importación alternativo)
|
|
14
|
+
* [Almacenamiento en caché](#Almacenamiento en caché)
|
|
15
|
+
* [Reflejo](#Reflejo)
|
|
16
|
+
* [Cifrado transparente](#Cifrado-transparente)
|
|
17
|
+
* [Rotación de clave](#Rotación de clave)
|
|
18
|
+
* [Interfaz del controlador](#Interfaz del controlador)
|
|
19
|
+
* [Registro](#Registro)
|
|
20
|
+
|
|
21
|
+
# Leer esto en otro idioma
|
|
22
|
+
Este documento README.md ha sido traducido, a través de [hokeylization](https://github.com/cobbzilla/hokeylization), a
|
|
23
|
+
**[¡todos los idiomas admitidos por Google Translate](https://cloud.google.com/translate/docs/languages)!**
|
|
24
|
+
|
|
25
|
+
Estoy seguro de que no es perfecto, ¡pero espero que sea mejor que nada!
|
|
26
|
+
|
|
27
|
+
[🇸🇦 Árabe](../ar/README.md)
|
|
28
|
+
[🇧🇩 bengalí](../bn/README.md)
|
|
29
|
+
[🇩🇪 Alemán](../de/README.md)
|
|
30
|
+
[🇺🇸 Español](../es/README.md)
|
|
31
|
+
[🇪🇸 Español](../es/README.md)
|
|
32
|
+
[🇫🇷 Francés](../fr/README.md)
|
|
33
|
+
[🇹🇩 Hausa](../ha/README.md)
|
|
34
|
+
[🇮🇳 hindi](../hi/README.md)
|
|
35
|
+
[🇮🇩 Indonesio](../id/README.md)
|
|
36
|
+
[🇮🇹 Italiano](../it/README.md)
|
|
37
|
+
[🇯🇵 Japonés](../ja/README.md)
|
|
38
|
+
[🇰🇷 Coreano](../ko/README.md)
|
|
39
|
+
[🇮🇳 Maranthi](../mr/README.md)
|
|
40
|
+
[🇵🇱 Polaco](../pl/README.md)
|
|
41
|
+
[🇧🇷 Portugués](../pt/README.md)
|
|
42
|
+
[🇷🇺 Ruso](../ru/README.md)
|
|
43
|
+
[🇰🇪 Suajili](../sw/README.md)
|
|
44
|
+
[🇵🇭 Tagalo](../tl/README.md)
|
|
45
|
+
[🇹🇷 Turco](../tr/README.md)
|
|
46
|
+
[🇵🇰 Urdu](../ur/README.md)
|
|
47
|
+
[🇻🇳 Vietnamita](../vi/README.md)
|
|
48
|
+
[🇨🇳 Chino](../zh/README.md)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
**[📚 ... Todos los idiomas ...](../README.md)**
|
|
52
|
+
----
|
|
53
|
+
|
|
54
|
+
### ¿Hay algún problema con esta traducción del LÉAME?
|
|
55
|
+
Esta traducción particular del [README] original (https://github.com/cobbzilla/mobiletto/blob/master/README.md)
|
|
56
|
+
puede tener fallas -- * ¡las correcciones son muy bienvenidas! * Envíe una [solicitud de extracción en GitHub](https://github.com/cobbzilla/mobiletto/pulls),
|
|
57
|
+
o si no se siente cómodo haciéndolo, [abra un problema](https://github.com/cobbzilla/mobiletto/issues)
|
|
58
|
+
|
|
59
|
+
Cuando cree un nuevo problema de GitHub sobre una traducción, haga lo siguiente:
|
|
60
|
+
* incluir la URL de la página (copiar/pegar desde la barra de direcciones del navegador)
|
|
61
|
+
* incluir el texto exacto que está mal (copiar/pegar desde el navegador)
|
|
62
|
+
* por favor describa lo que está mal -- ¿la traducción es incorrecta? ¿El formato está roto de alguna manera?
|
|
63
|
+
* ofrezca amablemente una sugerencia de una mejor traducción, o cómo el texto debe formatearse correctamente
|
|
64
|
+
* **¡Gracias!**
|
|
65
|
+
|
|
66
|
+
## ¿Por qué Mobiletto?
|
|
67
|
+
|
|
68
|
+
### ¡Adiós al bloqueo de proveedores!
|
|
69
|
+
Los diversos proveedores de almacenamiento en la nube tienen API incompatibles. Incluso aquellos que luchan por la "compatibilidad con S3"
|
|
70
|
+
tienen comportamientos idiosincrásicos.
|
|
71
|
+
|
|
72
|
+
Cuando elige un proveedor de almacenamiento en particular para su aplicación, si codifica directamente a su API, su aplicación
|
|
73
|
+
ahora depende de ese servicio. A medida que pasa el tiempo y se acumula el código, cambiar de proveedor se vuelve
|
|
74
|
+
cada vez más insostenible. ¡Bienvenido al divertido mundo del bloqueo de proveedores!
|
|
75
|
+
|
|
76
|
+
Mobiletto fue diseñado para resolver este problema. Al codificar su aplicación para la API de mobiletto, puede fácilmente
|
|
77
|
+
cambie los proveedores de almacenamiento y sepa que la capa de almacenamiento de su aplicación se comportará de manera idéntica.
|
|
78
|
+
|
|
79
|
+
### Pruebas exhaustivas
|
|
80
|
+
Todos los controladores se someten a pruebas de comportamiento idéntico con más de 60 pruebas para cada controlador.
|
|
81
|
+
Probamos todos los controladores con cada combinación de:
|
|
82
|
+
* Cifrado: tanto habilitado como deshabilitado
|
|
83
|
+
* Caché Redis: tanto habilitado como deshabilitado
|
|
84
|
+
|
|
85
|
+
Este enfoque nos da la tranquilidad de que mobiletto se comportará igual independientemente del controlador que utilice,
|
|
86
|
+
e independientemente de si habilita el almacenamiento en caché y/o el cifrado.
|
|
87
|
+
|
|
88
|
+
### Compatibilidad con el controlador
|
|
89
|
+
Controladores de almacenamiento Mobiletto actuales:
|
|
90
|
+
* `s3` : Amazon S3
|
|
91
|
+
* `b2` : Backblaze B2
|
|
92
|
+
* `local` : sistema de archivos local
|
|
93
|
+
|
|
94
|
+
*¡Las contribuciones para apoyar a más proveedores de almacenamiento en la nube son muy bienvenidas!*
|
|
95
|
+
|
|
96
|
+
## mobiletto-cli
|
|
97
|
+
Mobiletto está destinado a ser utilizado como biblioteca por otro código JavaScript.
|
|
98
|
+
|
|
99
|
+
Para trabajar con mobiletto en la línea de comandos, use [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli)
|
|
100
|
+
|
|
101
|
+
## Fuente
|
|
102
|
+
* [mobiletto en GitHub](https://github.com/cobbzilla/mobiletto)
|
|
103
|
+
* [mobiletto en npm](https://www.npmjs.com/package/mobiletto)
|
|
104
|
+
|
|
105
|
+
## Inicio rápido
|
|
106
|
+
Un breve ejemplo usando el controlador mobiletto `s3` .
|
|
107
|
+
|
|
108
|
+
Este código se ejecutaría igual si el controlador fuera `b2` o `local` .
|
|
109
|
+
|
|
110
|
+
const storage = require('mobiletto')
|
|
111
|
+
const bucket = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk'})
|
|
112
|
+
|
|
113
|
+
// list objects: returns array of metadata objects
|
|
114
|
+
const listing = await bucket.list()
|
|
115
|
+
const dirList = await bucket.list('some/dir/')
|
|
116
|
+
const everything = await bucket.list('', {recursive: true})
|
|
117
|
+
|
|
118
|
+
// write an entire file
|
|
119
|
+
let bytesWritten = await bucket.writeFile('some/path', someBufferOfData)
|
|
120
|
+
|
|
121
|
+
// write a file from a stream/generator
|
|
122
|
+
bytesWritten = await bucket.write('some/path', streamOrGenerator)
|
|
123
|
+
|
|
124
|
+
// read an entire file
|
|
125
|
+
// returns null if an exception would otherwise be thrown
|
|
126
|
+
const bufferOrNull = await bucket.safeReadFile('some/path')
|
|
127
|
+
|
|
128
|
+
// stream-read a file, passing data to callback
|
|
129
|
+
const bytesRead = await bucket.read('some/path', (chunk) => { ...do something with chunk... } )
|
|
130
|
+
|
|
131
|
+
// remove a file, returns the path removed
|
|
132
|
+
let removed = await bucket.remove('some/path') // removed is a string
|
|
133
|
+
|
|
134
|
+
// remove a directory, returns array of paths removed
|
|
135
|
+
removed = await bucket.remove('some/directory', {recursive: true}) // removed is now an array!
|
|
136
|
+
|
|
137
|
+
----
|
|
138
|
+
## Uso básico
|
|
139
|
+
Un ejemplo mucho más extenso, que muestra la mayoría de las características ofrecidas:
|
|
140
|
+
|
|
141
|
+
const { mobiletto } = require('mobiletto')
|
|
142
|
+
|
|
143
|
+
// General usage
|
|
144
|
+
const api = await mobiletto(driverName, key, secret, opts)
|
|
145
|
+
|
|
146
|
+
// To use 'local' driver:
|
|
147
|
+
// * key: base directory
|
|
148
|
+
// * secret: ignored, can be null
|
|
149
|
+
// * opts object:
|
|
150
|
+
// * readOnly: optional, never change anything on the filesystem; default is false
|
|
151
|
+
// * fileMode: optional, permissions used when creating new files, default is 0600. can be string or integer
|
|
152
|
+
// * dirMode: optional, permissions used when creating new directories, default is 0700. can be string or integer
|
|
153
|
+
const local = await mobiletto('local', '/home/ubuntu/tmp', null, {fileMode: 0o0600, dirMode: '0700'})
|
|
154
|
+
|
|
155
|
+
// To use 's3' driver:
|
|
156
|
+
// * key: AWS Access Key ID
|
|
157
|
+
// * secret: AWS Secret Key
|
|
158
|
+
// * opts object:
|
|
159
|
+
// * readOnly: optional, never change anything on the bucket; default is false
|
|
160
|
+
// * bucket: required, name of the S3 bucket
|
|
161
|
+
// * region: optional, the AWS region to communicate with, default is us-east-1
|
|
162
|
+
// * prefix: optional, all read/writes within the S3 bucket will be under this prefix
|
|
163
|
+
// * delimiter: optional, directory delimiter, default is '/' (note: always '/' when encryption is enabled)
|
|
164
|
+
const s3 = await mobiletto('s3', aws_key, aws_secret, {bucket: 'bk', region: 'us-east-1'})
|
|
165
|
+
|
|
166
|
+
// To use 'b2' driver:
|
|
167
|
+
// * key: Backblaze Key ID
|
|
168
|
+
// * secret: Backblaze Application Key
|
|
169
|
+
// * opts object:
|
|
170
|
+
// * readOnly: optional, never change anything on the bucket; default is false
|
|
171
|
+
// * bucket: required, the ID (**not the name**) of the B2 bucket
|
|
172
|
+
// * prefix: optional, all read/writes within the B2 bucket will be under this prefix
|
|
173
|
+
// * delimiter: optional, directory delimiter, default is '/' (note: always '/' when encryption is enabled)
|
|
174
|
+
// * partSize: optional, large files will be split into chunks of this size when uploading
|
|
175
|
+
const b3 = await mobiletto('b2', b2_key_id, b2_app_key, {bucket: 'bk', partSize: 10000000})
|
|
176
|
+
|
|
177
|
+
// List files
|
|
178
|
+
api.list() // --> returns an array of metadata objects
|
|
179
|
+
|
|
180
|
+
// List files recursively
|
|
181
|
+
api.list({ recursive: true })
|
|
182
|
+
|
|
183
|
+
// List files in a directory
|
|
184
|
+
const path = 'some/path'
|
|
185
|
+
api.list(path)
|
|
186
|
+
api.list(path, { recursive: true }) // also supports recursive flag
|
|
187
|
+
|
|
188
|
+
// Visit files in a directory -- visitor function must be async
|
|
189
|
+
api.list(path, { visitor: myAsyncFunc })
|
|
190
|
+
api.list(path, { visitor: myAsyncFunc, recursive: true })
|
|
191
|
+
|
|
192
|
+
// The `list` method throws MobilettoNotFoundError if the path does not exist
|
|
193
|
+
// When you call `safeList` on a non-existent path, it returns an empty array
|
|
194
|
+
api.safeList('/path/that/does/not/exist') // returns []
|
|
195
|
+
|
|
196
|
+
// Read metadata for a file
|
|
197
|
+
api.metadata(path) // returns metadata object
|
|
198
|
+
|
|
199
|
+
// The `metadata` method throws MobilettoNotFoundError if the path does not exist
|
|
200
|
+
// When you call `safeMetadata` on a non-existent path, it returns null
|
|
201
|
+
api.safeMetadata('/tmp/does_not_exist') // returns null
|
|
202
|
+
|
|
203
|
+
// Read a file
|
|
204
|
+
// Provide a callback that writes the data someplace
|
|
205
|
+
const callback = (chunk) => { ... write chunk somewhere ... }
|
|
206
|
+
api.read(path, callback) // returns count of bytes read
|
|
207
|
+
|
|
208
|
+
// Read an entire file at once
|
|
209
|
+
const data = await api.readFile(path) // returns a byte Buffer of the file contents
|
|
210
|
+
|
|
211
|
+
// Read an entire file at once
|
|
212
|
+
// returns null if an exception would otherwise be thrown
|
|
213
|
+
const bufferOrNull = await bucket.safeReadFile('some/path')
|
|
214
|
+
|
|
215
|
+
// Write a file
|
|
216
|
+
// Provide a generator function that yields chunks of data
|
|
217
|
+
const generator = function* () {
|
|
218
|
+
while ( ... more-data-to-return ... ) {
|
|
219
|
+
data = ... load-data ...
|
|
220
|
+
yield data
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
local.api(path, generator) // returns count of bytes written
|
|
224
|
+
|
|
225
|
+
// Write an entire file at once (convenience method)
|
|
226
|
+
await api.writeFile(path, bufferOrString) // returns count of bytes written
|
|
227
|
+
|
|
228
|
+
// Delete a file
|
|
229
|
+
// Quiet param is optional (default false), when set errors will not be thrown if the path does not exist
|
|
230
|
+
// Always returns a value or throws an error.
|
|
231
|
+
// Return value may be a single string of the file removed, or an array of all files removed (driver-dependent)
|
|
232
|
+
const quiet = true
|
|
233
|
+
api.remove(path, {quiet}) // returns single path removed
|
|
234
|
+
|
|
235
|
+
// Recursively delete a directory and do it quietly (do not report errors)
|
|
236
|
+
const recursive = true
|
|
237
|
+
const quiet = true
|
|
238
|
+
api.remove(path, {recursive, quiet}) // returns array of paths removed
|
|
239
|
+
|
|
240
|
+
## Metadatos
|
|
241
|
+
El comando `metadata` devuelve metadatos sobre una sola entrada del sistema de archivos.
|
|
242
|
+
Del mismo modo, el valor de retorno del comando `list` es una matriz de objetos de metadatos.
|
|
243
|
+
|
|
244
|
+
Un objeto de metadatos se ve así:
|
|
245
|
+
|
|
246
|
+
{
|
|
247
|
+
"name": "fully/qualified/path/to/file",
|
|
248
|
+
"type": "entry-type",
|
|
249
|
+
"size": size-in-bytes,
|
|
250
|
+
"ctime": creation-time-epoch-millis,
|
|
251
|
+
"mtime": modification-time-epoch-millis
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
La propiedad `type` puede ser `file` , `dir` , `link` o `special` .
|
|
255
|
+
|
|
256
|
+
Según el tipo de controlador, es posible que un comando `list` no devuelva todos los campos. Las `name` y `type`
|
|
257
|
+
siempre debe estar presente. Un comando posterior de `metadata` devolverá todas las propiedades disponibles.
|
|
258
|
+
|
|
259
|
+
## Estilo de importación alternativo
|
|
260
|
+
Importe el módulo de alcance completo y use la función `connect` :
|
|
261
|
+
|
|
262
|
+
const storage = require('mobiletto')
|
|
263
|
+
const opts = {bucket: 'bk', region: 'us-east-1'}
|
|
264
|
+
const s3 = await storage.connect('s3', aws_key, aws_secret, opts)
|
|
265
|
+
const objectData = await s3.readFile('some/path')
|
|
266
|
+
|
|
267
|
+
## Almacenamiento en caché
|
|
268
|
+
Mobiletto funciona mejor con un caché <a href="https://redis.io">redis</a> .
|
|
269
|
+
|
|
270
|
+
Mobiletto intentará conectarse a una instancia de redis en 127.0.0.1:6379
|
|
271
|
+
|
|
272
|
+
Puede anular cualquiera de estos:
|
|
273
|
+
* Configure la variable de `MOBILETTO_REDIS_HOST` , mobilet para conectarse aquí en lugar de localhost
|
|
274
|
+
* Establecer el env var `MOBILETTO_REDIS_PORT` , se utilizará este puerto
|
|
275
|
+
|
|
276
|
+
Mobiletto almacenará todas sus claves redis con el prefijo `_mobiletto__` . Puedes cambiar esto
|
|
277
|
+
configurando la variable de entorno `MOBILETTO_REDIS_PREFIX` .
|
|
278
|
+
|
|
279
|
+
También puede configurar el almacenamiento en caché por conexión con el objeto `opts.redisConfig` :
|
|
280
|
+
|
|
281
|
+
const redisConfig = {
|
|
282
|
+
enabled: true, // optional, default is true. if false other props are ignored
|
|
283
|
+
host: '127.0.0.1',
|
|
284
|
+
port: 6379,
|
|
285
|
+
prefix: '_mobiletto__'
|
|
286
|
+
}
|
|
287
|
+
const opts = { redisConfig, bucket: 'bk', region: 'us-east-1' }
|
|
288
|
+
const s3 = await storage.connect('s3', aws_key, aws_secret, opts)
|
|
289
|
+
|
|
290
|
+
### ¿No quieres el almacenamiento en caché de redis?
|
|
291
|
+
Para deshabilitar: pase `enabled: false` en su objeto `opts.redisConfig` cuando establezca su conexión.
|
|
292
|
+
|
|
293
|
+
Como se explica a continuación, deshabilitar el almacenamiento en caché tendrá un efecto adverso en el rendimiento e incurrirá en más solicitudes.
|
|
294
|
+
al almacenamiento que realmente necesita.
|
|
295
|
+
|
|
296
|
+
### Guía de almacenamiento en caché
|
|
297
|
+
**Almacenamiento cifrado**: la lectura/escritura del almacenamiento cifrado es solo un poco más lenta de lo normal,
|
|
298
|
+
pero navegar por los directorios (que es lo que hacen algunas cosas) es bastante costoso. Usando un caché redis
|
|
299
|
+
le dará un impulso de rendimiento significativo.
|
|
300
|
+
|
|
301
|
+
El caché predeterminado es seguro, pero no funciona bien si tiene muchas operaciones de escritura/eliminación.
|
|
302
|
+
Cualquier operación de escritura o eliminación invalida toda la memoria caché, lo que garantiza que las lecturas posteriores verán el
|
|
303
|
+
Últimos cambios.
|
|
304
|
+
|
|
305
|
+
### herramientas CLI
|
|
306
|
+
Si está utilizando una herramienta CLI como [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli),
|
|
307
|
+
definitivamente querrá que el caché redis esté habilitado, ya que dura a través de las invocaciones del comando `mo` .
|
|
308
|
+
|
|
309
|
+
## Reflejo
|
|
310
|
+
|
|
311
|
+
// Copy a local filesystem mobiletto to S3
|
|
312
|
+
s3.mirror(local)
|
|
313
|
+
|
|
314
|
+
// Mirror a local subdirectory from one mobiletto to an S3 mobiletto, with it's own subdirectory
|
|
315
|
+
local.mirror(s3, 'some/local-folder', 'some/s3-folder')
|
|
316
|
+
|
|
317
|
+
El comando `mirror` realiza una copia única de todos los archivos de un móvil a otro.
|
|
318
|
+
No ejecuta ningún proceso para mantener el espejo a lo largo del tiempo. Ejecute el comando `mirror` nuevamente
|
|
319
|
+
para sincronizar los archivos que faltan.
|
|
320
|
+
|
|
321
|
+
El valor de retorno de `mirror` es un objeto simple con contadores de cuántos archivos fueron exitosos
|
|
322
|
+
reflejado y cuántos archivos tenían errores:
|
|
323
|
+
|
|
324
|
+
{
|
|
325
|
+
success: count-of-files-mirrored,
|
|
326
|
+
errors: count-of-files-with-errors
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
ADVERTENCIA: Duplicar grandes conjuntos de datos puede llevar mucho tiempo y un uso intensivo del ancho de banda
|
|
330
|
+
|
|
331
|
+
Con la semántica de la llamada `mirror` , a veces puede ser confuso entender quién es el
|
|
332
|
+
lector y quién es el escritor. Imagínelo como una declaración de asignación: el "mobiletto de la mano izquierda"
|
|
333
|
+
es la cosa a la que se asigna (datos reflejados escritos), y el "mobiletto de la mano derecha" (el
|
|
334
|
+
argumento del método `mirror` ) es el valor que se asigna (se leen los datos reflejados).
|
|
335
|
+
|
|
336
|
+
## Cifrado transparente
|
|
337
|
+
Habilite el cifrado transparente del lado del cliente:
|
|
338
|
+
|
|
339
|
+
// Pass encryption parameters
|
|
340
|
+
const encryption = {
|
|
341
|
+
// key is required, must be >= 16 chars
|
|
342
|
+
key: randomstring.generate(128),
|
|
343
|
+
|
|
344
|
+
// optional, the default is to derive IV from key
|
|
345
|
+
// when set, IV must be >= 16 chars
|
|
346
|
+
iv: randomstring.generate(128),
|
|
347
|
+
|
|
348
|
+
// optional, the default is aes-256-cbc
|
|
349
|
+
algo: 'aes-256-cbc'
|
|
350
|
+
}
|
|
351
|
+
const api = await mobiletto(driverName, key, secret, opts, encryption)
|
|
352
|
+
|
|
353
|
+
// Subsequent write operations will encrypt data (client side) when writing
|
|
354
|
+
// Subsequent read operations will decrypt data (client side) when reading
|
|
355
|
+
|
|
356
|
+
¿Qué esta pasando? Un directorio separado de "entrada de directorio" (dirent) (encriptado) rastrea qué archivos hay en ese
|
|
357
|
+
directorio (también conocido como el directorio dirent).
|
|
358
|
+
* El comando `list` lee los archivos de entrada del directorio, descifra cada ruta listada; luego devuelve metadatos para cada archivo
|
|
359
|
+
* Los comandos `list` son más ineficientes, especialmente para directorios con una gran cantidad de archivos
|
|
360
|
+
* El comando `write` escribe archivos diferentes en el directorio principal de cada padre, recursivamente; luego escribe el archivo
|
|
361
|
+
* Los comandos `write` incurrirán en O(N) escrituras, con N = profundidad en la jerarquía de directorios
|
|
362
|
+
* El comando `remove` elimina el archivo de directorio correspondiente, y su padre si está vacío, recursivamente; luego elimina el archivo
|
|
363
|
+
* Los comandos `remove` no recursivos generarán O(N) lecturas y potencialmente tantas eliminaciones, con N = profundidad en la jerarquía de directorios
|
|
364
|
+
* Los comandos `remove` en sistemas de archivos grandes y profundos pueden ser costosos
|
|
365
|
+
|
|
366
|
+
Tenga en cuenta que incluso con el cifrado del lado del cliente habilitado, un adversario con visibilidad completa de su lado del servidor cifrado
|
|
367
|
+
almacenamiento, incluso sin la clave, aún puede ver el número total de directorios y cuántos archivos hay en cada uno, y con
|
|
368
|
+
algún esfuerzo, descubra parte o la totalidad de la estructura general de la jerarquía de directorios.
|
|
369
|
+
*Nota: Use una estructura relativamente plana para mayor seguridad.*
|
|
370
|
+
El adversario no sabría los nombres de los directorios/archivos a menos que también supiera su encriptación
|
|
371
|
+
clave o de otro modo había descifrado con éxito el cifrado. ¡Todas las apuestas están canceladas entonces!
|
|
372
|
+
|
|
373
|
+
### Rendimiento y almacenamiento en caché
|
|
374
|
+
Las operaciones en el almacenamiento cifrado pueden ser lentas. Las listas recursivas y las eliminaciones pueden ser muy lentas.
|
|
375
|
+
El almacenamiento en caché a través de redis es de gran ayuda, pero tenga en cuenta que el caché se vacía con cualquier escritura o eliminación.
|
|
376
|
+
|
|
377
|
+
## Rotación de claves
|
|
378
|
+
Cree un mobiletto con su nueva clave, luego refleje los datos antiguos en él:
|
|
379
|
+
|
|
380
|
+
const storage = require('mobiletto')
|
|
381
|
+
|
|
382
|
+
const oldEncryption = { key: .... }
|
|
383
|
+
const oldStorage = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk', region: 'us-east-1'}, oldEncryption)
|
|
384
|
+
|
|
385
|
+
const newEncryption = { key: .... }
|
|
386
|
+
const newStorage = await storage.connect('s3', aws_key, aws_secret, {bucket: 'zz', region: 'us-east-1'}, newEncryption)
|
|
387
|
+
|
|
388
|
+
newStorage.mirror(oldStorage) // if oldStorage is very large, this may take a looooooong time...
|
|
389
|
+
|
|
390
|
+
## Interfaz del controlador
|
|
391
|
+
Un controlador es cualquier archivo JS que exporta una función 'storageClient' con esta firma:
|
|
392
|
+
|
|
393
|
+
function storageClient (key, secret, opts)
|
|
394
|
+
|
|
395
|
+
* `key` : una cadena, su clave API (para el controlador `local` este es el directorio base)
|
|
396
|
+
* `secret` : una cadena, su secreto de API (se puede omitir para el controlador `local` )
|
|
397
|
+
* `opts` : un objeto, las propiedades son por controlador:
|
|
398
|
+
* Para `local` , las `fileMode` y `dirMode` determinan cómo se crean los nuevos archivos y directorios.
|
|
399
|
+
* Para `s3` , se requiere la propiedad `bucket` . Las propiedades opcionales son:
|
|
400
|
+
* `region`: the S3 region, default is us-east-1
|
|
401
|
+
* `prefix`: a prefix to prepend to all S3 paths, default is the empty string
|
|
402
|
+
* `delimiter`: the directory delimiter, default is '/'
|
|
403
|
+
|
|
404
|
+
El objeto que devuelve la función storageClient debe definir estas funciones:
|
|
405
|
+
|
|
406
|
+
// Test the driver before using, ensure proper configuration
|
|
407
|
+
async testConfig ()
|
|
408
|
+
|
|
409
|
+
// List files in path (or from base-directory)
|
|
410
|
+
// If recursive is true, list recursively
|
|
411
|
+
// If visitor is defined, it will be an async function. await the visitor function on each file found
|
|
412
|
+
// Otherwise, perform the listing and return an array of objects
|
|
413
|
+
async list (path, recursive = false, visitor = null) // path may be omitted
|
|
414
|
+
|
|
415
|
+
// Read metadata for a path
|
|
416
|
+
async metadata (path)
|
|
417
|
+
|
|
418
|
+
// Read a file
|
|
419
|
+
// callback receives a chunk of data. endCallback is called at end-of-stream
|
|
420
|
+
async read (path, callback, endCallback = null)
|
|
421
|
+
|
|
422
|
+
// Write a file
|
|
423
|
+
// driver must be able to handle a generator or a stream
|
|
424
|
+
async write (path, generatorOrReadableStream)
|
|
425
|
+
|
|
426
|
+
// Remove a file, or recursively delete a directory
|
|
427
|
+
// returns a string of a single path removed, or an array of multiple paths removed
|
|
428
|
+
async remove (path, recursive = false, quiet = false)
|
|
429
|
+
|
|
430
|
+
## Inicio sesión
|
|
431
|
+
Mobiletto usa la biblioteca de registro [winston](https://www.npmjs.com/package/winston).
|
|
432
|
+
|
|
433
|
+
Los registros **contendrán** rutas de archivos y mensajes de error, pero **nunca** contendrán claves, secretos,
|
|
434
|
+
o cualquier otra información de configuración de conexión.
|
|
435
|
+
|
|
436
|
+
### Nivel de registro
|
|
437
|
+
Use la variable de entorno `MOBILETTO_LOG_LEVEL` para establecer el nivel de registro, usando uno
|
|
438
|
+
de los niveles `npm` definidos en [https://www.npmjs.com/package/winston#logging-levels](https://www.npmjs.com/package/winston#logging-levels)
|
|
439
|
+
|
|
440
|
+
El nivel predeterminado es `error` . El nivel más detallado es `silly` , aunque actualmente mobiletto
|
|
441
|
+
no inicia sesión en niveles por debajo `debug`
|
|
442
|
+
|
|
443
|
+
MOBILETTO_LOG_LEVEL=silly # maximum logs!
|
|
444
|
+
|
|
445
|
+
### Archivo de registro
|
|
446
|
+
De forma predeterminada, el registrador escribe en la consola. Para enviar registros a un archivo, configure `MOBILETTO_LOG_FILE`
|
|
447
|
+
Variable ambiental. Al iniciar sesión en un archivo, los registros ya no se escribirán en la consola.
|
|
448
|
+
|
|
449
|
+
MOBILETTO_LOG_FILE=/var/my_mobiletto_log
|
|
450
|
+
|
|
451
|
+
Para desactivar el registro:
|
|
452
|
+
|
|
453
|
+
MOBILETTO_LOG_FILE=/dev/null
|
|
454
|
+
|
|
455
|
+
</pre>
|