Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@push.rocks/smarts3
Advanced tools
A Node.js TypeScript package to create a local S3 endpoint for simulating AWS S3 operations using mapped local directories for development and testing purposes.
# @push.rocks/smarts3
A Node.js TypeScript package to create a local S3 endpoint for development and testing using mapped local directories, simulating AWS S3.
## Install
To integrate `@push.rocks/smarts3` with your project, you need to install it via npm. Execute the following command within your project's root directory:
```sh
npm install @push.rocks/smarts3 --save
```
This command will add @push.rocks/smarts3
as a dependency in your project's package.json
file and download the package into the node_modules
directory.
The @push.rocks/smarts3
module allows users to create a mock S3 endpoint that maps to a local directory using s3rver
. This simulation of AWS S3 operations facilitates development and testing by enabling file uploads, bucket creation, and other interactions locally. This local setup is ideal for developers looking to test cloud file storage operations without requiring access to a real AWS S3 instance.
In this comprehensive guide, we will explore setting up a local S3 server, performing operations like creating buckets and uploading files, and how to effectively integrate this into your development workflow.
To begin any operations, your environment must be configured correctly. Here’s a simple setup procedure:
import * as path from 'path';
import { promises as fs } from 'fs';
async function setupEnvironment() {
const packageDir = path.resolve();
const nogitDir = path.join(packageDir, './.nogit');
const bucketsDir = path.join(nogitDir, 'bucketsDir');
try {
await fs.mkdir(bucketsDir, { recursive: true });
} catch (error) {
console.error('Failed to create buckets directory!', error);
throw error;
}
console.log('Environment setup complete.');
}
setupEnvironment().catch(console.error);
This script sets up a directory structure required for the smarts3
server, ensuring that the directories needed for bucket storage exist before starting the server.
Once your environment is set up, start an instance of the smarts3
server. This acts as your local mock S3 endpoint:
import { Smarts3 } from '@push.rocks/smarts3';
async function startServer() {
const smarts3Instance = await Smarts3.createAndStart({
port: 3000,
cleanSlate: true,
});
console.log('S3 server is up and running at http://localhost:3000');
return smarts3Instance;
}
startServer().catch(console.error);
Parameters:
3000
.true
, clears the storage directory each time the server starts, providing a fresh test state.With your server running, create buckets for storing files. A bucket in S3 acts similarly to a root directory.
async function createBucket(smarts3Instance: Smarts3, bucketName: string) {
const bucket = await smarts3Instance.createBucket(bucketName);
console.log(`Bucket created: ${bucket.name}`);
}
startServer()
.then((smarts3Instance) => createBucket(smarts3Instance, 'my-awesome-bucket'))
.catch(console.error);
Uploading files to a bucket uses the SmartBucket
module, part of the @push.rocks/smartbucket
ecosystem:
import { SmartBucket } from '@push.rocks/smartbucket';
async function uploadFile(
smarts3Instance: Smarts3,
bucketName: string,
filePath: string,
fileContent: string,
) {
const s3Descriptor = await smarts3Instance.getS3Descriptor();
const smartbucketInstance = new SmartBucket(s3Descriptor);
const bucket = await smartbucketInstance.getBucket(bucketName);
await bucket.getBaseDirectory().fastStore(filePath, fileContent);
console.log(`File "${filePath}" uploaded successfully to bucket "${bucketName}".`);
}
startServer()
.then(async (smarts3Instance) => {
await createBucket(smarts3Instance, 'my-awesome-bucket');
await uploadFile(smarts3Instance, 'my-awesome-bucket', 'hello.txt', 'Hello, world!');
})
.catch(console.error);
Listing files within a bucket allows you to manage its contents conveniently:
async function listFiles(smarts3Instance: Smarts3, bucketName: string) {
const s3Descriptor = await smarts3Instance.getS3Descriptor();
const smartbucketInstance = new SmartBucket(s3Descriptor);
const bucket = await smartbucketInstance.getBucket(bucketName);
const baseDirectory = await bucket.getBaseDirectory();
const files = await baseDirectory.listFiles();
console.log(`Files in bucket "${bucketName}":`, files);
}
startServer()
.then(async (smarts3Instance) => {
await createBucket(smarts3Instance, 'my-awesome-bucket');
await listFiles(smarts3Instance, 'my-awesome-bucket');
})
.catch(console.error);
Managing storage efficiently involves deleting files when necessary:
async function deleteFile(smarts3Instance: Smarts3, bucketName: string, filePath: string) {
const s3Descriptor = await smarts3Instance.getS3Descriptor();
const smartbucketInstance = new SmartBucket(s3Descriptor);
const bucket = await smartbucketInstance.getBucket(bucketName);
await bucket.getBaseDirectory().fastDelete(filePath);
console.log(`File "${filePath}" deleted from bucket "${bucketName}".`);
}
startServer()
.then(async (smarts3Instance) => {
await createBucket(smarts3Instance, 'my-awesome-bucket');
await deleteFile(smarts3Instance, 'my-awesome-bucket', 'hello.txt');
})
.catch(console.error);
Feature Development: Use @push.rocks/smarts3
to simulate file upload endpoints, ensuring your application handles file operations correctly before going live.
Continuous Integration/Continuous Deployment (CI/CD): Integrate with CI/CD pipelines to automatically test file interactions.
Data Migration Testing: Simulate data migrations between buckets to perfect processes before implementation on actual S3.
Onboarding New Developers: Offer new team members hands-on practice with mock setups to improve their understanding without real-world consequences.
Safely shutting down the server when tasks are complete ensures system resources are managed well:
async function stopServer(smarts3Instance: Smarts3) {
await smarts3Instance.stop();
console.log('S3 server has been stopped.');
}
startServer()
.then(async (smarts3Instance) => {
await createBucket(smarts3Instance, 'my-awesome-bucket');
await stopServer(smarts3Instance);
})
.catch(console.error);
In this guide, we walked through setting up and fully utilizing the @push.rocks/smarts3
package for local development and testing. The package simulates AWS S3 operations, reducing dependency on remote services and allowing efficient development iteration cycles. By implementing the practices and scripts shared here, you can ensure a seamless and productive development experience using the local S3 simulation capabilities of @push.rocks/smarts3
.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
FAQs
A Node.js TypeScript package to create a local S3 endpoint for simulating AWS S3 operations using mapped local directories for development and testing purposes.
The npm package @push.rocks/smarts3 receives a total of 25 weekly downloads. As such, @push.rocks/smarts3 popularity was classified as not popular.
We found that @push.rocks/smarts3 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.