Compare commits

..

4 Commits

Author SHA1 Message Date
standardci c9bf024109 chore(release): publish new version
- @standardnotes/api-gateway@1.87.6
 - @standardnotes/home-server@1.22.10
 - @standardnotes/websockets-server@1.21.3
2023-12-06 15:02:30 +00:00
Karol Sójko 529795d393 fix(api-gateway): add grpc logs for internal errors 2023-12-06 15:42:12 +01:00
Karol Sójko 79ae07623f fix(websockets): change error message on unknown errors 2023-12-05 14:58:48 +01:00
Micah Zoltu 6bdb524489 Adds support for loading environment vars from file. (#938)
* Adds support for loading environment from file.
2023-12-05 12:19:30 +01:00
11 changed files with 91 additions and 7 deletions
+44
View File
@@ -1,5 +1,27 @@
#!/bin/bash
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
# Setup environment variables
export MODE="self-hosted"
@@ -44,10 +66,12 @@ if [ -z "$DB_PORT" ]; then
echo "DB_PORT is not set. Please set it in your .env file."
exit 1
fi
file_env 'DB_USERNAME'
if [ -z "$DB_USERNAME" ]; then
echo "DB_USERNAME is not set. Please set it in your .env file."
exit 1
fi
file_env 'DB_PASSWORD'
if [ -z "$DB_PASSWORD" ]; then
echo "DB_PASSWORD is not set. Please set it in your .env file."
exit 1
@@ -89,11 +113,13 @@ fi
# SHARED #
##########
file_env 'AUTH_JWT_SECRET'
if [ -z "$AUTH_JWT_SECRET" ]; then
echo "AUTH_JWT_SECRET is not set. Please set it in your .env file. You can run 'openssl rand -hex 32' to generate a random string."
exit 1
fi
file_env 'VALET_TOKEN_SECRET'
if [ -z "$VALET_TOKEN_SECRET" ]; then
echo "VALET_TOKEN_SECRET is not set. Please set it in your .env file. You can run 'openssl rand -hex 32' to generate a random string."
exit 1
@@ -120,6 +146,7 @@ if [ -z "$AUTH_SERVER_DISABLE_USER_REGISTRATION" ]; then
export AUTH_SERVER_DISABLE_USER_REGISTRATION=false
fi
file_env 'AUTH_SERVER_PSEUDO_KEY_PARAMS_KEY'
if [ -z "$AUTH_SERVER_PSEUDO_KEY_PARAMS_KEY" ]; then
export AUTH_SERVER_PSEUDO_KEY_PARAMS_KEY=$(openssl rand -hex 32)
fi
@@ -142,6 +169,7 @@ if [ -z "$AUTH_SERVER_EPHEMERAL_SESSION_AGE" ]; then
export AUTH_SERVER_EPHEMERAL_SESSION_AGE=259200
fi
file_env 'AUTH_SERVER_ENCRYPTION_SERVER_KEY'
if [ -z "$AUTH_SERVER_ENCRYPTION_SERVER_KEY" ]; then
echo "AUTH_SERVER_ENCRYPTION_SERVER_KEY is not set. Please set it in your .env file. You can run 'openssl rand -hex 32' to generate a random string."
exit 1
@@ -161,9 +189,11 @@ fi
if [ -z "$AUTH_SERVER_SNS_ENDPOINT" ]; then
export AUTH_SERVER_SNS_ENDPOINT="http://localstack:4566"
fi
file_env 'AUTH_SERVER_SNS_SECRET_ACCESS_KEY'
if [ -z "$AUTH_SERVER_SNS_SECRET_ACCESS_KEY" ]; then
export AUTH_SERVER_SNS_SECRET_ACCESS_KEY="x"
fi
file_env 'AUTH_SERVER_SNS_ACCESS_KEY_ID'
if [ -z "$AUTH_SERVER_SNS_ACCESS_KEY_ID" ]; then
export AUTH_SERVER_SNS_ACCESS_KEY_ID="x"
fi
@@ -176,9 +206,11 @@ fi
if [ -z "$AUTH_SERVER_SQS_AWS_REGION" ]; then
export AUTH_SERVER_SQS_AWS_REGION="us-east-1"
fi
file_env 'AUTH_SERVER_SQS_ACCESS_KEY_ID'
if [ -z "$AUTH_SERVER_SQS_ACCESS_KEY_ID" ]; then
export AUTH_SERVER_SQS_ACCESS_KEY_ID="x"
fi
file_env 'AUTH_SERVER_SQS_SECRET_ACCESS_KEY'
if [ -z "$AUTH_SERVER_SQS_SECRET_ACCESS_KEY" ]; then
export AUTH_SERVER_SQS_SECRET_ACCESS_KEY="x"
fi
@@ -218,9 +250,11 @@ fi
if [ -z "$SYNCING_SERVER_SNS_ENDPOINT" ]; then
export SYNCING_SERVER_SNS_ENDPOINT="http://localstack:4566"
fi
file_env 'SYNCING_SERVER_SNS_SECRET_ACCESS_KEY'
if [ -z "$SYNCING_SERVER_SNS_SECRET_ACCESS_KEY" ]; then
export SYNCING_SERVER_SNS_SECRET_ACCESS_KEY="x"
fi
file_env 'SYNCING_SERVER_SNS_ACCESS_KEY_ID'
if [ -z "$SYNCING_SERVER_SNS_ACCESS_KEY_ID" ]; then
export SYNCING_SERVER_SNS_ACCESS_KEY_ID="x"
fi
@@ -233,9 +267,11 @@ fi
if [ -z "$SYNCING_SERVER_SQS_AWS_REGION" ]; then
export SYNCING_SERVER_SQS_AWS_REGION="us-east-1"
fi
file_env 'SYNCING_SERVER_SQS_ACCESS_KEY_ID'
if [ -z "$SYNCING_SERVER_SQS_ACCESS_KEY_ID" ]; then
export SYNCING_SERVER_SQS_ACCESS_KEY_ID="x"
fi
file_env 'SYNCING_SERVER_SQS_SECRET_ACCESS_KEY'
if [ -z "$SYNCING_SERVER_SQS_SECRET_ACCESS_KEY" ]; then
export SYNCING_SERVER_SQS_SECRET_ACCESS_KEY="x"
fi
@@ -278,9 +314,11 @@ fi
if [ -z "$FILES_SERVER_SNS_ENDPOINT" ]; then
export FILES_SERVER_SNS_ENDPOINT="http://localstack:4566"
fi
file_env 'FILES_SERVER_SNS_SECRET_ACCESS_KEY'
if [ -z "$FILES_SERVER_SNS_SECRET_ACCESS_KEY" ]; then
export FILES_SERVER_SNS_SECRET_ACCESS_KEY="x"
fi
file_env 'FILES_SERVER_SNS_ACCESS_KEY_ID'
if [ -z "$FILES_SERVER_SNS_ACCESS_KEY_ID" ]; then
export FILES_SERVER_SNS_ACCESS_KEY_ID="x"
fi
@@ -293,9 +331,11 @@ fi
if [ -z "$FILES_SERVER_SQS_AWS_REGION" ]; then
export FILES_SERVER_SQS_AWS_REGION="us-east-1"
fi
file_env 'FILES_SERVER_SQS_ACCESS_KEY_ID'
if [ -z "$FILES_SERVER_SQS_ACCESS_KEY_ID" ]; then
export FILES_SERVER_SQS_ACCESS_KEY_ID="x"
fi
file_env 'FILES_SERVER_SQS_SECRET_ACCESS_KEY'
if [ -z "$FILES_SERVER_SQS_SECRET_ACCESS_KEY" ]; then
export FILES_SERVER_SQS_SECRET_ACCESS_KEY="x"
fi
@@ -322,9 +362,11 @@ fi
if [ -z "$REVISIONS_SERVER_SNS_ENDPOINT" ]; then
export REVISIONS_SERVER_SNS_ENDPOINT="http://localstack:4566"
fi
file_env 'REVISIONS_SERVER_SNS_SECRET_ACCESS_KEY'
if [ -z "$REVISIONS_SERVER_SNS_SECRET_ACCESS_KEY" ]; then
export REVISIONS_SERVER_SNS_SECRET_ACCESS_KEY="x"
fi
file_env 'REVISIONS_SERVER_SNS_ACCESS_KEY_ID'
if [ -z "$REVISIONS_SERVER_SNS_ACCESS_KEY_ID" ]; then
export REVISIONS_SERVER_SNS_ACCESS_KEY_ID="x"
fi
@@ -337,9 +379,11 @@ fi
if [ -z "$REVISIONS_SERVER_SQS_AWS_REGION" ]; then
export REVISIONS_SERVER_SQS_AWS_REGION="us-east-1"
fi
file_env 'REVISIONS_SERVER_SQS_ACCESS_KEY_ID'
if [ -z "$REVISIONS_SERVER_SQS_ACCESS_KEY_ID" ]; then
export REVISIONS_SERVER_SQS_ACCESS_KEY_ID="x"
fi
file_env 'REVISIONS_SERVER_SQS_SECRET_ACCESS_KEY'
if [ -z "$REVISIONS_SERVER_SQS_SECRET_ACCESS_KEY" ]; then
export REVISIONS_SERVER_SQS_SECRET_ACCESS_KEY="x"
fi
+6
View File
@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.87.6](https://github.com/standardnotes/server/compare/@standardnotes/api-gateway@1.87.5...@standardnotes/api-gateway@1.87.6) (2023-12-06)
### Bug Fixes
* **api-gateway:** add grpc logs for internal errors ([529795d](https://github.com/standardnotes/server/commit/529795d393442727833f318234d308543c1ea731))
## [1.87.5](https://github.com/standardnotes/server/compare/@standardnotes/api-gateway@1.87.4...@standardnotes/api-gateway@1.87.5) (2023-12-01)
**Note:** Version bump only for package @standardnotes/api-gateway
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@standardnotes/api-gateway",
"version": "1.87.5",
"version": "1.87.6",
"engines": {
"node": ">=18.0.0 <21.0.0"
},
@@ -210,6 +210,7 @@ export class ContainerConfigLoader {
container.get<MapperInterface<SyncResponse, SyncResponseHttpRepresentation>>(
TYPES.Mapper_SyncResponseGRPCMapper,
),
container.get<winston.Logger>(TYPES.ApiGateway_Logger),
),
)
container
@@ -4,12 +4,15 @@ import { MapperInterface } from '@standardnotes/domain-core'
import { Metadata } from '@grpc/grpc-js'
import { SyncResponseHttpRepresentation } from '../../Mapping/Sync/Http/SyncResponseHttpRepresentation'
import { Status } from '@grpc/grpc-js/build/src/constants'
import { Logger } from 'winston'
export class GRPCSyncingServerServiceProxy {
constructor(
private syncingClient: ISyncingClient,
private syncRequestGRPCMapper: MapperInterface<Record<string, unknown>, SyncRequest>,
private syncResponseGRPCMapper: MapperInterface<SyncResponse, SyncResponseHttpRepresentation>,
private logger: Logger,
) {}
async sync(
@@ -39,12 +42,31 @@ export class GRPCSyncingServerServiceProxy {
})
}
if (error.code === Status.INTERNAL) {
this.logger.error(
`[GRPCSyncingServerServiceProxy] Internal gRPC error: ${error.message}. Payload: ${JSON.stringify(
payload,
)}`,
)
}
return reject(error)
}
return resolve({ status: 200, data: this.syncResponseGRPCMapper.toProjection(syncResponse) })
})
} catch (error) {
if (
'code' in (error as Record<string, unknown>) &&
(error as Record<string, unknown>).code === Status.INTERNAL
) {
this.logger.error(
`[GRPCSyncingServerServiceProxy] Internal gRPC error: ${JSON.stringify(error)}. Payload: ${JSON.stringify(
payload,
)}`,
)
}
reject(error)
}
})
+4
View File
@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.22.10](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.22.9...@standardnotes/home-server@1.22.10) (2023-12-06)
**Note:** Version bump only for package @standardnotes/home-server
## [1.22.9](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.22.8...@standardnotes/home-server@1.22.9) (2023-12-04)
**Note:** Version bump only for package @standardnotes/home-server
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@standardnotes/home-server",
"version": "1.22.9",
"version": "1.22.10",
"engines": {
"node": ">=18.0.0 <21.0.0"
},
+7
View File
@@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.21.3](https://github.com/standardnotes/server/compare/@standardnotes/websockets-server@1.21.2...@standardnotes/websockets-server@1.21.3) (2023-12-06)
### Bug Fixes
* **api-gateway:** add grpc logs for internal errors ([529795d](https://github.com/standardnotes/server/commit/529795d393442727833f318234d308543c1ea731))
* **websockets:** change error message on unknown errors ([79ae076](https://github.com/standardnotes/server/commit/79ae07623fa392f1f60160ecdc34a0fcfa4d9a48))
## [1.21.2](https://github.com/standardnotes/server/compare/@standardnotes/websockets-server@1.21.1...@standardnotes/websockets-server@1.21.2) (2023-12-01)
### Bug Fixes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@standardnotes/websockets-server",
"version": "1.21.2",
"version": "1.21.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},
@@ -69,7 +69,7 @@ describe('SendMessageToClient', () => {
expect(result.isFailed()).toBe(true)
expect(result.getError()).toBe(
'Could not send message to connection connection-id for user 00000000-0000-0000-0000-000000000000. Error: error',
'Could not send message to connection connection-id for user 00000000-0000-0000-0000-000000000000. Error: {}',
)
})
@@ -45,9 +45,9 @@ export class SendMessageToClient implements UseCaseInterface<void> {
}
} catch (error) {
return Result.fail(
`Could not send message to connection ${connection.props.connectionId} for user ${userUuid.value}. Error: ${
(error as Error).message
}`,
`Could not send message to connection ${connection.props.connectionId} for user ${
userUuid.value
}. Error: ${JSON.stringify(error)}`,
)
}
}