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
|
+
Mobiletto
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
Mobiletto è un livello di astrazione dello storage JavaScript, con crittografia lato client trasparente opzionale.
|
|
5
|
+
|
|
6
|
+
# Contenuti
|
|
7
|
+
* [Perché Mobiletto?](#Perché-Mobiletto?)
|
|
8
|
+
* [Avvio rapido](#Avvio rapido)
|
|
9
|
+
* [CLI Mobiletto](#mobiletto-cli)
|
|
10
|
+
* [Fonte](#Fonte)
|
|
11
|
+
* [Utilizzo di base](#Utilizzo di base)
|
|
12
|
+
* [Metadati](#Metadati)
|
|
13
|
+
* [Stile di importazione alternativo](#Stile di importazione alternativo)
|
|
14
|
+
* [Memorizzazione nella cache](#Memorizzazione nella cache)
|
|
15
|
+
* [Mirroring](#Mirroring)
|
|
16
|
+
* [Crittografia trasparente](#Crittografia trasparente)
|
|
17
|
+
* [Rotazione chiave](#Rotazione chiave)
|
|
18
|
+
* [Interfaccia del driver](#Interfaccia del driver)
|
|
19
|
+
* [Registrazione](#Registrazione)
|
|
20
|
+
|
|
21
|
+
# Leggi questo in un'altra lingua
|
|
22
|
+
Questo documento README.md è stato tradotto, tramite [hokeylization](https://github.com/cobbzilla/hokeylization), in
|
|
23
|
+
**[ogni lingua supportata da Google Translate](https://cloud.google.com/translate/docs/languages)!**
|
|
24
|
+
|
|
25
|
+
Sono certa che non sia perfetto, ma spero sia meglio di niente!
|
|
26
|
+
|
|
27
|
+
[🇸🇦 Arabo](../ar/README.md)
|
|
28
|
+
[🇧🇩 Bengali](../bn/README.md)
|
|
29
|
+
[🇩🇪 Tedesco](../de/README.md)
|
|
30
|
+
[🇺🇸 Inglese](../en/README.md)
|
|
31
|
+
[🇪🇸 Spagnolo](../es/README.md)
|
|
32
|
+
[🇫🇷 Francese](../fr/README.md)
|
|
33
|
+
[🇹🇩 Hausa](../ha/README.md)
|
|
34
|
+
[🇮🇳 Hindi](../hi/README.md)
|
|
35
|
+
[🇮🇩 Indonesiano](../id/README.md)
|
|
36
|
+
[🇮🇹 Italiano](../it/README.md)
|
|
37
|
+
[🇯🇵 Giapponese](../ja/README.md)
|
|
38
|
+
[🇰🇷 Coreano](../ko/README.md)
|
|
39
|
+
[🇮🇳 Maranthi](../mr/README.md)
|
|
40
|
+
[🇵🇱 Polacco](../pl/README.md)
|
|
41
|
+
[🇧🇷 Portoghese](../pt/README.md)
|
|
42
|
+
[🇷🇺 Russo](../ru/README.md)
|
|
43
|
+
[🇰🇪 Swahili](../sw/README.md)
|
|
44
|
+
[🇵🇭 Tagalog](../tl/README.md)
|
|
45
|
+
[🇹🇷 Turco](../tr/README.md)
|
|
46
|
+
[🇵🇰 Urdu](../ur/README.md)
|
|
47
|
+
[🇻🇳 Vietnamita](../vi/README.md)
|
|
48
|
+
[🇨🇳 Cinese](../zh/README.md)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
**[📚 ... Tutte le lingue ...](../README.md)**
|
|
52
|
+
----
|
|
53
|
+
|
|
54
|
+
### C'è un problema con questa traduzione del README?
|
|
55
|
+
Questa particolare traduzione dell'originale [README](https://github.com/cobbzilla/mobiletto/blob/master/README.md)
|
|
56
|
+
potrebbe essere difettoso -- *le correzioni sono molto gradite!* Si prega di inviare una [richiesta pull su GitHub](https://github.com/cobbzilla/mobiletto/pulls),
|
|
57
|
+
o se non ti senti a tuo agio nel farlo, [apri un problema](https://github.com/cobbzilla/mobiletto/issues)
|
|
58
|
+
|
|
59
|
+
Quando crei un nuovo problema GitHub su una traduzione, esegui:
|
|
60
|
+
* includi l'URL della pagina (copia/incolla dalla barra degli indirizzi del browser)
|
|
61
|
+
* includi il testo esatto che è sbagliato (copia/incolla dal browser)
|
|
62
|
+
* per favore descrivi cosa c'è che non va -- la traduzione è errata? la formattazione è rotta in qualche modo?
|
|
63
|
+
* offrire gentilmente un suggerimento per una traduzione migliore o come formattare correttamente il testo
|
|
64
|
+
* **Grazie!**
|
|
65
|
+
|
|
66
|
+
## Perché Mobiletto?
|
|
67
|
+
|
|
68
|
+
### Addio blocco del venditore!
|
|
69
|
+
I vari provider di archiviazione cloud hanno API incompatibili. Anche quelli che lottano per la "compatibilità S3"
|
|
70
|
+
avere comportamenti idiosincratici.
|
|
71
|
+
|
|
72
|
+
Quando scegli un particolare fornitore di storage per la tua app, se codifichi direttamente la sua API, la tua app
|
|
73
|
+
ora dipende da quel servizio. Col passare del tempo e il codice si accumula, cambiano i fornitori
|
|
74
|
+
sempre più insostenibile. Benvenuto nel divertente mondo del blocco dei fornitori!
|
|
75
|
+
|
|
76
|
+
Mobiletto è stato progettato per risolvere questo problema. Codificando la tua app sull'API di mobiletto, puoi facilmente
|
|
77
|
+
cambia provider di archiviazione e sappi che il livello di archiviazione della tua app si comporterà in modo identico.
|
|
78
|
+
|
|
79
|
+
### Test approfonditi
|
|
80
|
+
Tutti i driver vengono testati per il comportamento identico con oltre 60 test per ciascun pilota.
|
|
81
|
+
Testiamo tutti i driver con ogni combinazione di:
|
|
82
|
+
* Crittografia: sia abilitata che disabilitata
|
|
83
|
+
* Cache Redis: sia abilitato che disabilitato
|
|
84
|
+
|
|
85
|
+
Questo approccio ci dà la tranquillità che mobiletto si comporterà allo stesso modo indipendentemente dal driver utilizzato,
|
|
86
|
+
e indipendentemente dal fatto che tu abiliti la memorizzazione nella cache e/o la crittografia.
|
|
87
|
+
|
|
88
|
+
### Supporto per i driver
|
|
89
|
+
Driver di archiviazione Mobiletto attuali:
|
|
90
|
+
* `s3` : Amazon S3
|
|
91
|
+
* `b2` : Backblaze B2
|
|
92
|
+
* `local` : filesystem locale
|
|
93
|
+
|
|
94
|
+
*I contributi per supportare più fornitori di servizi di archiviazione cloud sono molto graditi!*
|
|
95
|
+
|
|
96
|
+
## mobiletto-cli
|
|
97
|
+
Mobiletto è concepito per essere utilizzato come libreria da altro codice JavaScript.
|
|
98
|
+
|
|
99
|
+
Per lavorare con mobiletto dalla riga di comando, usa [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli)
|
|
100
|
+
|
|
101
|
+
## Fonte
|
|
102
|
+
* [mobiletto su GitHub](https://github.com/cobbzilla/mobiletto)
|
|
103
|
+
* [mobiletto su npm](https://www.npmjs.com/package/mobiletto)
|
|
104
|
+
|
|
105
|
+
## Avvio veloce
|
|
106
|
+
Un breve esempio usando il driver mobiletto `s3` .
|
|
107
|
+
|
|
108
|
+
Questo codice funzionerebbe allo stesso modo se il driver fosse `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
|
+
## Utilizzo di base
|
|
139
|
+
Un esempio molto più ampio, che mostra la maggior parte delle funzionalità offerte:
|
|
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
|
+
## Metadati
|
|
241
|
+
Il comando `metadata` restituisce i metadati su una singola voce del filesystem.
|
|
242
|
+
Allo stesso modo, il valore restituito dal comando `list` è un array di oggetti di metadati.
|
|
243
|
+
|
|
244
|
+
Un oggetto di metadati ha il seguente aspetto:
|
|
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 proprietà `type` type` può essere `file` , `dir` , `link` o `special` .
|
|
255
|
+
|
|
256
|
+
A seconda del tipo di driver, un comando `list` potrebbe non restituire tutti i campi. Le proprietà `name` e `type`
|
|
257
|
+
dovrebbe essere sempre presente. Un successivo comando `metadata` restituirà tutte le proprietà disponibili.
|
|
258
|
+
|
|
259
|
+
## Stile di importazione alternativo
|
|
260
|
+
Importa il modulo con ambito completo e usa la funzione `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
|
+
## Memorizzazione nella cache
|
|
268
|
+
Mobiletto funziona meglio con una cache <a href="https://redis.io">redis</a> .
|
|
269
|
+
|
|
270
|
+
Mobiletto tenterà di connettersi a un'istanza redis su 127.0.0.1:6379
|
|
271
|
+
|
|
272
|
+
Puoi sovrascrivere uno di questi:
|
|
273
|
+
* Impostare `MOBILETTO_REDIS_HOST` env var, mobiletto connect qui invece di localhost
|
|
274
|
+
* Imposta la `MOBILETTO_REDIS_PORT` env var, questa porta verrà utilizzata
|
|
275
|
+
|
|
276
|
+
Mobiletto memorizzerà tutte le sue chiavi redis con il prefisso `_mobiletto__` . Puoi cambiarlo
|
|
277
|
+
impostando il `MOBILETTO_REDIS_PREFIX` env var.
|
|
278
|
+
|
|
279
|
+
Puoi anche impostare la memorizzazione nella cache per connessione con l'oggetto `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
|
+
### Non vuoi redis memorizzare nella cache?
|
|
291
|
+
Per disabilitare: passa `enabled: false` nel tuo oggetto `opts.redisConfig` quando stabilisci la connessione.
|
|
292
|
+
|
|
293
|
+
Come discusso di seguito, la disabilitazione della memorizzazione nella cache avrà un effetto negativo sulle prestazioni e comporterà più richieste
|
|
294
|
+
allo spazio di archiviazione di cui hai davvero bisogno.
|
|
295
|
+
|
|
296
|
+
### Guida alla memorizzazione nella cache
|
|
297
|
+
**Archiviazione crittografata**: la lettura/scrittura dello spazio di archiviazione crittografato è solo leggermente più lenta del normale,
|
|
298
|
+
ma navigare nelle directory (cosa che fanno alcune cose) è piuttosto costoso. Utilizzo di una cache redis
|
|
299
|
+
ti darà un notevole aumento delle prestazioni.
|
|
300
|
+
|
|
301
|
+
La cache predefinita è sicura, ma non funziona bene se hai molte operazioni di scrittura/rimozione.
|
|
302
|
+
Qualsiasi operazione di scrittura o rimozione invalida l'intera cache, assicurando che le letture successive vedranno il file
|
|
303
|
+
ultime modifiche.
|
|
304
|
+
|
|
305
|
+
### Strumenti dell'interfaccia a riga di comando
|
|
306
|
+
Se stai utilizzando uno strumento CLI come [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli),
|
|
307
|
+
vorrai sicuramente abilitare la cache redis, poiché dura durante le invocazioni del comando `mo` .
|
|
308
|
+
|
|
309
|
+
## Specchio
|
|
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
|
+
Il comando `mirror` esegue una copia unica di tutti i file da un mobiletto all'altro.
|
|
318
|
+
Non esegue alcun processo per mantenere lo specchio nel tempo. Esegui di nuovo il comando `mirror`
|
|
319
|
+
per sincronizzare eventuali file mancanti.
|
|
320
|
+
|
|
321
|
+
Il valore restituito da `mirror` è un semplice oggetto con contatori di quanti file sono stati eseguiti correttamente
|
|
322
|
+
con mirroring e quanti file hanno avuto errori:
|
|
323
|
+
|
|
324
|
+
{
|
|
325
|
+
success: count-of-files-mirrored,
|
|
326
|
+
errors: count-of-files-with-errors
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
AVVISO: il mirroring di set di dati di grandi dimensioni può richiedere molto tempo e la larghezza di banda
|
|
330
|
+
|
|
331
|
+
Con la semantica della chiamata `mirror` a volte può essere fonte di confusione capire chi è il
|
|
332
|
+
lettore e chi è lo scrittore. Immaginalo come una dichiarazione di assegnazione: il "mobiletto di sinistra"
|
|
333
|
+
è la cosa a cui si assegna (scrittura dei dati speculari), e il "mobiletto di destra" (il
|
|
334
|
+
argomento del metodo `mirror` ) è il valore assegnato (i dati speculari vengono letti).
|
|
335
|
+
|
|
336
|
+
## Crittografia trasparente
|
|
337
|
+
Abilita la crittografia lato client trasparente:
|
|
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
|
+
Cosa sta succedendo? Una directory separata "voce di directory" (direct) (crittografata) tiene traccia dei file in essa contenuti
|
|
357
|
+
directory (ovvero la directory diretta).
|
|
358
|
+
* Il comando `list` legge i file di ingresso della directory, decrittografa ogni percorso elencato; quindi restituisce i metadati per ogni file
|
|
359
|
+
* I comandi `list` sono più inefficienti, specialmente per le directory con un gran numero di file
|
|
360
|
+
* Il comando `write` scrive i file diretti nella directory diretta di ciascun genitore, in modo ricorsivo; quindi scrive il file
|
|
361
|
+
* I comandi `write` comporteranno O(N) scritture, con N = profondità nella gerarchia delle directory
|
|
362
|
+
* Il comando `remove` rimuove il file diretto corrispondente e il suo genitore, se vuoto, in modo ricorsivo; quindi rimuove il file
|
|
363
|
+
* I comandi `remove` non ricorsivi comporteranno O(N) letture e potenzialmente altrettante eliminazioni, con N = profondità nella gerarchia delle directory
|
|
364
|
+
* I comandi ricorsivi `remove` su filesystem grandi e profondi possono essere costosi
|
|
365
|
+
|
|
366
|
+
Tieni presente che anche con la crittografia lato client abilitata, un avversario con piena visibilità sul lato server crittografato
|
|
367
|
+
l'archiviazione, anche senza la chiave, può ancora vedere il numero totale di directory e quanti file ci sono in ciascuna e con
|
|
368
|
+
qualche sforzo, scoprire parte o tutta la struttura generale della gerarchia di directory.
|
|
369
|
+
*Nota: utilizzare una struttura relativamente piatta per una maggiore sicurezza.*
|
|
370
|
+
L'avversario non conoscerebbe i nomi delle directory/file a meno che non conoscesse anche la tua crittografia
|
|
371
|
+
chiave o altrimenti ha violato con successo la crittografia. Allora tutte le scommesse sono finite!
|
|
372
|
+
|
|
373
|
+
### Prestazioni e memorizzazione nella cache
|
|
374
|
+
Le operazioni sull'archiviazione crittografata possono essere lente. Le inserzioni e le rimozioni ricorsive possono essere molto lente.
|
|
375
|
+
La memorizzazione nella cache tramite redis aiuta enormemente, ma tieni presente che la cache viene svuotata in caso di scrittura o rimozione.
|
|
376
|
+
|
|
377
|
+
## Rotazione chiave
|
|
378
|
+
Crea un mobiletto con la tua nuova chiave, quindi rispecchia i vecchi dati al suo interno:
|
|
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
|
+
## Interfaccia del driver
|
|
391
|
+
Un driver è qualsiasi file JS che esporta una funzione 'storageClient' con questa firma:
|
|
392
|
+
|
|
393
|
+
function storageClient (key, secret, opts)
|
|
394
|
+
|
|
395
|
+
* `key` : una stringa, la tua chiave API (per il driver `local` questa è la directory di base)
|
|
396
|
+
* `secret` : una stringa, il tuo segreto API (può essere omesso per il driver `local` )
|
|
397
|
+
* `opts` : un oggetto, le proprietà sono per driver:
|
|
398
|
+
* Per `local` , le `fileMode` e `dirMode` determinano come vengono creati i nuovi file e directory di creazione
|
|
399
|
+
* Per `s3` è richiesta la proprietà `bucket` . Le proprietà opzionali sono:
|
|
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
|
+
L'oggetto restituito dalla funzione storageClient deve definire queste funzioni:
|
|
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
|
+
## Registrazione
|
|
431
|
+
Mobiletto utilizza la libreria di registrazione [winston](https://www.npmjs.com/package/winston).
|
|
432
|
+
|
|
433
|
+
I registri **conterranno** percorsi di file e messaggi di errore, ma **non conterranno mai** chiavi, segreti,
|
|
434
|
+
o qualsiasi altra informazione sulla configurazione della connessione.
|
|
435
|
+
|
|
436
|
+
### Livello di registro
|
|
437
|
+
Usa la variabile d'ambiente `MOBILETTO_LOG_LEVEL` per impostare il livello di log, usandone uno
|
|
438
|
+
dei livelli `npm` definiti in [https://www.npmjs.com/package/winston#logging-levels](https://www.npmjs.com/package/winston#logging-levels)
|
|
439
|
+
|
|
440
|
+
Il livello predefinito è `error` . Il livello più dettagliato è `silly` , sebbene attualmente mobiletto
|
|
441
|
+
non registra a livelli inferiori a `debug`
|
|
442
|
+
|
|
443
|
+
MOBILETTO_LOG_LEVEL=silly # maximum logs!
|
|
444
|
+
|
|
445
|
+
### File di registro
|
|
446
|
+
Per impostazione predefinita, il logger scrive sulla console. Per inviare i log a un file, impostare il `MOBILETTO_LOG_FILE`
|
|
447
|
+
variabile d'ambiente. Quando si accede a un file, i registri non verranno più scritti nella console.
|
|
448
|
+
|
|
449
|
+
MOBILETTO_LOG_FILE=/var/my_mobiletto_log
|
|
450
|
+
|
|
451
|
+
Per disattivare la registrazione:
|
|
452
|
+
|
|
453
|
+
MOBILETTO_LOG_FILE=/dev/null
|
|
454
|
+
|
|
455
|
+
</pre>
|