Thanks to visit codestin.com
Credit goes to github.com

Skip to content

This repository contains a sample project demonstrating how to use the Skyflow Node SDK within a Cloudflare Worker. The project includes functionality for deidentifying sensitive information in files and text, as well as uploading files to a Skyflow vault.

Notifications You must be signed in to change notification settings

SkyflowFoundry/sdk-cloudflare-worker-samples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare Worker Sample Project

This repository contains a sample project demonstrating how to use the Skyflow Node SDK within a Cloudflare Worker. The project includes functionality for deidentifying sensitive information in files and text, as well as uploading files to a Skyflow vault.

Table of Contents

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js (version 14 or later)
  • Skyflow account with access to the Skyflow Node SDK

Installation

  1. Clone the repository:

    git clone https://github.com/SkyflowFoundry/cloudflare_worker_samples.git
    cd cloudflare_worker_samples
  2. Install the dependencies:

    npm install

Create the vault

  1. In a browser, navigate to Skyflow Studio.
  2. Create a vault by clicking Add Vault > Start With a Template > Quickstart vault.
  3. Once the vault is created, click the gear icon and select Vault Details.
  4. Note your Vault URL and Vault ID values. You'll need these later.

Create a service account

  1. In the side navigation click, Access > Service Accounts > Add Service Account.
  2. For Name, enter "SDK Samples". For Roles, choose Vault Editor.
  3. Click Create. Your browser downloads a credentials.json file. Keep this file secure. You'll need it for each of the samples.

Configuration

  1. Add your environment variables in the wrangler.jsonc file under the env section. These will store your VAULT_ID, CLUSTER_ID and CREDENTIALS. For example:
{
   "name": "cloudflare-worker-sample", // Environment-specific configurations
   "env": {
      "dev": { // Development environment configuration
         "vars": {
            "VAULT_ID": "<VAULT_ID>", // Replace with your actual Skyflow Vault ID for development
            "CLUSTER_ID": "<CLUSTER_ID>", // Replace with your actual Skyflow Cluster ID (e.g., "us1", "in1", etc.)
            "CREDENTIALS": {} // Replace with your development service account credentials JSON object
         }
      },
      "prod": { // Production environment configuration
         "vars": {
            "VAULT_ID": "<VAULT_ID>", // Replace with your actual Skyflow Vault ID for production
            "CLUSTER_ID": "<CLUSTER_ID>", // Replace with your actual Skyflow Cluster ID
            "CREDENTIALS": {} // Replace with your production service account credentials JSON object
      }
    }
   }
}
  1. Open the index.ts file located in the src directory.
  2. Vault configuration initialisation:
   const credentials: Credentials = {
      credentialsString: JSON.stringify(env.CREDENTIALS), // Update the CREDENTIALS env variable in wrangler.jsonc
   };
   // Configure Vault 
   const primaryVaultConfig: VaultConfig = {
      vaultId: env.VAULT_ID,          // update the VAULT_ID env variable in wrangler.jsonc
      clusterId: env.CLUSTER_ID,      // update the CLUSTER_ID env variable in wrangler.jsonc
      env: Env.DEV,                   // Deployment environment
      credentials: credentials        // Authentication method
   };

Running the Project

To run the Cloudflare Worker locally, follow these steps:

  1. Install the Cloudflare Workers CLI (Wrangler):

    npm install -g wrangler
  2. You can test the worker locally using:

    npm run dev

API Endpoints

The following API endpoints are available in the Cloudflare Worker:

  • POST /saveFile: Uploads a file to the Skyflow vault.

    • Request body: FormData containing the file.
  • POST /detectFile: Deidentifies sensitive information in a file.

    • Request body: FormData containing the file.
  • POST /detectText: Deidentifies sensitive information in text.

    • Request body: FormData containing the text.

Samples

Resources

About

This repository contains a sample project demonstrating how to use the Skyflow Node SDK within a Cloudflare Worker. The project includes functionality for deidentifying sensitive information in files and text, as well as uploading files to a Skyflow vault.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •