Skip to content

Commit

Permalink
refactor: used new decorate function for distributed services in KDK
Browse files Browse the repository at this point in the history
  • Loading branch information
claustres committed Dec 23, 2024
1 parent 895d11e commit 0b6977e
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions api/src/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import fs from 'fs-extra'
import { fileURLToPath } from 'url'
import makeDebug from 'debug'
import kCore, { permissions, createDefaultUsers } from '@kalisio/kdk/core.api.js'
import kCore, { permissions, createDefaultUsers, decorateDistributedService } from '@kalisio/kdk/core.api.js'
import kMap, { createFeaturesServiceForLayer, createDefaultCatalogLayers } from '@kalisio/kdk/map.api.js'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
Expand Down Expand Up @@ -34,22 +34,13 @@ export default async function () {
app.on('service', service => {
// Make remote services compliant with our internal app services so that permissions can be used
if (service.key === 'weacast') {
// Remote service are registered according to their path, ie with API prefix (but without trailing /)
const remoteService = app.service(service.path)
// Get name from service path without api prefix
const name = service.path.replace(app.get('apiPath').substring(1) + '/', '')
remoteService.name = name
// As remote services have no context, from the internal point of view path = name
// Unfortunately this property is already set and used by feathers-distributed and should not be altered
// remoteService.path = name
remoteService.app = app
remoteService.getPath = function (withApiPrefix) { return (withApiPrefix ? app.get('apiPath') + '/' + name : name) }
decorateDistributedService.call(app, service)
// Register default permissions for it
debug('Registering permissions for remote service ', name)
debug('Registering permissions for remote service ', service.name)
permissions.defineAbilities.registerHook((subject, can, cannot) => {
can('service', name)
can('read', name)
if (name === 'probes') can('create', name)
can('service', service.name)
can('read', service.name)
if (service.name === 'probes') can('create', service.name)
})
// We then need to update abilities cache
const authorisationService = app.getService('authorisations')
Expand Down

0 comments on commit 0b6977e

Please sign in to comment.