Skip to content

Commit df447a4

Browse files
authored
docs: update readme (#31)
1 parent b1d73dc commit df447a4

File tree

1 file changed

+53
-33
lines changed

1 file changed

+53
-33
lines changed

README.md

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,52 @@
1-
# parse-server-fs-adapter
2-
<a href="https://www.npmjs.com/package/@parse/fs-files-adapter"><img alt="npm version" src="https://img.shields.io/npm/v/@parse/fs-files-adapter.svg?style=flat"></a>
3-
[![codecov.io](https://codecov.io/github/parse-community/parse-server-fs-adapter/coverage.svg?branch=master)](https://codecov.io/github/parse-community/parse-server-fs-adapter?branch=master)
4-
<a href="https://github.com/parse-community/parse-server-fs-adapter/actions?query=workflow%3Aci+branch%3Amain">
5-
<img alt="Build status" src="https://github.com/parse-community/parse-server-fs-adapter/workflows/ci/badge.svg?branch=main">
6-
</a>
1+
# Parse Server FS Adapter <!-- omit in toc -->
72

8-
parse-server file system storage adapter.
3+
[![Build Status](https://github.com/parse-community/parse-server-fs-adapter/workflows/ci/badge.svg?branch=main)](https://github.com/parse-community/parse-server-fs-adapter/actions?query=workflow%3Aci+branch%3Amain)
4+
[![Snyk Badge](https://snyk.io/test/github/parse-community/parse-server-fs-adapter/badge.svg)](https://snyk.io/test/github/parse-community/parse-server-fs-adapter)
5+
[![Coverage](https://img.shields.io/codecov/c/github/parse-community/parse-server-fs-adapter/main.svg)](https://codecov.io/github/parse-community/parse-server-fs-adapter?branch=main)
6+
[![auto-release](https://img.shields.io/badge/%F0%9F%9A%80-auto--release-9e34eb.svg)](https://github.com/parse-community/parse-server-fs-adapter/releases)
97

8+
[![npm latest version](https://img.shields.io/npm/v/@parse/fs-files-adapter.svg)](https://www.npmjs.com/package/@parse/fs-files-adapter)
109

11-
# Multiple instances of parse-server
12-
When using parse-server-fs-adapter across multiple parse-server instances it's important to establish "centralization" of your file storage (this is the same premise as the other file adapters, you are sending/recieving files through a dedicated link). You can accomplish this at the file storage level by Samba mounting (or any other type of mounting) your storage to each of your parse-server instances, e.g if you are using parse-server via docker (volume mount your SMB drive to `- /Volumes/SMB-Drive/MyParseApp1/files:/parse-server/files`). All parse-server instances need to be able to read and write to the same storage in order for parse-server-fs-adapter to work properly with parse-server. If the file storage isn't centralized, parse-server will have trouble locating files and you will get random behavior on client-side.
10+
---
11+
12+
The Parse Server File System Storage Adapter.
13+
14+
---
15+
16+
- [Installation](#installation)
17+
- [Configuration](#configuration)
18+
- [Parse Server Config](#parse-server-config)
19+
- [In-Code Instance](#in-code-instance)
20+
- [Rotating Encryption Key](#rotating-encryption-key)
21+
- [Encrypting Previously Unencrypted Files](#encrypting-previously-unencrypted-files)
22+
- [Encrypting Previously Encrypted Files](#encrypting-previously-encrypted-files)
23+
- [Other Considerations](#other-considerations)
1324

1425
# Installation
1526

1627
`npm install --save @parse/fs-files-adapter`
1728

18-
# Usage with parse-server
29+
# Configuration
1930

20-
### Using a config file
31+
## Parse Server Config
2132

2233
```javascript
2334
{
2435
"appId": 'my_app_id',
2536
"masterKey": 'my_master_key',
2637
// other options
38+
// ...
2739
"filesAdapter": {
2840
"module": "@parse/fs-files-adapter",
2941
"options": {
30-
"filesSubDirectory": "my/files/folder", // optional, defaults to ./files
31-
"encryptionKey": "someKey" //optional, but mandatory if you want to encrypt files
42+
"filesSubDirectory": "my/files/folder", // Optional, defaults to `./files`
43+
"encryptionKey": "someKey" // Optional, but mandatory if you want to encrypt files
3244
}
3345
}
3446
}
3547
```
3648

37-
### Passing as an instance
49+
## In-Code Instance
3850

3951
```javascript
4052
var FSFilesAdapter = require('@parse/fs-files-adapter');
@@ -51,48 +63,56 @@ var api = new ParseServer({
5163
})
5264
```
5365

54-
### Rotating to a new encryptionKey
55-
Periodically you may want to rotate your encryptionKey for security reasons. When this is the case, you can start up a development parse-server that has the same configuration as your production server. In the development server, initialize the file adapter with the new key and do the following in your `index.js`:
66+
## Rotating Encryption Key
67+
68+
Periodically you may want to rotate your encryptionKey for security reasons. When this is the case, you can start up a development parse-server that has the same configuration as your production server. In the development server, initialize the file adapter with the new key and use the examples below.
69+
70+
Note that the examples below to rotate keys are are not optimized for performance. Is it therefore not recommended to rotate a large number of files using the code below in a production environment; instead use dedicated resources for that.
71+
72+
### Encrypting Previously Unencrypted Files
5673

57-
#### Files were previously unencrypted and you want to encrypt
5874
```javascript
5975
var FSFilesAdapter = require('@parse/fs-files-adapter');
6076

6177
var fsAdapter = new FSFilesAdapter({
62-
"filesSubDirectory": "my/files/folder", // optional, defaults to ./files
63-
"encryptionKey": "newKey" //Use the newKey
78+
"filesSubDirectory": "my/files/folder", // Optional, defaults to `./files`
79+
"encryptionKey": "newKey" // Use the new key
6480
});
6581

6682
var api = new ParseServer({
6783
appId: 'my_app',
6884
masterKey: 'master_key',
6985
filesAdapter: fsAdapter
70-
})
86+
});
7187

72-
//This can take awhile depending on how many files and how larger they are. It will attempt to rotate the key of all files in your filesSubDirectory
73-
//It is not recommended to do this on the production server, deploy a development server to complete the process.
74-
const {rotated, notRotated} = await api.filesAdapter.rotateEncryptionKey();
88+
const { rotated, notRotated } = await api.filesAdapter.rotateEncryptionKey();
7589
console.log('Files rotated to newKey: ' + rotated);
76-
console.log('Files that couldn't be rotated to newKey: ' + notRotated);
90+
console.log('Files that couldn\'t be rotated to newKey: ' + notRotated);
7791
```
7892

7993
After successfully rotating your key, you should change the `encryptionKey` to `newKey` on your production server and then restart the server.
8094

8195

82-
#### Files were previously encrypted with `oldKey` and you want to encrypt with `newKey`
83-
The same process as above, but pass in your `oldKey` to `rotateEncryptionKey()`.
96+
### Encrypting Previously Encrypted Files
97+
98+
To encrypt files with a new key that were previously encrypted with a different key, the same process applies as above, but you pass in your `oldKey` to `rotateEncryptionKey()`.
99+
84100
```javascript
85-
//This can take awhile depending on how many files and how larger they are. It will attempt to rotate the key of all files in your filesSubDirectory
86101
const {rotated, notRotated} = await api.filesAdapter.rotateEncryptionKey({oldKey: oldKey});
87102
console.log('Files rotated to newKey: ' + rotated);
88-
console.log('Files that couldn't be rotated to newKey: ' + notRotated);
103+
console.log('Files that couldn\'t be rotated to newKey: ' + notRotated);
89104
```
90105

91-
#### Only rotate a select list of files that were previously encrypted with `oldKey` and you want to encrypt with `newKey`
92-
This is useful if for some reason there errors and some of the files werent rotated and returned in `notRotated`. The same process as above, but pass in your `oldKey` along with the array of `fileNames` to `rotateEncryptionKey()`.
106+
You can also only rotate a select list of files that were previously encrypted with `oldKey` and you want to encrypt with `newKey`. This is useful if for some reason there errors and some of the files werent rotated and returned in `notRotated`. The same process as above, but pass in your `oldKey` along with the array of `fileNames` to `rotateEncryptionKey()`.
107+
93108
```javascript
94-
//This can take awhile depending on how many files and how larger they are. It will attempt to rotate the key of all files in your filesSubDirectory
95-
const {rotated, notRotated} = await api.filesAdapter.rotateEncryptionKey({oldKey: oldKey, fileNames: ["fileName1.png","fileName2.png"]});
109+
const { rotated, notRotated } = await api.filesAdapter.rotateEncryptionKey({ oldKey: oldKey, fileNames: ["fileName1.png","fileName2.png"] });
96110
console.log('Files rotated to newKey: ' + rotated);
97-
console.log('Files that couldn't be rotated to newKey: ' + notRotated);
111+
console.log('Files that couldn\'t be rotated to newKey: ' + notRotated);
98112
```
113+
114+
# Other Considerations
115+
116+
- Multiple Instances of Parse Server
117+
118+
When using the adapter across multiple Parse Server instances it's important to establish "centralization" of your file storage (this is the same premise as the other file adapters, you are sending/receiving files through a dedicated link). You can accomplish this at the file storage level by Samba mounting (or any other type of mounting) your storage to each of your parse-server instances, e.g if you are using parse-server via docker (volume mount your SMB drive to `- /Volumes/SMB-Drive/MyParseApp1/files:/parse-server/files`). All parse-server instances need to be able to read and write to the same storage in order for parse-server-fs-adapter to work properly with parse-server. If the file storage isn't centralized, parse-server will have trouble locating files and you will get random behavior on client-side.

0 commit comments

Comments
 (0)