Skip to content

Commit

Permalink
Merge pull request #235 from privacy-scaling-explorations/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
baumstern authored Nov 2, 2023
2 parents bf3a814 + d49f35f commit bc780c8
Show file tree
Hide file tree
Showing 38 changed files with 432 additions and 364 deletions.
23 changes: 21 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
"no-bitwise": "off",
"no-await-in-loop": "off",
"no-restricted-syntax": "off",
"no-console": ["warn", { "allow": ["info", "warn", "error", "log"] }],
"no-console": [
"warn",
{
"allow": ["info", "warn", "error", "log"]
}
],
"@typescript-eslint/lines-between-class-members": "off",
"no-plusplus": "off",
"@typescript-eslint/no-unused-expressions": "warn",
Expand All @@ -28,5 +33,19 @@
"no-promise-executor-return": "warn",
"prefer-promise-reject-errors": "warn",
"@typescript-eslint/no-shadow": "warn"
}
},
"overrides": [
{
"files": ["packages/actions/src/helpers/utils.ts"],
"rules": {
"no-useless-escape": "off"
}
},
{
"files": ["packages/**/*.test.ts"],
"rules": {
"@typescript-eslint/no-unused-expressions": "off"
}
}
]
}
19 changes: 10 additions & 9 deletions .github/workflows/publish-dev-packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ jobs:
registry-url: "https://registry.npmjs.org"
cache: yarn

- name: Initialize Project
run: |
yarn install
yarn build
env:
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: "false"

- name: Update package.json dependencies and names
run: |
# Enable recursive globbing
Expand All @@ -34,16 +42,9 @@ jobs:
sed -i -e 's/"name": "@p0tion\/backend"/"name": "@devtion\/backend"/g' ./packages/backend/package.json
sed -i -e 's/"name": "@p0tion\/actions"/"name": "@devtion\/actions"/g' ./packages/actions/package.json
# Update string literals in TypeScript files
# Update string literals in TypeScript and JS files
sed -i 's|p0tion/actions|devtion/actions|g' packages/**/*.ts
- name: Initialize Project
run: |
yarn install
yarn build
env:
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: "false"
sed -i 's|p0tion/actions|devtion/actions|g' packages/**/*.js
- name: Install lerna
run: |
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/publish-staging-packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ jobs:
registry-url: "https://registry.npmjs.org"
cache: yarn

- name: Initialize Project
run: |
yarn install
yarn build
env:
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: "false"

- name: Update package.json dependencies and names
run: |
# Enable recursive globbing
Expand All @@ -34,16 +42,9 @@ jobs:
sed -i -e 's/"name": "@p0tion\/backend"/"name": "@stagtion\/backend"/g' ./packages/backend/package.json
sed -i -e 's/"name": "@p0tion\/actions"/"name": "@stagtion\/actions"/g' ./packages/actions/package.json
# Update string literals in TypeScript files
# Update string literals in TypeScript and JS files
sed -i 's|p0tion/actions|stagtion/actions|g' packages/**/*.ts
- name: Initialize Project
run: |
yarn install
yarn build
env:
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: "false"
sed -i 's|p0tion/actions|stagtion/actions|g' packages/**/*.js
- name: Install lerna
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ lerna-debug.log
coverage/

.DS_Store
.idea

.gcloudignore

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ For test execution (e2e/unit) we leverage [Jest](https://jestjs.io/).

#### Local Environment

**Prerequisities**
**Prerequisites**

- Node.js version 16.0 or higher.
- Java JDK version 11 or higher.
Expand All @@ -202,7 +202,7 @@ yarn test

#### Production Environment

**Prerequisities**
**Prerequisites**

- A Firebase Application w/ active billing (Blaze Plan) in order to support Cloud Functions deployment.
- Copy the `packages/actions/.env.default` file as `.env` `cp .env.default .env` and add your environment variables.
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages/*"
],
"npmClient": "yarn",
"version": "1.0.9",
"version": "1.1.0",
"changelogPreset": {
"name": "conventionalcommits",
"issuePrefixes": [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"scripts": {
"build": "yarn workspaces foreach -t run build",
"test": "yarn test:dev",
"test:dev": "NODE_ENV=dev yarn workspace @p0tion/backend emulator:exec-test",
"test:firebase-emulator": "NODE_ENV=dev yarn workspace @p0tion/backend emulator:exec-test",
"test:prod": "yarn workspace @p0tion/actions test:contracts && GOOGLE_APPLICATION_CREDENTIALS=\"./packages/backend/serviceAccountKey.json\" && NODE_ENV=prod jest --config=jest.json --detectOpenHandles --forceExit --runInBand",
"test:ci-prod": "NODE_ENV=prod jest --config=jest.json --detectOpenHandles --forceExit --runInBand",
Expand Down
4 changes: 2 additions & 2 deletions packages/actions/.env.default
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ AWS_SECRET_ACCESS_KEY="YOUR-AWS-SECRET-ACCESS-KEY"
AWS_REGION="YOUR-AWS-REGION"
# The AWS AMI ID (default to Amazon Linux 2).
AWS_AMI_ID="ami-022e1a32d3f742bd8"
# The EC2 instance role to access S3
AWS_ROLE_ARN="YOUR-AWS-ROLE-ARN"
# The IAM instance profile for the EC2 instance to assume
AWS_INSTANCE_PROFILE_ARN="YOUR-AWS-INSTANCE-PROFILE-ARN"

### AUTHENTICATION ###
### These configs are related to the authentication of users.
Expand Down
2 changes: 1 addition & 1 deletion packages/actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ yarn add @p0tion/actions

### Local Development

**Prerequisities**
**Prerequisites**

- Node.js version 16.0 or higher.
- Yarn version 3.5.0 or higher.
Expand Down
2 changes: 1 addition & 1 deletion packages/actions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@p0tion/actions",
"version": "1.0.9",
"version": "1.1.0",
"description": "A set of actions and helpers for CLI commands",
"repository": "[email protected]:privacy-scaling-explorations/p0tion.git",
"homepage": "https://github.com/privacy-scaling-explorations/p0tion",
Expand Down
13 changes: 8 additions & 5 deletions packages/actions/src/helpers/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const getGitHubStats = async (user: string): Promise<any> => {
following: jsonData.following,
followers: jsonData.followers,
publicRepos: jsonData.public_repos,
avatarUrl: jsonData.avatar_url
avatarUrl: jsonData.avatar_url,
age: jsonData.created_at
}

return data
Expand All @@ -38,19 +39,21 @@ export const githubReputation = async (
userLogin: string,
minimumAmountOfFollowing: number,
minimumAmountOfFollowers: number,
minimumAmountOfPublicRepos: number
minimumAmountOfPublicRepos: number,
minimumAge: number
): Promise<any> => {
if (!process.env.GITHUB_ACCESS_TOKEN)
throw new Error(
"The GitHub access token is missing. Please insert a valid token to be used for anti-sybil checks on user registation, and then try again."
)

const { following, followers, publicRepos, avatarUrl } = await getGitHubStats(userLogin)
const { following, followers, publicRepos, avatarUrl, age } = await getGitHubStats(userLogin)

if (
following < minimumAmountOfFollowing ||
publicRepos < minimumAmountOfPublicRepos ||
followers < minimumAmountOfFollowers
followers < minimumAmountOfFollowers ||
new Date(age) > new Date(Date.now() - minimumAge)
)
return {
reputable: false,
Expand All @@ -59,6 +62,6 @@ export const githubReputation = async (

return {
reputable: true,
avatarUrl: avatarUrl
avatarUrl
}
}
4 changes: 2 additions & 2 deletions packages/actions/src/helpers/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getAWSVariables = (): AWSVariables => {
!process.env.AWS_ACCESS_KEY_ID ||
!process.env.AWS_SECRET_ACCESS_KEY ||
!process.env.AWS_REGION ||
!process.env.AWS_ROLE_ARN ||
!process.env.AWS_INSTANCE_PROFILE_ARN ||
!process.env.AWS_AMI_ID
)
throw new Error(
Expand All @@ -44,7 +44,7 @@ export const getAWSVariables = (): AWSVariables => {
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
region: process.env.AWS_REGION || "us-east-1",
roleArn: process.env.AWS_ROLE_ARN!,
instanceProfileArn: process.env.AWS_INSTANCE_PROFILE_ARN!,
amiId: process.env.AWS_AMI_ID!
}
}
Expand Down
18 changes: 15 additions & 3 deletions packages/actions/src/helpers/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import mime from "mime-types"
import fs, { createWriteStream } from "fs"
import fetch from "@adobe/node-fetch-retry"
import https from "https"
import { GenericBar } from "cli-progress"
import { ETagWithPartNumber, ChunkWithUrl, TemporaryParticipantContributionData } from "../types/index"
import { commonTerms } from "./constants"
import {
Expand Down Expand Up @@ -80,18 +81,23 @@ export const getChunksAndPreSignedUrls = async (
* @param cloudFunctions <Functions> - the Firebase Cloud Functions service instance.
* @param ceremonyId <string> - the unique identifier of the ceremony.
* @param alreadyUploadedChunks Array<ETagWithPartNumber> - the temporary information about the already uploaded chunks.
* @param logger <GenericBar> - an optional logger to show progress.
* @returns <Promise<Array<ETagWithPartNumber>>> - the completed (uploaded) chunks information.
*/
export const uploadParts = async (
chunksWithUrls: Array<ChunkWithUrl>,
contentType: string | false,
cloudFunctions?: Functions,
ceremonyId?: string,
alreadyUploadedChunks?: Array<ETagWithPartNumber>
alreadyUploadedChunks?: Array<ETagWithPartNumber>,
logger?: GenericBar
): Promise<Array<ETagWithPartNumber>> => {
// Keep track of uploaded chunks.
const uploadedChunks: Array<ETagWithPartNumber> = alreadyUploadedChunks || []

// if we were passed a logger, start it
if (logger) logger.start(chunksWithUrls.length, 0)

// Loop through remaining chunks.
for (let i = alreadyUploadedChunks ? alreadyUploadedChunks.length : 0; i < chunksWithUrls.length; i += 1) {
// Consume the pre-signed url to upload the chunk.
Expand Down Expand Up @@ -128,6 +134,9 @@ export const uploadParts = async (
// nb. this must be done only when contributing (not finalizing).
if (!!ceremonyId && !!cloudFunctions)
await temporaryStoreCurrentContributionUploadedChunkData(cloudFunctions, ceremonyId, chunk)

// increment the count on the logger
if (logger) logger.increment()
}

return uploadedChunks
Expand All @@ -150,6 +159,7 @@ export const uploadParts = async (
* @param configStreamChunkSize <number> - size of each chunk into which the artifact is going to be splitted (nb. will be converted in MB).
* @param [ceremonyId] <string> - the unique identifier of the ceremony (used as a double-edge sword - as identifier and as a check if current contributor is the coordinator finalizing the ceremony).
* @param [temporaryDataToResumeMultiPartUpload] <TemporaryParticipantContributionData> - the temporary information necessary to resume an already started multi-part upload.
* @param logger <GenericBar> - an optional logger to show progress.
*/
export const multiPartUpload = async (
cloudFunctions: Functions,
Expand All @@ -158,7 +168,8 @@ export const multiPartUpload = async (
localFilePath: string,
configStreamChunkSize: number,
ceremonyId?: string,
temporaryDataToResumeMultiPartUpload?: TemporaryParticipantContributionData
temporaryDataToResumeMultiPartUpload?: TemporaryParticipantContributionData,
logger?: GenericBar
) => {
// The unique identifier of the multi-part upload.
let multiPartUploadId: string = ""
Expand Down Expand Up @@ -198,7 +209,8 @@ export const multiPartUpload = async (
mime.lookup(localFilePath), // content-type.
cloudFunctions,
ceremonyId,
alreadyUploadedChunks
alreadyUploadedChunks,
logger
)

// Step (3).
Expand Down
Loading

0 comments on commit bc780c8

Please sign in to comment.