Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Changes for instance server setting service to use schema, knex & fea…
Browse files Browse the repository at this point in the history
…thers 5 (#8081)
  • Loading branch information
hanzlamateen authored Jun 14, 2023
1 parent d839d9a commit 84d7a2f
Show file tree
Hide file tree
Showing 19 changed files with 401 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import styles from '../../styles/settings.module.scss'
const InstanceServer = () => {
const { t } = useTranslation()
const instanceServerSettingState = useHookstate(getMutableState(AdminInstanceServerSettingsState))
const instanceServerSettings = instanceServerSettingState?.instanceserver?.get({ noproxy: true }) || []
const instanceServerSettings = instanceServerSettingState?.instanceServer?.get({ noproxy: true }) || []

const user = useHookstate(getMutableState(AuthState).user)

Expand Down Expand Up @@ -46,23 +46,23 @@ const InstanceServer = () => {
/>

<InputText
name="rtc_start_port"
name="rtcStartPort"
label={t('admin:components.setting.rtcStartPort')}
value={el?.rtc_start_port || ''}
value={el?.rtcStartPort || ''}
disabled
/>

<InputText
name="rtc_end_port"
name="rtcEndPort"
label={t('admin:components.setting.rtcEndPort')}
value={el?.rtc_end_port || ''}
value={el?.rtcEndPort || ''}
disabled
/>

<InputText
name="rtc_port_block_size"
name="rtcPortBlockSize"
label={t('admin:components.setting.rtcPortBlockSize')}
value={el?.rtc_port_block_size || ''}
value={el?.rtcPortBlockSize || ''}
disabled
/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Paginated } from '@feathersjs/feathers'

import { InstanceServerSetting } from '@etherealengine/common/src/interfaces/InstanceServerSetting'
import { matches, Validator } from '@etherealengine/engine/src/common/functions/MatchesUtils'
import {
instanceServerSettingPath,
InstanceServerSettingType
} from '@etherealengine/engine/src/schemas/setting/instance-server-setting.schema'
import { defineAction, defineState, dispatchAction, getMutableState } from '@etherealengine/hyperflux'

import { API } from '../../../API'
Expand All @@ -10,7 +13,7 @@ import { NotificationService } from '../../../common/services/NotificationServic
export const AdminInstanceServerSettingsState = defineState({
name: 'AdminInstanceServerSettingsState',
initial: () => ({
instanceserver: [] as Array<InstanceServerSetting>,
instanceServer: [] as Array<InstanceServerSettingType>,
updateNeeded: true
})
})
Expand All @@ -19,7 +22,7 @@ const fetchedInstanceServerReceptor = (
action: typeof InstanceServerSettingActions.fetchedInstanceServer.matches._TYPE
) => {
const state = getMutableState(AdminInstanceServerSettingsState)
return state.merge({ instanceserver: action.instanceServerSettings.data, updateNeeded: false })
return state.merge({ instanceServer: action.instanceServerSettings.data, updateNeeded: false })
}

export const AdminInstanceServerReceptors = {
Expand All @@ -30,8 +33,8 @@ export const InstanceServerSettingService = {
fetchedInstanceServerSettings: async (inDec?: 'increment' | 'decrement') => {
try {
const instanceServerSettings = (await API.instance.client
.service('instance-server-setting')
.find()) as Paginated<InstanceServerSetting>
.service(instanceServerSettingPath)
.find()) as Paginated<InstanceServerSettingType>
dispatchAction(InstanceServerSettingActions.fetchedInstanceServer({ instanceServerSettings }))
} catch (err) {
NotificationService.dispatchNotify(err.message, { variant: 'error' })
Expand All @@ -42,6 +45,6 @@ export const InstanceServerSettingService = {
export class InstanceServerSettingActions {
static fetchedInstanceServer = defineAction({
type: 'ee.client.InstanceServerSetting.INSTANCE_SERVER_SETTING_DISPLAY',
instanceServerSettings: matches.object as Validator<unknown, Paginated<InstanceServerSetting>>
instanceServerSettings: matches.object as Validator<unknown, Paginated<InstanceServerSettingType>>
})
}
14 changes: 0 additions & 14 deletions packages/common/src/dbmodels/InstanceServerSetting.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/common/src/interfaces/InstanceServerSetting.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// // For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
import { querySyntax, Type } from '@feathersjs/typebox'
import type { Static } from '@feathersjs/typebox'

export const instanceServerSettingPath = 'instance-server-setting'

export const instanceServerSettingMethods = ['find', 'get', 'create', 'patch', 'remove'] as const

// Main data model schema
export const instanceServerSettingSchema = Type.Object(
{
id: Type.String({
format: 'uuid'
}),
clientHost: Type.String(),
rtcStartPort: Type.Integer(),
rtcEndPort: Type.Integer(),
rtcPortBlockSize: Type.Integer(),
identifierDigits: Type.Integer(),
local: Type.Boolean(),
domain: Type.String(),
releaseName: Type.String(),
port: Type.String(),
mode: Type.String(),
locationName: Type.String(),
createdAt: Type.String({ format: 'date-time' }),
updatedAt: Type.String({ format: 'date-time' })
},
{ $id: 'InstanceServerSetting', additionalProperties: false }
)
export type InstanceServerSettingType = Static<typeof instanceServerSettingSchema>

// Schema for creating new entries
export const instanceServerSettingDataSchema = Type.Pick(
instanceServerSettingSchema,
[
'clientHost',
'rtcStartPort',
'rtcEndPort',
'rtcPortBlockSize',
'identifierDigits',
'local',
'domain',
'releaseName',
'port',
'mode',
'locationName'
],
{
$id: 'InstanceServerSettingData'
}
)
export type InstanceServerSettingData = Static<typeof instanceServerSettingDataSchema>

// Schema for updating existing entries
export const instanceServerSettingPatchSchema = Type.Partial(instanceServerSettingSchema, {
$id: 'InstanceServerSettingPatch'
})
export type InstanceServerSettingPatch = Static<typeof instanceServerSettingPatchSchema>

// Schema for allowed query properties
export const instanceServerSettingQueryProperties = Type.Pick(instanceServerSettingSchema, [
'id',
'clientHost',
'rtcStartPort',
'rtcEndPort',
'rtcPortBlockSize',
'identifierDigits',
'local',
'domain',
'releaseName',
'port',
'mode',
'locationName'
])
export const instanceServerSettingQuerySchema = Type.Intersect(
[
querySyntax(instanceServerSettingQueryProperties),
// Add additional query properties here
Type.Object({}, { additionalProperties: false })
],
{ additionalProperties: false }
)
export type InstanceServerSettingQuery = Static<typeof instanceServerSettingQuerySchema>
6 changes: 3 additions & 3 deletions packages/server-core/src/appconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ const client = {
// TODO: rename to 'instanceserver'
const instanceserver = {
clientHost: process.env.APP_HOST!,
rtc_start_port: parseInt(process.env.RTC_START_PORT!),
rtc_end_port: parseInt(process.env.RTC_END_PORT!),
rtc_port_block_size: parseInt(process.env.RTC_PORT_BLOCK_SIZE!),
rtcStartPrt: parseInt(process.env.RTC_START_PORT!),
rtcEndPort: parseInt(process.env.RTC_END_PORT!),
rtcPortBlockSize: parseInt(process.env.RTC_PORT_BLOCK_SIZE!),
identifierDigits: 5,
local: process.env.LOCAL === 'true',
domain: process.env.INSTANCESERVER_DOMAIN || 'instanceserver.etherealengine.com',
Expand Down
8 changes: 4 additions & 4 deletions packages/server-core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@ export const localConfig = {
protocol: 'udp',
ip: configFile.instanceserver.domain! || '0.0.0.0',
announcedIp: null! as string,
port: process.env.DEV_CHANNEL === 'true' ? 30000 : configFile.instanceserver.rtc_start_port
port: process.env.DEV_CHANNEL === 'true' ? 30000 : configFile.instanceserver.rtcStartPrt
},
{
protocol: 'tcp',
ip: configFile.instanceserver.domain! || '0.0.0.0',
announcedIp: null! as string,
port: process.env.DEV_CHANNEL === 'true' ? 30000 : configFile.instanceserver.rtc_start_port
port: process.env.DEV_CHANNEL === 'true' ? 30000 : configFile.instanceserver.rtcStartPrt
}
]
},
worker: {
rtcMinPort: process.env.DEV_CHANNEL === 'true' ? 30000 : configFile.instanceserver.rtc_start_port,
rtcMinPort: process.env.DEV_CHANNEL === 'true' ? 30000 : configFile.instanceserver.rtcStartPrt,
rtcMaxPort:
(process.env.DEV_CHANNEL === 'true' ? 30000 : configFile.instanceserver.rtc_start_port) + NUM_RTC_PORTS - 1,
(process.env.DEV_CHANNEL === 'true' ? 30000 : configFile.instanceserver.rtcStartPrt) + NUM_RTC_PORTS - 1,
logLevel: 'info',
logTags: ['info', 'ice', 'dtls', 'rtp', 'srtp', 'rtcp']
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { SequelizeServiceOptions, Service } from 'feathers-sequelize'
import type { Params } from '@feathersjs/feathers'
import { KnexService } from '@feathersjs/knex'
import type { KnexAdapterParams } from '@feathersjs/knex'

import { InstanceServerSetting as InstanceServerSettingInterface } from '@etherealengine/common/src/interfaces/InstanceServerSetting'
import {
InstanceServerSettingData,
InstanceServerSettingPatch,
InstanceServerSettingQuery,
InstanceServerSettingType
} from '@etherealengine/engine/src/schemas/setting/instance-server-setting.schema'

import { Application } from '../../../declarations'
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface InstanceServerSettingParams extends KnexAdapterParams<InstanceServerSettingQuery> {}

export type InstanceServerSettingDataType = InstanceServerSettingInterface

export class InstanceServerSetting<T = InstanceServerSettingDataType> extends Service<T> {
app: Application

constructor(options: Partial<SequelizeServiceOptions>, app: Application) {
super(options)
this.app = app
}
}
export class InstanceServerSettingService<
T = InstanceServerSettingType,
ServiceParams extends Params = InstanceServerSettingParams
> extends KnexService<
InstanceServerSettingType,
InstanceServerSettingData,
InstanceServerSettingParams,
InstanceServerSettingPatch
> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createSwaggerServiceOptions } from 'feathers-swagger'

import {
instanceServerSettingDataSchema,
instanceServerSettingPatchSchema,
instanceServerSettingQuerySchema,
instanceServerSettingSchema
} from '@etherealengine/engine/src/schemas/setting/instance-server-setting.schema'

export default createSwaggerServiceOptions({
schemas: {
instanceServerSettingDataSchema,
instanceServerSettingPatchSchema,
instanceServerSettingQuerySchema,
instanceServerSettingSchema
},
docs: {
description: 'Instance server setting service description',
securities: ['all']
}
})
Original file line number Diff line number Diff line change
@@ -1,17 +1,60 @@
import { hooks as schemaHooks } from '@feathersjs/schema'
import { getValidator } from '@feathersjs/typebox'
import { iff, isProvider } from 'feathers-hooks-common'

import {
instanceServerSettingDataSchema,
instanceServerSettingPatchSchema,
instanceServerSettingQuerySchema,
instanceServerSettingSchema
} from '@etherealengine/engine/src/schemas/setting/instance-server-setting.schema'
import { dataValidator, queryValidator } from '@etherealengine/server-core/validators'

import authenticate from '../../hooks/authenticate'
import verifyScope from '../../hooks/verify-scope'
import {
instanceServerSettingDataResolver,
instanceServerSettingExternalResolver,
instanceServerSettingPatchResolver,
instanceServerSettingQueryResolver,
instanceServerSettingResolver
} from './instance-server-setting.resolvers'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const instanceServerSettingValidator = getValidator(instanceServerSettingSchema, dataValidator)
const instanceServerSettingDataValidator = getValidator(instanceServerSettingDataSchema, dataValidator)
const instanceServerSettingPatchValidator = getValidator(instanceServerSettingPatchSchema, dataValidator)
const instanceServerSettingQueryValidator = getValidator(instanceServerSettingQuerySchema, queryValidator)

export default {
around: {
all: [
schemaHooks.resolveExternal(instanceServerSettingExternalResolver),
schemaHooks.resolveResult(instanceServerSettingResolver)
]
},

before: {
all: [authenticate(), iff(isProvider('external'), verifyScope('admin', 'admin') as any)],
find: [iff(isProvider('external'), verifyScope('settings', 'read') as any)],
get: [iff(isProvider('external'), verifyScope('settings', 'read') as any)],
create: [iff(isProvider('external'), verifyScope('settings', 'write') as any)],
update: [iff(isProvider('external'), verifyScope('settings', 'write') as any)],
patch: [iff(isProvider('external'), verifyScope('settings', 'write') as any)],
remove: [iff(isProvider('external'), verifyScope('settings', 'write') as any)]
all: [
authenticate(),
iff(isProvider('external'), verifyScope('admin', 'admin')),
() => schemaHooks.validateQuery(instanceServerSettingQueryValidator),
schemaHooks.resolveQuery(instanceServerSettingQueryResolver)
],
find: [iff(isProvider('external'), verifyScope('settings', 'read'))],
get: [iff(isProvider('external'), verifyScope('settings', 'read'))],
create: [
iff(isProvider('external'), verifyScope('settings', 'write')),
() => schemaHooks.validateData(instanceServerSettingDataValidator),
schemaHooks.resolveData(instanceServerSettingDataResolver)
],
update: [iff(isProvider('external'), verifyScope('settings', 'write'))],
patch: [
iff(isProvider('external'), verifyScope('settings', 'write')),
() => schemaHooks.validateData(instanceServerSettingPatchValidator),
schemaHooks.resolveData(instanceServerSettingPatchResolver)
],
remove: [iff(isProvider('external'), verifyScope('settings', 'write'))]
},

after: {
Expand Down
Loading

0 comments on commit 84d7a2f

Please sign in to comment.