Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branch 'release/1.0.0-rc.3' #11

Merged
merged 2 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
28 changes: 18 additions & 10 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,27 @@ <h3> </h3>
<a href="./.github/workflows/ci.yml"><img src="https://github.com/msudgh/sync-cloud-storage/actions/workflows/ci.yml/badge.svg?branch=main" alt="Pipeline Status"></a>
<a href="https://codecov.io/gh/msudgh/sync-cloud-storage"><img src="https://codecov.io/gh/msudgh/sync-cloud-storage/branch/main/graph/badge.svg?token=2BY6063VOY" alt="Codecov Status"></a>
<a href="LICENSE"><img src="https://img.shields.io/github/license/msudgh/sync-cloud-storage" alt="License"></a></p>
<p>A simple way to sync folders &amp; files between a remote machine and a cloud provider's framework.</p>
<p>A simple way to sync folders &amp; files between a remote machine and a cloud provider's storage.</p>
<p>Available for following cloud frameworks:</p>
<ul>
<li><a href="https://serverless.com/">Serverless</a></li>
</ul>
<blockquote>
<p><strong>Note</strong>: This plugin is still in development and may not be stable. Use with caution.</p>
</blockquote>
<h2>Installation</h2>
<pre class="prettyprint source lang-bash"><code>npm install --save sync-cloud-storage
</code></pre>
<ol>
<li><a href="https://github.com/antfu/ni"><strong>ni</strong></a>: <code>ni sync-cloud-storage -D</code></li>
<li><a href="https://npmjs.com/"><strong>npm</strong></a>: <code>npm i sync-cloud-storage -D</code></li>
<li><a href="https://yarnpkg.com/"><strong>yarn</strong></a>: <code>yarn add sync-cloud-storage -D</code></li>
<li><a href="https://pnpm.io/"><strong>pnpm</strong></a>: <code>pnpm add sync-cloud-storage -D</code></li>
</ol>
<h2>Why</h2>
<ul>
<li>Uses the latest official cloud provider's SDK.</li>
<li>Sync multiple storages at once.</li>
<li>Sync tags and metadata of each storage.</li>
</ul>
<h2>Usage</h2>
<h3>Serverless</h3>
<pre class="prettyprint source lang-yaml"><code>plugins:
Expand All @@ -73,11 +86,6 @@ <h3>Serverless</h3>
metadata:
foo: bar
bar: foo
</code></pre>
<h2>Deployments</h2>
<h3><a href="https://github.com/common-fate/granted">Granted</a> (assume)</h3>
<p>By using the <code>assume</code> command, you can grant access to the plugin to deploy to your cloud framework.</p>
<pre class="prettyprint source lang-bash"><code>assume
</code></pre></article>
</section>

Expand All @@ -95,10 +103,10 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
</html>
16 changes: 2 additions & 14 deletions docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,11 @@ <h1 class="page-title">Source: index.js</h1>
* @param {Object} logging - Serverless logging module
*/
constructor(serverless, options, logging) {
if (!serverless) {
throw new Error('Serverless instance is required');
}
// Typing with *as* makes testing enable to use a DI version of instance
this.serverless = serverless;
this.servicePath = this.serverless.service.serverless.config.servicePath;
if (!options) {
throw new Error("Options can't be undefined");
}
this.options = options;
if (!logging) {
throw new Error("Logging can't be undefined");
}
this.logging = logging;
this.servicePath = this.serverless.service.serverless.config.servicePath;
const config = this.serverless.service.custom;
const validatedConfig = input_1.custom.safeParse(config);
const { success } = validatedConfig;
Expand Down Expand Up @@ -193,9 +184,6 @@ <h1 class="page-title">Source: index.js</h1>
* await this.onExit()
*/
async onExit() {
if (this.taskProcess) {
this.taskProcess.remove();
}
if (this.client) {
this.client.destroy();
}
Expand Down Expand Up @@ -226,7 +214,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions docs/module-SyncCloudStorage-SyncCloudStorage.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions docs/module-SyncCloudStorage.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion docs/providers_local_objects.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
7 changes: 6 additions & 1 deletion docs/providers_s3_buckets.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ <h1 class="page-title">Source: providers/s3/buckets.js</h1>
*/
const syncTags = async (client, storage) => {
logger_1.default.info("Syncing storage's tags", { storage: storage.name });
const { name } = storage;
const storageExist = await (0, exports.storageExists)(client, name);
if (!storageExist) {
return { error: new Error('StorageNotFound') };
}
let existingTagSet = { TagSet: [] };
try {
try {
Expand Down Expand Up @@ -231,7 +236,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/providers_s3_credentials.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
82 changes: 35 additions & 47 deletions docs/providers_s3_objects.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ <h1 class="page-title">Source: providers/s3/objects.js</h1>
const uploadedObjects = [];
for (const checksum of filesToUpload) {
const fileToUpload = localFiles.find((file) => (0, objects_1.getChecksum)(file.Key, file.ETag) === checksum);
if (!fileToUpload) {
continue;
}
logger_1.default.info('Upload file to bucket', {
storage: storage.name,
key: fileToUpload.Key,
Expand Down Expand Up @@ -113,57 +110,48 @@ <h1 class="page-title">Source: providers/s3/objects.js</h1>
* @param {_Object[]} objects
* @returns {Promise&lt;DeletedObject[]>}
*/
const deleteObjects = async (client, storage, objects, retry = 0) => {
const deleteObjects = async (client, storage, objects) => {
const keys = [...objects].map((object) => object.Key);
logger_1.default.info('Delete following objects from bucket', {
storage: storage.name,
keys,
});
try {
const versions = await client.send(new client_s3_1.ListObjectVersionsCommand({
const versions = await client.send(new client_s3_1.ListObjectVersionsCommand({
Bucket: storage.name,
Prefix: storage.prefix ? storage.prefix : undefined,
}));
const deleteMarkers = (versions.DeleteMarkers ?? []).map((marker) => ({
Key: marker.Key,
VersionId: marker.VersionId,
}));
const versionsToDelete = (versions.Versions ?? []).map((version) => ({
Key: version.Key,
VersionId: version.VersionId,
}));
const objectsToDelete = [
...objects.map((object) => ({
Key: object.Key,
VersionId: object.ETag,
})),
...deleteMarkers,
...versionsToDelete,
];
if (objectsToDelete.length > 0) {
const { Deleted: deleted = [] } = await client.send(new client_s3_1.DeleteObjectsCommand({
Bucket: storage.name,
Prefix: storage.prefix ? storage.prefix : undefined,
MaxKeys: 1000000000,
}));
const deleteMarkers = (versions.DeleteMarkers ?? []).map((marker) => ({
Key: marker.Key,
VersionId: marker.VersionId,
}));
const versionsToDelete = (versions.Versions ?? []).map((version) => ({
Key: version.Key,
VersionId: version.VersionId,
Delete: {
Objects: objectsToDelete,
Quiet: false,
},
}));
const objectsToDelete = [
...objects.map((object) => ({
Key: object.Key,
VersionId: object.ETag,
})),
...deleteMarkers,
...versionsToDelete,
];
if (objectsToDelete.length > 0) {
const { Deleted: deleted = [] } = await client.send(new client_s3_1.DeleteObjectsCommand({
Bucket: storage.name,
Delete: {
Objects: objectsToDelete,
Quiet: false,
},
}));
logger_1.default.info(`Permanently deleted all versions of object.`, {
storage: storage.name,
});
return deleted;
}
else {
logger_1.default.info(`No objects to delete.`, { storage: storage.name });
return [];
}
logger_1.default.info(`Permanently deleted all versions of object.`, {
storage: storage.name,
});
return deleted;
}
catch (error) {
if (retry >= 3) {
throw error;
}
return (0, exports.deleteObjects)(client, storage, objects, retry + 1);
else {
logger_1.default.info(`No objects to delete.`, { storage: storage.name });
return [];
}
};
exports.deleteObjects = deleteObjects;
Expand All @@ -183,7 +171,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
26 changes: 12 additions & 14 deletions docs/utils_objects.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,18 @@ <h1 class="page-title">Source: utils/objects.js</h1>
const extractAfterSubdirectory = (fullPath, subdirectory) => {
// Normalize both paths to ensure consistent separators
const normalizedFullPath = path_1.default.normalize(fullPath);
const normalizedSubdirectory = path_1.default.normalize(subdirectory);
const normalizedLocalPath = path_1.default.normalize(subdirectory);
// Find the start index of the subdirectory in the full path
const startIndex = normalizedFullPath.indexOf(normalizedSubdirectory);
if (startIndex !== -1) {
// Calculate the end index of the subdirectory within the full path
const endIndex = startIndex + normalizedSubdirectory.length + 1;
// Extract the part of the full path after the subdirectory
const afterSubdirectory = normalizedFullPath.substring(endIndex);
// Normalize the extracted path to clean up any leading separators
return path_1.default.normalize(afterSubdirectory);
}
else {
return ''; // Subdirectory not found in the full path
}
const startIndex = normalizedFullPath.indexOf(normalizedLocalPath);
// Assuming subdirectory is always part of fullPath, calculate the end index
const endIndex = startIndex + normalizedLocalPath.length;
// Extract the part of the full path after the subdirectory
// Check if endIndex is at the path's end or adjust for separator
const afterSubdirectory = endIndex >= normalizedFullPath.length
? ''
: normalizedFullPath.substring(endIndex + 1);
// Return the extracted path part, ensuring no leading separators
return afterSubdirectory ? path_1.default.normalize(afterSubdirectory) : '';
};
exports.extractAfterSubdirectory = extractAfterSubdirectory;
</code></pre>
Expand All @@ -92,7 +90,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/utils_tags.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Sy
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Fri Feb 09 2024 00:49:08 GMT+0100 (Central European Standard Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sat Feb 10 2024 14:54:25 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sync-cloud-storage",
"version": "1.0.0-rc.2",
"version": "1.0.0-rc.3",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down