Skip to content

Commit

Permalink
Merge branch 'main' into refactor/lookup-reference
Browse files Browse the repository at this point in the history
  • Loading branch information
7sete7 committed Oct 22, 2024
2 parents 099b3df + 93f0db1 commit 4221ffa
Show file tree
Hide file tree
Showing 23 changed files with 570 additions and 82 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ RUN yarn install --production --silent --non-interactive --frozen-lockfile


RUN addgroup -g 1001 -S nodejs
RUN adduser -S konecty -u 1001
RUN adduser -S konecty -u 1001 --ingroup nodejs

USER konecty:nodejs

USER konecty
ENV PORT=3000
ENV NODE_ENV production
ENV NODE_ICU_DATA=/app/node_modules/full-icu
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Create .env using the sample.

Fill MONGO_URL with your database url, adding authentication and options

MONGO_URL=mongodb+srv://login:password@konecty.mongodb.net/?appName=konecty

MONGO_URL=mongodb+srv://login:password@konecty.mongodb.net/?appName=konecty

```
yarn
Expand All @@ -22,8 +21,6 @@ If this is a empty database, basic metadata and starting collections will be aut

The UI will be running at `localhost:3000`



## Konecty environment variables

- `KONECTY_MODE`: Can be `production` or `development`
Expand Down Expand Up @@ -76,6 +73,12 @@ docker run --name kondata -p 3000:3000 --link mongo --env MONGO_URL=mongodb://mo

Examples of REST usage can be found here: [REST](REST.md)

## Namespace configuration

The namespace is made of many parts, documented at:

- [Storage api](STORAGE.md)

## Logs

- KONDATA only log requests when **_status code_** of the response isn't 200 (OK).
79 changes: 79 additions & 0 deletions STORAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Storage API Configuration

This document describes the configuration for the storage API, including details on storage type, file management, and image processing settings.
The files api is [located here](./src/server/routes/rest/file/).

## Configuration Structure

The storage API configuration is part of the [Namespace](./src/imports/model/Namespace.ts) configuration. In any given deployment, it is located at the Namespace document: `MetaObjects > { "_id": "Namespace" }`, and is structured as the following example:

```json
{
"storage": {
"type": "local",
"directory": "/kon-files",
"wm": null,
"maxFileSize": 1073741824,
"thumbnail": {
"size": 200
},
"jpeg": {
"maxWidth": 3840,
"maxHeight": 3840,
"quality": 80
}
}
}
```

### Fields

- **type**: The type of storage being used. In this configuration, it is set to `"local"`, indicating that files are stored on the local filesystem. Its options can be:
- **s3**
- **local**
- **directory**: The directory where files will be stored, in the local filesystem. In this case, it is set to `"/kon-files"`.

- **wm**: This field is reserved for watermarking functionality. In this case set to `null` meaning no Watermark. The field type is described at [src/imports/types/watermark.ts](./src/imports/types/watermark.ts)

- **maxFileSize**: The maximum allowed file size for uploads, specified in bytes. Here, it is set to `1073741824` bytes (1 GB).

- **thumbnail**: Configuration for generating thumbnails.

- **size**: The size of the thumbnails, set to `200` pixels (width and height).

- **jpeg**: Configuration for processing JPEG images.
- **maxWidth**: The maximum width for JPEG images, set to `3840` pixels.
- **maxHeight**: The maximum height for JPEG images, set to `3840` pixels.
- **quality**: The quality of JPEG images after processing, with a value of `80` (on a scale from 0 to 100).

## Kubernetes CI YAML Configuration

When using the local filesystem, for deployment in a Kubernetes environment, the folder must be made a volume, so it can have the correct permissions.

```yaml
spec:
containers:
- name: konecty
image: konecty/konecty:2.1.9

(...)

volumeMounts:
- name: files-folder
mountPath: /kon-files

volumes:
- name: files-folder
emptyDir: {}
```
### Explanation
- **volumeMounts**: This section defines where the volumes should be mounted in the container.
- **name**: The name of the volume, here called `files-folder`.
- **mountPath**: The path inside the container where the volume should be mounted. This matches the directory in the storage configuration (`/kon-files`).

- **volumes**: This section defines the volumes available to the pod.
- **name**: The name of the volume, corresponding to the volume mount.
- **emptyDir**: This specifies that the volume is an empty directory, which exists only as long as the pod is running. It is used for temporary storage.
3 changes: 2 additions & 1 deletion src/imports/auth/geolocation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function saveGeoLocation({ authTokenId, longitude, latitude, userAg
return { success: false, errors: [{ message: 'Longitude or Latitude not defined' }] };
}

const user = getUser(authTokenId);
const user = await getUser(authTokenId);

const ua = new UAParser(userAgent ?? 'API Call').getResult();

Expand All @@ -30,6 +30,7 @@ export async function saveGeoLocation({ authTokenId, longitude, latitude, userAg
group: user.group,
},
],
__from: "setGeoLocation",
};

await MetaObject.Collections.AccessLog.insertOne(accessLog);
Expand Down
2 changes: 1 addition & 1 deletion src/imports/auth/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface UserInfoResponse {
name?: string;
namespace?: {
_id: string;
logoURL: string;
logoURL?: string;
siteURL: string;
title: string;
};
Expand Down
6 changes: 6 additions & 0 deletions src/imports/auth/login/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface accessLog {
resolution?: { width: number; height: number };
reason?: string;
source?: string;
__from?: string;
_user?: [
{
_id: string;
Expand All @@ -53,8 +54,13 @@ export async function login({ ip, user, password, password_SHA256, geolocation,
os: ua.os.name,
platform: ua.device.type,
source,
__from: 'login',
};

if (accessLog.source == null) {
delete accessLog.source;
}

if (resolution != null) {
if (typeof resolution === 'string') {
accessLog.resolution = JSON.parse(resolution);
Expand Down
5 changes: 5 additions & 0 deletions src/imports/data/filterUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ export function parseFilterCondition(condition, metaObject, { user }, invert) {
return parseInt(value);
}
break;
case "phone.phoneNumber":
if (value && !isString(value)) {
return value.toString();
}
break;
}
return value;
};
Expand Down
3 changes: 2 additions & 1 deletion src/imports/konsistent/createHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default async function createHistory(metaName, action, id, updatedBy, upd
return;
}

const keysToIgnore = ['_updatedAt', '_createdAt', '_deletedAt', '_updatedBy', '_createdBy', '_deletedBy'];
const changeId = uuidV4();
const meta = MetaObject.Meta[metaName];

Expand All @@ -24,7 +25,7 @@ export default async function createHistory(metaName, action, id, updatedBy, upd
dataId: id,
createdAt: updatedAt,
createdBy: pick(updatedBy, userDetailFields),
data: omitBy(changed, (value, key) => meta.fields[key]?.ignoreHistory),
data: omitBy(changed, (value, key) => keysToIgnore.includes(key) || meta.fields[key]?.ignoreHistory),
type: action,
};

Expand Down
4 changes: 1 addition & 3 deletions src/imports/konsistent/processIncomingChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import processReverseLookups from './processReverseLookups';
import * as References from './updateReferences';

import { DataDocument } from '@imports/types/data';
import omit from 'lodash/omit';
import { ClientSession, MongoServerError } from 'mongodb';

type Action = 'create' | 'update' | 'delete';
Expand All @@ -22,7 +21,6 @@ export default async function processIncomingChange(
changedProps: Record<string, any>,
dbSession?: ClientSession,
) {
const keysToIgnore = ['_updatedAt', '_createdAt', '_deletedAt', '_updatedBy', '_createdBy', '_deletedBy'];
let startTime = process.hrtime();

try {
Expand All @@ -37,7 +35,7 @@ export default async function processIncomingChange(
await References.updateRelations(metaName, action, incomingChange._id, incomingChange, dbSession);
logTimeSpent(startTime, `Updated relation references for ${metaName}`);

await createHistory(metaName, action, incomingChange._id, user, new Date(), omit(changedProps, keysToIgnore), dbSession);
await createHistory(metaName, action, incomingChange._id, user, new Date(), changedProps, dbSession);
logTimeSpent(startTime, `Created history for ${metaName}`);
} catch (e) {
if ((e as MongoServerError).codeName === 'NoSuchTransaction') {
Expand Down
5 changes: 2 additions & 3 deletions src/imports/lib/buildI18N/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import get from 'lodash/get';
import set from 'lodash/set';

import { MetaObjectType } from '../../types/metadata';
import { Label } from '@imports/model/Label';
import { MetaObject } from '../../model/MetaObject';
import { User } from '../../model/User';
import { MetaObjectType } from '../../types/metadata';
import { getAccessFor } from '../../utils/accessUtils';
import { Label } from '@imports/model/Label';
const negative: Label = {
en: 'Not',
de: 'Nicht',
Expand Down Expand Up @@ -88,7 +88,6 @@ export const buildI18N = async (user: User): Promise<Record<string, unknown>> =>
Object.entries(label).forEach(([lang, value]) => {
set(acc, [fixISO(lang), ...keyPath, metaProp, field], value as string);
if (metaProp === 'fields' && type === 'boolean') {
console.log('field', fieldLabel);
const boolLabels = {
true: value as string,
false: get(fieldLabel, 'labelOpposite', `${negative[lang] ?? 'not'} ${value}`),
Expand Down
3 changes: 3 additions & 0 deletions src/imports/meta/loadMetaObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ function dbWatch() {
case 'list':
MetaObject.DisplayMeta[fullDocument._id as unknown as string] = fullDocument as unknown as (typeof MetaObject.DisplayMeta)[string];
break;
case 'namespace':
Object.assign(MetaObject.Namespace, fullDocument);
break;
}
}
rebuildReferences();
Expand Down
1 change: 1 addition & 0 deletions src/imports/model/Namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const NamespaceSchema = z
trackUserGeolocation: z.boolean().optional(),
loginExpiration: z.number().optional(),
dateFormat: z.string().optional(),
logoURL: z.string().optional(),

storage: z.discriminatedUnion('type', [S3Storage, FSStorage]).optional(),
RocketChat: z
Expand Down
11 changes: 7 additions & 4 deletions src/imports/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const OTEL_URL = process.env.OTEL_URL;
const PROMETHEUS_URL = process.env.PROMETHEUS_URL;
const OTEL_SERVICE_NAME = process.env.OTEL_SERVICE_NAME ?? 'konecty';
const OTEL_SERVICE_VERSION = process.env.OTEL_SERVICE_VERSION ?? '1.0.0';
const DISABLE_TELEMETRY_LOGS = process.env.DISABLE_TELEMETRY_LOGS === 'true';

export default function initializeInstrumentation() {
const getTraceExporter = () => {
Expand All @@ -29,7 +30,7 @@ export default function initializeInstrumentation() {
return undefined;
}

return new ConsoleSpanExporter();
return DISABLE_TELEMETRY_LOGS ? undefined : new ConsoleSpanExporter();
};

const getMetricExporter = () => {
Expand All @@ -42,9 +43,11 @@ export default function initializeInstrumentation() {
if (process.env.NODE_ENV === 'test') {
return undefined;
}
return new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter(),
});
return DISABLE_TELEMETRY_LOGS
? undefined
: new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter(),
});
};
const sdk = new NodeSDK({
resource: new Resource({
Expand Down
Loading

0 comments on commit 4221ffa

Please sign in to comment.