Skip to content

Commit

Permalink
feat(entities-plugins): support upstream-oauth (#1543)
Browse files Browse the repository at this point in the history
* feat(entities-plugins): support upstream-oauth

* fix(entities-plugins): edit number array fields
  • Loading branch information
Leopoldthecoder authored Aug 8, 2024
1 parent ab848a2 commit 3aec318
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 16 deletions.
8 changes: 6 additions & 2 deletions packages/core/forms/src/components/fields/FieldArray.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@
/>

<KInput
v-else-if="!schema.inputAttributes || !schema.inputAttributes.type || schema.inputAttributes.type === 'text'"
v-model="value[index]"
v-else-if="!schema.inputAttributes || !schema.inputAttributes.type || schema.inputAttributes.type === 'text' || schema.inputAttributes.type === 'number'"
:aria-labelledby="getLabelId(schema)"
v-bind="schema.inputAttributes"
:model-value="value[index]"
:type="schema.inputAttributes && schema.inputAttributes.type || 'text'"
@input="(val) => { handleInput(val, index) }"
/>

<input
Expand Down Expand Up @@ -211,6 +212,9 @@ export default {
return 'field-' + fieldSchema.type
},
modelUpdated() {},
handleInput(val, index) {
this.value = this.value.map((item, i) => i === index ? val : item)
},
},
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ const getModel = (): Record<string, any> => {
} else if (fieldSchemaValueType === 'array') {
if ((!fieldValue || !fieldValue.length)) {
fieldValue = fieldSchema.submitWhenNull ? null : []
} else if (fieldSchema.inputAttributes?.type === 'number') {
fieldValue = fieldValue.map((value: string) => Number(value))
}
}
Expand Down
17 changes: 7 additions & 10 deletions packages/entities/entities-plugins/src/components/PluginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ import { computed, onBeforeMount, reactive, ref, watch, type PropType } from 'vu
import { useRouter } from 'vue-router'
import composables from '../composables'
import { CREDENTIAL_METADATA, CREDENTIAL_SCHEMAS, PLUGIN_METADATA } from '../definitions/metadata'
import { ArrayStringFieldSchema } from '../definitions/schemas/ArrayStringFieldSchema'
import { ArrayInputFieldSchema } from '../definitions/schemas/ArrayInputFieldSchema'
import endpoints from '../plugins-endpoints'
import {
EntityTypeIdField,
Expand Down Expand Up @@ -623,11 +623,11 @@ const buildFormSchema = (parentKey: string, response: Record<string, any>, initi
fields: [{
schema: {
fields: [{
...ArrayStringFieldSchema,
...ArrayInputFieldSchema,
model: field,
valueArrayType: elementsType === 'integer' ? 'number' : elementsType || 'string',
inputAttributes: {
...ArrayStringFieldSchema.inputAttributes,
...ArrayInputFieldSchema.inputAttributes,
type: elementsType === 'integer' ? 'number' : 'text',
inputMode: elementsType === 'integer' ? 'numeric' : 'text',
},
Expand Down Expand Up @@ -685,14 +685,11 @@ const buildFormSchema = (parentKey: string, response: Record<string, any>, initi
// pass the referenceable flag from elements to the parent
initialFormSchema[field].referenceable = elements.referenceable
if (elements.type === 'string' && !elements.one_of) {
if ((elements.type === 'string' || elements.type === 'integer') && !elements.one_of) {
const { id, help, label, hint, values, referenceable } = initialFormSchema[field]
const { help: helpOverride, ...overrides } = JSON.parse(JSON.stringify(ArrayStringFieldSchema))
initialFormSchema[field] = { id, help, label, hint, values, referenceable, ...overrides }
// Only replace the help text when it is not defined because ArrayStringFieldSchema is more generic
if (initialFormSchema[field].help === undefined && typeof helpOverride === 'string') {
initialFormSchema[field].help = marked.parse(helpOverride, { mangle: false, headerIds: false } as MarkedOptions)
}
const { inputAttributes, ...overrides } = JSON.parse(JSON.stringify(ArrayInputFieldSchema))
inputAttributes.type = elements.type === 'integer' ? 'number' : 'text'
initialFormSchema[field] = { id, help, label, hint, values, referenceable, inputAttributes, ...overrides }
}
}
Expand Down
11 changes: 8 additions & 3 deletions packages/entities/entities-plugins/src/composables/useSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { aiPromptDecoratorSchema } from '../definitions/schemas/AIPromptDecorato
import { aiPromptTemplateSchema } from '../definitions/schemas/AIPromptTemplate'
import { aiRateLimitingAdvancedSchema } from '../definitions/schemas/AIRateLimitingAdvanced'
import { applicationRegistrationSchema } from '../definitions/schemas/ApplicationRegistration'
import { ArrayStringFieldSchema } from '../definitions/schemas/ArrayStringFieldSchema'
import { ArrayInputFieldSchema } from '../definitions/schemas/ArrayInputFieldSchema'
import { dataDogSchema } from '../definitions/schemas/Datadog'
import { graphqlRateLimitingAdvancedSchema } from '../definitions/schemas/GraphQLRateLimitingAdvanced'
import { jwtSchema } from '../definitions/schemas/JWT'
Expand All @@ -22,6 +22,7 @@ import { statsDSchema } from '../definitions/schemas/StatsD'
import { statsDAdvancedSchema } from '../definitions/schemas/StatsDAdvanced'
import { vaultAuthSchema } from '../definitions/schemas/VaultAuth'
import ZipkinSchema from '../definitions/schemas/Zipkin'
import { upstreamOauthSchema } from '../definitions/schemas/UpstreamOauth'
import typedefs from '../definitions/schemas/typedefs'
import { type CustomSchemas } from '../types'
import useI18n from './useI18n'
Expand Down Expand Up @@ -200,6 +201,10 @@ export const useSchemas = (options?: UseSchemasOptions) => {
...ZipkinSchema,
},

'upstream-oauth': {
...upstreamOauthSchema,
},

saml: {
...samlSchema,
},
Expand Down Expand Up @@ -499,11 +504,11 @@ export const useSchemas = (options?: UseSchemasOptions) => {
fields: [{
schema: {
fields: [{
...ArrayStringFieldSchema,
...ArrayInputFieldSchema,
model: schema.model,
valueArrayType: elementsType === 'integer' ? 'number' : elementsType || 'string',
inputAttributes: {
...ArrayStringFieldSchema.inputAttributes,
...ArrayInputFieldSchema.inputAttributes,
type: elementsType === 'integer' ? 'number' : 'text',
inputMode: elementsType === 'integer' ? 'numeric' : 'text',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,14 @@ export const PLUGIN_METADATA: Record<string, Omit<PluginMetaData<I18nMessageSour
],
},
},
'upstream-oauth': {
descriptionKey: 'plugins.meta.upstream-oauth.description',
group: PluginGroup.AUTHENTICATION,
isEnterprise: true,
nameKey: 'plugins.meta.upstream-oauth.name',
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER, PluginScope.CONSUMER_GROUP],
imageName: 'oauth2',
},
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const ArrayStringFieldSchema = {
export const ArrayInputFieldSchema = {
type: 'array',
valueType: 'string',
valueArrayType: 'array',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { UpstreamOauthSchema } from '../../types/plugins/upstream-oauth'

export const upstreamOauthSchema: UpstreamOauthSchema = {
'config-behavior-idp_error_response_body_template': {
type: 'textArea',
rows: 4,
},
}
4 changes: 4 additions & 0 deletions packages/entities/entities-plugins/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@
"header-cert-auth": {
"name": "Header Certificate Authentication",
"description": "Authenticate clients with MTLS certificate passed in header by a WAF or load balancer"
},
"upstream-oauth": {
"name": "Upstream OAuth",
"description": "Configure Kong to obtain a OAuth2 token to consume an upstream API"
}
},
"fields": {
Expand Down
2 changes: 2 additions & 0 deletions packages/entities/entities-plugins/src/types/plugin-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { VaultAuthSchema } from './plugins/vault-auth'
import type { GraphQLRateLimitingAdvancedSchema } from './plugins/graphql-rate-limiting-advanced'
import type { SAMLSchema } from './plugins/saml'
import type { OasValidationSchema } from './plugins/oas-validation'
import type { UpstreamOauthSchema } from './plugins/upstream-oauth'

export interface BasePluginSelectConfig {
/** A function that returns the route for creating a plugin */
Expand Down Expand Up @@ -215,4 +216,5 @@ export interface CustomSchemas {
zipkin: CommonSchemaFields & Record<string, any>
saml: SAMLSchema
'oas-validation': OasValidationSchema
'upstream-oauth': UpstreamOauthSchema
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { CommonSchemaFields } from './shared'

export interface UpstreamOauthSchema extends CommonSchemaFields {
'config-behavior-idp_error_response_body_template': {
type: string,
rows: number
}
}

0 comments on commit 3aec318

Please sign in to comment.