Skip to content

Commit

Permalink
feat(plugins): support scoping for consumer groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Leopoldthecoder committed Sep 5, 2023
1 parent 7fb5ad7 commit e8fd72f
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,17 @@ export default {
async created() {
await this.$nextTick()
let presetEntity
let entityData
switch (this.fieldState) {
case fieldStates.UPDATE_ENTITY:
if (!this[FORMS_API_KEY]) {
console.warn('[@kong-ui-public/forms] No API service provided')
break
}
presetEntity = await this.getItem((await this[FORMS_API_KEY].getOne(this.entity, this.model[this.schema.model])).data)
entityData = (await this[FORMS_API_KEY].getOne(this.entity, this.model[this.schema.model])).data
console.log(this.schema.entityDataKey, this.getItem(this.schema.entityDataKey ? entityData[this.schema.entityDataKey] : entityData))
presetEntity = this.getItem(this.schema.entityDataKey ? entityData[this.schema.entityDataKey] : entityData)
this.idValue = presetEntity.id
break
case fieldStates.CREATE_FROM_ENTITY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Set this value to `true` to hide the card title.
- required: `false`
- default: `''`

The type of the entity with which the plugin is associated. Can be one of `'services'`, `'routes'` or `'consumers'`.
The type of the entity with which the plugin is associated. Can be one of `'services'`, `'routes'`, `'consumers'` or `consumer_groups`.

#### `scopedEntityId`

Expand Down
8 changes: 4 additions & 4 deletions packages/entities/entities-plugins/docs/plugin-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ A table component for plugins.
- type: `string`
- required: `false`
- default: `null`
- Current entity id if the PluginList is nested in the plugins tab on a consumer, gateway service, or route detail page.
- Current entity id if the PluginList is nested in the plugins tab on a consumer, consumer group, gateway service, or route detail page.

- `entityType`:
- type: `'consumers' | 'services' | 'routes'`
- type: `'consumers' | 'consumer_groups' | 'services' | 'routes'`
- required: `false`
- default: `null`
- Current entity type if the PluginList is nested in the plugins tab on a consumer, gateway service, or route detail page.
- Current entity type if the PluginList is nested in the plugins tab on a consumer, consumer group, gateway service, or route detail page.

The base konnect or kongManger config.

Expand Down Expand Up @@ -178,7 +178,7 @@ A synchronous or asynchronous function, that returns a boolean, that evaluates i

#### `canRetrieveScopedEntity`

- type: `Function as PropType<(entityType: 'service' | 'route' | 'consumer', entityId: string) => boolean | Promise<boolean>>`
- type: `Function as PropType<(entityType: 'service' | 'route' | 'consumer' | 'consumer_group', entityId: string) => boolean | Promise<boolean>>`
- required: `false`
- default: `async () => true`

Expand Down
3 changes: 1 addition & 2 deletions packages/entities/entities-plugins/fixtures/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const plugins: FetcherRawResponse = {
ordering: {},
instance_name: 'instance-1',
created_at: 1610617600,

consumer_group: { id: 'consumer-group-1' },
consumer: { id: 'consumer-1' },
route: { id: 'route-1' },
service: null,
Expand All @@ -32,7 +32,6 @@ export const plugins: FetcherRawResponse = {
protocols: ['http', 'https'],
tags: ['tag2'],
created_at: 1610617601,

consumer: null,
route: null,
service: null,
Expand Down
1 change: 1 addition & 0 deletions packages/entities/entities-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
},
"dependencies": {
"@kong-ui-public/copy-uuid": "workspace:^",
"@kong-ui-public/entities-consumer-groups": "workspace:^",
"@kong-ui-public/entities-consumers": "workspace:^",
"@kong-ui-public/entities-gateway-services": "workspace:^",
"@kong-ui-public/entities-routes": "workspace:^",
Expand Down
5 changes: 5 additions & 0 deletions packages/entities/entities-plugins/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const init = async () => {
name: 'view-consumer',
component: () => import('./pages/FallbackPage.vue'),
},
{
path: '/consumer_group/:id',
name: 'view-consumer_group',
component: () => import('./pages/FallbackPage.vue'),
},
{
path: '/plugin/:id/configure-dynamic-ordering',
name: 'configure-dynamic-ordering',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@
:uuid="rowValue.id"
/>
</template>
<template #consumer_group="{ rowValue, row }">
<span v-if="!rowValue">–</span>
<CopyUuid
v-else
data-testid="consumer-group-copy-uuid"
:notify="() => { }"
:success-tooltip="t('copy.success_tooltip')"
:tooltip="t('copy.tooltip', { label: row.label })"
:truncated="false"
:uuid="rowValue.id"
/>
</template>
</EntityBaseConfigCard>
</div>
</template>
Expand Down Expand Up @@ -197,6 +209,11 @@ const configSchema = computed((): ConfigurationSchema => {
section: ConfigurationSchemaSection.Basic,
order: 6,
},
consumer_group: {
label: t('plugins.fields.consumer_group'),
section: ConfigurationSchemaSection.Basic,
order: 6,
},
protocols: {
type: ConfigurationSchemaType.BadgeTag,
section: ConfigurationSchemaSection.Basic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ describe('<PluginList />', () => {
.should('not.contain.text', 'Global')
.should('contain.text', 'Route')
.should('contain.text', 'Consumer')
.should('have.lengthOf', 2)
.should('contain.text', 'Consumer Group')
.should('have.lengthOf', 3)

cy.getTestId('acl').find('[data-testid="appliedTo"] .k-badge')
.should('have.lengthOf', 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ const aggregateAppliedTo = (row: EntityRow): ({ type: ViewRouteType | null, badg
if (row.consumer?.id) {
badges.push({ type: 'consumer', badgeText: t('plugins.list.table_headers.applied_to_badges.consumer') })
}
if (row.consumer_group?.id) {
badges.push({ type: 'consumer_group', badgeText: t('plugins.list.table_headers.applied_to_badges.consumer_group') })
}
if (badges.length) {
return badges
}
Expand All @@ -482,6 +485,9 @@ const handleAppliedToClick = (type: ViewRouteType, row: EntityRow) => {
case 'consumer':
id = row.consumer?.id
break
case 'consumer_group':
id = row.consumer_group?.id
break
default:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const usePluginMetaData = () => {
group: PluginGroup.TRAFFIC_CONTROL,
isEnterprise: true,
name: t('plugins.meta.rate-limiting-advanced.name'),
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER],
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER, PluginScope.CONSUMER_GROUP],
},
'rate-limiting': {
description: t('plugins.meta.rate-limiting.description'),
Expand Down Expand Up @@ -317,7 +317,7 @@ export const usePluginMetaData = () => {
group: PluginGroup.TRANSFORMATIONS,
isEnterprise: false,
name: t('plugins.meta.response-transformer-advanced.name'),
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER],
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER, PluginScope.CONSUMER_GROUP],
},
'correlation-id': {
description: t('plugins.meta.correlation-id.description'),
Expand All @@ -331,21 +331,21 @@ export const usePluginMetaData = () => {
group: PluginGroup.TRANSFORMATIONS,
isEnterprise: true,
name: t('plugins.meta.request-transformer-advanced.name'),
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER],
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER, PluginScope.CONSUMER_GROUP],
},
'request-transformer': {
description: t('plugins.meta.request-transformer.description'),
group: PluginGroup.TRANSFORMATIONS,
isEnterprise: false,
name: t('plugins.meta.request-transformer.name'),
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER],
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER, PluginScope.CONSUMER_GROUP],
},
'response-transformer': {
description: t('plugins.meta.response-transformer.description'),
group: PluginGroup.TRANSFORMATIONS,
isEnterprise: false,
name: t('plugins.meta.response-transformer.name'),
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER],
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER, PluginScope.CONSUMER_GROUP],
},
'route-transformer-advanced': {
description: t('plugins.meta.route-transformer-advanced.description'),
Expand Down
6 changes: 4 additions & 2 deletions packages/entities/entities-plugins/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"consumer": "Consumer",
"global": "Global",
"route": "Route",
"service": "Service"
"service": "Service",
"consumer_group": "Consumer Group"
},
"id": "ID",
"name": "Name",
Expand Down Expand Up @@ -388,7 +389,8 @@
"fields": {
"service": "Service ID",
"route": "Route ID",
"consumer": "Consumer ID"
"consumer": "Consumer ID",
"consumer_group": "Consumer Group ID"
}
},
"glossary": {
Expand Down
6 changes: 4 additions & 2 deletions packages/entities/entities-plugins/src/types/plugin-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import type { FilterSchema, KongManagerBaseTableConfig, KonnectBaseTableConfig }
import type { EntityRow as ServiceEntity } from '@kong-ui-public/entities-gateway-services'
import type { EntityRow as ConsumerEntity } from '@kong-ui-public/entities-consumers'
import type { EntityRow as RouteEntity } from '@kong-ui-public/entities-routes'
import type { EntityRow as ConsumerGroupEntity } from '@kong-ui-public/entities-consumer-groups'

export type ViewRouteType = 'consumer' | 'route' | 'service'
export type EntityType = 'consumers' | 'routes' | 'services'
export type ViewRouteType = 'consumer' | 'route' | 'service' | 'consumer_group'
export type EntityType = 'consumers' | 'routes' | 'services' | 'consumer_groups'

export interface EntityRow extends Record<string, any> {
config: any
Expand All @@ -22,6 +23,7 @@ export interface EntityRow extends Record<string, any> {
consumer?: Pick<ConsumerEntity, 'id'> | null
route?: Pick<RouteEntity, 'id'> | null
service?: Pick<ServiceEntity, 'id'> | null
consumer_group?: Pick<ConsumerGroupEntity, 'id'> | null
}

export interface BasePluginListConfig {
Expand Down
1 change: 1 addition & 0 deletions packages/entities/entities-plugins/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum PluginScope {
SERVICE = 'service',
ROUTE = 'route',
CONSUMER = 'consumer',
CONSUMER_GROUP = 'consumer_group',
}

export type PluginMetaData = {
Expand Down
Loading

0 comments on commit e8fd72f

Please sign in to comment.