Skip to content

Commit

Permalink
Fixes per Nik for emit(), provider config check, naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesegrits committed Dec 11, 2024
1 parent 116dd7b commit cdebb67
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
4 changes: 4 additions & 0 deletions api/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config> {
if (!process.env.AWS_REGION) {
process.env.AWS_REGION = 'us-east-1';
Expand Down
4 changes: 2 additions & 2 deletions api/routes/agency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
}

Expand Down
12 changes: 6 additions & 6 deletions api/routes/ldap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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()
})
Expand All @@ -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');
}

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions api/web/src/components/Connection/CertificateMachineUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default {
connection: Object
},
emits: [
'certs', 'integration',
'integration',
],
data: function() {
return {
Expand Down Expand Up @@ -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
});
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions api/web/src/components/ConnectionEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@
<template v-else-if='type === "creation"'>
<CertificateMachineUser
:connection='connection'
@certs='creation($event)'
@integration='integration($event)'
@integration='creation($event)'
@err='err = $event'
/>
</template>
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit cdebb67

Please sign in to comment.