From cdebb677c9b7d3f84b68d2c7ee3cfa5606d59322 Mon Sep 17 00:00:00 2001 From: Hugh Messenger Date: Wed, 11 Dec 2024 15:45:25 -0600 Subject: [PATCH] Fixes per Nik for emit(), provider config check, naming convention --- api/lib/config.ts | 4 ++++ api/routes/agency.ts | 4 ++-- api/routes/ldap.ts | 12 ++++++------ .../Connection/CertificateMachineUser.vue | 8 +++++--- api/web/src/components/ConnectionEdit.vue | 13 +++++-------- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/api/lib/config.ts b/api/lib/config.ts index ba67e3b5b..c5bfadb9a 100644 --- a/api/lib/config.ts +++ b/api/lib/config.ts @@ -112,6 +112,10 @@ export default class Config { } } + externalProviderIsConfigured(): boolean { + return !!(this.server.provider_url && this.server.provider_secret && this.server.provider_client); + } + static async env(args: ConfigArgs): Promise { if (!process.env.AWS_REGION) { process.env.AWS_REGION = 'us-east-1'; diff --git a/api/routes/agency.ts b/api/routes/agency.ts index 5841654cc..7eb73320f 100644 --- a/api/routes/agency.ts +++ b/api/routes/agency.ts @@ -28,7 +28,7 @@ export default async function router(schema: Schema, config: Config) { const user = await Auth.as_user(config, req); const profile = await config.models.Profile.from(user.email); - if (!config.server.provider_url || !config.server.provider_secret || !config.server.provider_client) { + if (!config.externalProviderIsConfigured()) { res.json({ total: 0, items: [] }) } else if (!profile.id) { throw new Err(400, null, 'External ID must be set on profile'); @@ -55,7 +55,7 @@ export default async function router(schema: Schema, config: Config) { const user = await Auth.as_user(config, req); const profile = await config.models.Profile.from(user.email); - if (!config.server.provider_url || !config.server.provider_secret || !config.server.provider_client) { + if (!config.externalProviderIsConfigured()) { throw new Err(404, null, 'External API not configured'); } diff --git a/api/routes/ldap.ts b/api/routes/ldap.ts index 8f340895b..dab421331 100644 --- a/api/routes/ldap.ts +++ b/api/routes/ldap.ts @@ -26,7 +26,7 @@ export default async function router(schema: Schema, config: Config) { try { const profile = await Auth.as_profile(config, req); - if (!config.server.provider_url || !config.server.provider_secret || !config.server.provider_client) { + if (!config.externalProviderIsConfigured()) { throw new Err(400, null, 'External LDAP API not configured - Contact your administrator'); } @@ -53,8 +53,8 @@ export default async function router(schema: Schema, config: Config) { }) }), res: Type.Object({ - integrationId: Type.Union([Type.Integer(), Type.Null()]), - certificate: Type.Object({ + integrationId: Type.Optional(Type.Integer()), + auth: Type.Object({ cert: Type.String(), key: Type.String() }) @@ -63,7 +63,7 @@ export default async function router(schema: Schema, config: Config) { try { const profile = await Auth.as_profile(config, req); - if (!config.server.provider_url || !config.server.provider_secret || !config.server.provider_client) { + if (!config.externalProviderIsConfigured()) { throw new Err(400, null, 'External LDAP API not configured - Contact your administrator'); } @@ -97,8 +97,8 @@ export default async function router(schema: Schema, config: Config) { const certs = await api.Credentials.generate(); res.json({ - integrationId: user.integrations.find(Boolean)?.id ?? null, - certificate: certs + integrationId: user.integrations.find(Boolean)?.id ?? undefined, + auth: certs }) } catch (err) { Err.respond(err, res); diff --git a/api/web/src/components/Connection/CertificateMachineUser.vue b/api/web/src/components/Connection/CertificateMachineUser.vue index 89a07cecc..cc3a4c42a 100644 --- a/api/web/src/components/Connection/CertificateMachineUser.vue +++ b/api/web/src/components/Connection/CertificateMachineUser.vue @@ -94,7 +94,7 @@ export default { connection: Object }, emits: [ - 'certs', 'integration', + 'integration', ], data: function() { return { @@ -173,8 +173,10 @@ export default { }) this.loading.gen = true; - this.$emit('certs', res.certificate); - this.$emit('integration', res.integrationId) + this.$emit('integration', { + 'certs': res.auth, + 'integrationId': res.integrationId + }); } } } diff --git a/api/web/src/components/ConnectionEdit.vue b/api/web/src/components/ConnectionEdit.vue index 975b02fe0..44c511f12 100644 --- a/api/web/src/components/ConnectionEdit.vue +++ b/api/web/src/components/ConnectionEdit.vue @@ -200,8 +200,7 @@ @@ -344,12 +343,10 @@ export default { this.connection.auth = { cert: '', key: '' } this.loading = false; }, - creation: function(certs) { - this.connection.auth.cert = certs.cert; - this.connection.auth.key = certs.key; - }, - integration: function(integrationId) { - this.connection.integrationId = integrationId; + creation: function(integration) { + this.connection.integrationId = integration.integrationId; + this.connection.auth.cert = integration.certs.cert; + this.connection.auth.key = integration.certs.key; }, marti: function(certs) { this.connection.integrationId = null;