sources/ldap: only save sync state in TaskInfo, return TaskInfo in API

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer
2021-04-08 23:20:48 +02:00
parent 7b0005ac42
commit d37c33d941
9 changed files with 148 additions and 102 deletions

View File

@ -150,7 +150,7 @@ msgstr "App"
#: src/elements/user/UserConsentList.ts:29
#: src/pages/admin-overview/TopApplicationsTable.ts:42
#: src/pages/applications/ApplicationListPage.ts:95
#: src/pages/applications/ApplicationListPage.ts:100
#: src/pages/providers/ProviderListPage.ts:53
msgid "Application"
msgstr "Application"
@ -370,6 +370,10 @@ msgstr "Binding Type"
msgid "Build hash: {0}"
msgstr "Build hash: {0}"
#: src/pages/sources/SourcesListPage.ts:62
msgid "Built-in"
msgstr "Built-in"
#: src/pages/outposts/ServiceConnectionDockerForm.ts:89
msgid "CA which the endpoint's Certificate is verified against. Can be left empty for no validation."
msgstr "CA which the endpoint's Certificate is verified against. Can be left empty for no validation."
@ -654,8 +658,8 @@ msgid "Copy Key"
msgstr "Copy Key"
#: src/pages/applications/ApplicationForm.ts:120
#: src/pages/applications/ApplicationListPage.ts:111
#: src/pages/applications/ApplicationListPage.ts:119
#: src/pages/applications/ApplicationListPage.ts:116
#: src/pages/applications/ApplicationListPage.ts:124
#: src/pages/crypto/CertificateKeyPairListPage.ts:122
#: src/pages/crypto/CertificateKeyPairListPage.ts:130
#: src/pages/events/RuleListPage.ts:91
@ -684,8 +688,8 @@ msgstr "Copy Key"
#: src/pages/providers/ProviderListPage.ts:116
#: src/pages/providers/RelatedApplicationButton.ts:27
#: src/pages/providers/RelatedApplicationButton.ts:35
#: src/pages/sources/SourcesListPage.ts:100
#: src/pages/sources/SourcesListPage.ts:109
#: src/pages/sources/SourcesListPage.ts:115
#: src/pages/sources/SourcesListPage.ts:124
#: src/pages/stages/StageListPage.ts:119
#: src/pages/stages/StageListPage.ts:128
#: src/pages/stages/invitation/InvitationListPage.ts:77
@ -701,7 +705,7 @@ msgstr "Copy Key"
msgid "Create"
msgstr "Create"
#: src/pages/applications/ApplicationListPage.ts:114
#: src/pages/applications/ApplicationListPage.ts:119
#: src/pages/providers/RelatedApplicationButton.ts:30
msgid "Create Application"
msgstr "Create Application"
@ -782,7 +786,7 @@ msgstr "Create provider"
#: src/pages/policies/PolicyListPage.ts:136
#: src/pages/property-mappings/PropertyMappingListPage.ts:125
#: src/pages/providers/ProviderListPage.ts:119
#: src/pages/sources/SourcesListPage.ts:112
#: src/pages/sources/SourcesListPage.ts:127
#: src/pages/stages/StageListPage.ts:131
msgid "Create {0}"
msgstr "Create {0}"
@ -826,7 +830,7 @@ msgid "Define how notifications are sent to users, like Email or Webhook."
msgstr "Define how notifications are sent to users, like Email or Webhook."
#: src/elements/forms/DeleteForm.ts:79
#: src/pages/applications/ApplicationListPage.ts:102
#: src/pages/applications/ApplicationListPage.ts:107
#: src/pages/crypto/CertificateKeyPairListPage.ts:86
#: src/pages/events/RuleListPage.ts:82
#: src/pages/events/TransportListPage.ts:86
@ -837,7 +841,7 @@ msgstr "Define how notifications are sent to users, like Email or Webhook."
#: src/pages/policies/PolicyListPage.ts:115
#: src/pages/property-mappings/PropertyMappingListPage.ts:104
#: src/pages/providers/ProviderListPage.ts:98
#: src/pages/sources/SourcesListPage.ts:91
#: src/pages/sources/SourcesListPage.ts:106
#: src/pages/stages/StageListPage.ts:110
#: src/pages/stages/invitation/InvitationListPage.ts:68
#: src/pages/stages/prompt/PromptListPage.ts:87
@ -939,7 +943,7 @@ msgstr "Disable Static Tokens"
msgid "Disable Time-based OTP"
msgstr "Disable Time-based OTP"
#: src/pages/sources/SourcesListPage.ts:60
#: src/pages/sources/SourcesListPage.ts:75
msgid "Disabled"
msgstr "Disabled"
@ -976,7 +980,7 @@ msgstr "Each provider has a different issuer, based on the application slug."
#: src/pages/providers/oauth2/OAuth2ProviderViewPage.ts:139
#: src/pages/providers/proxy/ProxyProviderViewPage.ts:138
#: src/pages/providers/saml/SAMLProviderViewPage.ts:132
#: src/pages/sources/SourcesListPage.ts:79
#: src/pages/sources/SourcesListPage.ts:94
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:116
#: src/pages/sources/oauth/OAuthSourceViewPage.ts:135
#: src/pages/sources/saml/SAMLSourceViewPage.ts:122
@ -1592,8 +1596,8 @@ msgstr "Last run"
msgid "Last seen: {0}"
msgstr "Last seen: {0}"
#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:23
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:150
#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:25
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:154
msgid "Last sync: {0}"
msgstr "Last sync: {0}"
@ -1950,11 +1954,11 @@ msgstr "Not connected."
msgid "Not found"
msgstr "Not found"
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:148
msgid "Not synced in the last hour, check System tasks."
msgstr "Not synced in the last hour, check System tasks."
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:165
msgid "Not synced yet."
msgstr "Not synced yet."
#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:32
#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:40
msgid "Not synced."
msgstr "Not synced."
@ -2043,6 +2047,10 @@ msgstr "Only fail the policy, don't set user's password."
msgid "Only send notification once, for example when sending a webhook into a chat channel."
msgstr "Only send notification once, for example when sending a webhook into a chat channel."
#: src/pages/applications/ApplicationListPage.ts:95
msgid "Open application"
msgstr "Open application"
#: src/pages/providers/oauth2/OAuth2ProviderViewPage.ts:172
msgid "OpenID Configuration Issuer"
msgstr "OpenID Configuration Issuer"
@ -2472,7 +2480,7 @@ msgstr "Resources"
msgid "Result"
msgstr "Result"
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:163
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:177
#: src/pages/system-tasks/SystemTaskListPage.ts:107
msgid "Retry Task"
msgstr "Retry Task"
@ -2589,7 +2597,7 @@ msgstr "See documentation for a list of all variables."
msgid "Select a provider that this application should use. Alternatively, create a new provider."
msgstr "Select a provider that this application should use. Alternatively, create a new provider."
#: src/elements/table/Table.ts:215
#: src/elements/table/Table.ts:218
msgid "Select all rows"
msgstr "Select all rows"
@ -2726,7 +2734,7 @@ msgid "Something went wrong! Please try again later."
msgstr "Something went wrong! Please try again later."
#: src/pages/providers/ProviderListPage.ts:91
#: src/pages/sources/SourcesListPage.ts:84
#: src/pages/sources/SourcesListPage.ts:99
msgid "Source"
msgstr "Source"
@ -3101,6 +3109,10 @@ msgstr "Symbol charset"
msgid "Sync"
msgstr "Sync"
#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:31
msgid "Sync failed."
msgstr "Sync failed."
#: src/pages/sources/ldap/LDAPSourceForm.ts:93
msgid "Sync groups"
msgstr "Sync groups"
@ -3142,6 +3154,14 @@ msgstr "TOTP Authenticators"
msgid "Target"
msgstr "Target"
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:151
msgid "Task finished with errors"
msgstr "Task finished with errors"
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:148
msgid "Task finished with warnings"
msgstr "Task finished with warnings"
#: src/pages/stages/email/EmailStageForm.ts:157
msgid "Template"
msgstr "Template"
@ -3351,7 +3371,7 @@ msgstr "Up-to-date!"
#: src/pages/providers/oauth2/OAuth2ProviderViewPage.ts:129
#: src/pages/providers/proxy/ProxyProviderViewPage.ts:128
#: src/pages/providers/saml/SAMLProviderViewPage.ts:122
#: src/pages/sources/SourcesListPage.ts:66
#: src/pages/sources/SourcesListPage.ts:81
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:106
#: src/pages/sources/oauth/OAuthSourceViewPage.ts:125
#: src/pages/sources/saml/SAMLSourceViewPage.ts:112
@ -3454,7 +3474,7 @@ msgstr "Update details"
#: src/pages/policies/PolicyListPage.ts:80
#: src/pages/property-mappings/PropertyMappingListPage.ts:69
#: src/pages/providers/ProviderListPage.ts:76
#: src/pages/sources/SourcesListPage.ts:69
#: src/pages/sources/SourcesListPage.ts:84
#: src/pages/stages/StageListPage.ts:88
#: src/pages/users/UserActiveForm.ts:41
msgid "Update {0}"
@ -3714,6 +3734,10 @@ msgstr "Yes"
msgid "You're currently impersonating {0}."
msgstr "You're currently impersonating {0}."
#: src/pages/sources/SourcesListPage.ts:61
msgid "authentik Built-in"
msgstr "authentik Built-in"
#: src/pages/stages/password/PasswordStageForm.ts:76
msgid "authentik Builtin Database"
msgstr "authentik Builtin Database"

View File

@ -150,7 +150,7 @@ msgstr ""
#: src/elements/user/UserConsentList.ts:29
#: src/pages/admin-overview/TopApplicationsTable.ts:42
#: src/pages/applications/ApplicationListPage.ts:95
#: src/pages/applications/ApplicationListPage.ts:100
#: src/pages/providers/ProviderListPage.ts:53
msgid "Application"
msgstr ""
@ -366,6 +366,10 @@ msgstr ""
msgid "Build hash: {0}"
msgstr ""
#: src/pages/sources/SourcesListPage.ts:62
msgid "Built-in"
msgstr ""
#: src/pages/outposts/ServiceConnectionDockerForm.ts:89
msgid "CA which the endpoint's Certificate is verified against. Can be left empty for no validation."
msgstr ""
@ -650,8 +654,8 @@ msgid "Copy Key"
msgstr ""
#: src/pages/applications/ApplicationForm.ts:120
#: src/pages/applications/ApplicationListPage.ts:111
#: src/pages/applications/ApplicationListPage.ts:119
#: src/pages/applications/ApplicationListPage.ts:116
#: src/pages/applications/ApplicationListPage.ts:124
#: src/pages/crypto/CertificateKeyPairListPage.ts:122
#: src/pages/crypto/CertificateKeyPairListPage.ts:130
#: src/pages/events/RuleListPage.ts:91
@ -680,8 +684,8 @@ msgstr ""
#: src/pages/providers/ProviderListPage.ts:116
#: src/pages/providers/RelatedApplicationButton.ts:27
#: src/pages/providers/RelatedApplicationButton.ts:35
#: src/pages/sources/SourcesListPage.ts:100
#: src/pages/sources/SourcesListPage.ts:109
#: src/pages/sources/SourcesListPage.ts:115
#: src/pages/sources/SourcesListPage.ts:124
#: src/pages/stages/StageListPage.ts:119
#: src/pages/stages/StageListPage.ts:128
#: src/pages/stages/invitation/InvitationListPage.ts:77
@ -697,7 +701,7 @@ msgstr ""
msgid "Create"
msgstr ""
#: src/pages/applications/ApplicationListPage.ts:114
#: src/pages/applications/ApplicationListPage.ts:119
#: src/pages/providers/RelatedApplicationButton.ts:30
msgid "Create Application"
msgstr ""
@ -778,7 +782,7 @@ msgstr ""
#: src/pages/policies/PolicyListPage.ts:136
#: src/pages/property-mappings/PropertyMappingListPage.ts:125
#: src/pages/providers/ProviderListPage.ts:119
#: src/pages/sources/SourcesListPage.ts:112
#: src/pages/sources/SourcesListPage.ts:127
#: src/pages/stages/StageListPage.ts:131
msgid "Create {0}"
msgstr ""
@ -822,7 +826,7 @@ msgid "Define how notifications are sent to users, like Email or Webhook."
msgstr ""
#: src/elements/forms/DeleteForm.ts:79
#: src/pages/applications/ApplicationListPage.ts:102
#: src/pages/applications/ApplicationListPage.ts:107
#: src/pages/crypto/CertificateKeyPairListPage.ts:86
#: src/pages/events/RuleListPage.ts:82
#: src/pages/events/TransportListPage.ts:86
@ -833,7 +837,7 @@ msgstr ""
#: src/pages/policies/PolicyListPage.ts:115
#: src/pages/property-mappings/PropertyMappingListPage.ts:104
#: src/pages/providers/ProviderListPage.ts:98
#: src/pages/sources/SourcesListPage.ts:91
#: src/pages/sources/SourcesListPage.ts:106
#: src/pages/stages/StageListPage.ts:110
#: src/pages/stages/invitation/InvitationListPage.ts:68
#: src/pages/stages/prompt/PromptListPage.ts:87
@ -935,7 +939,7 @@ msgstr ""
msgid "Disable Time-based OTP"
msgstr ""
#: src/pages/sources/SourcesListPage.ts:60
#: src/pages/sources/SourcesListPage.ts:75
msgid "Disabled"
msgstr ""
@ -972,7 +976,7 @@ msgstr ""
#: src/pages/providers/oauth2/OAuth2ProviderViewPage.ts:139
#: src/pages/providers/proxy/ProxyProviderViewPage.ts:138
#: src/pages/providers/saml/SAMLProviderViewPage.ts:132
#: src/pages/sources/SourcesListPage.ts:79
#: src/pages/sources/SourcesListPage.ts:94
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:116
#: src/pages/sources/oauth/OAuthSourceViewPage.ts:135
#: src/pages/sources/saml/SAMLSourceViewPage.ts:122
@ -1588,8 +1592,8 @@ msgstr ""
msgid "Last seen: {0}"
msgstr ""
#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:23
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:150
#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:25
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:154
msgid "Last sync: {0}"
msgstr ""
@ -1946,11 +1950,11 @@ msgstr ""
msgid "Not found"
msgstr ""
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:148
msgid "Not synced in the last hour, check System tasks."
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:165
msgid "Not synced yet."
msgstr ""
#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:32
#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:40
msgid "Not synced."
msgstr ""
@ -2039,6 +2043,10 @@ msgstr ""
msgid "Only send notification once, for example when sending a webhook into a chat channel."
msgstr ""
#: src/pages/applications/ApplicationListPage.ts:95
msgid "Open application"
msgstr ""
#: src/pages/providers/oauth2/OAuth2ProviderViewPage.ts:172
msgid "OpenID Configuration Issuer"
msgstr ""
@ -2468,7 +2476,7 @@ msgstr ""
msgid "Result"
msgstr ""
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:163
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:177
#: src/pages/system-tasks/SystemTaskListPage.ts:107
msgid "Retry Task"
msgstr ""
@ -2585,7 +2593,7 @@ msgstr ""
msgid "Select a provider that this application should use. Alternatively, create a new provider."
msgstr ""
#: src/elements/table/Table.ts:215
#: src/elements/table/Table.ts:218
msgid "Select all rows"
msgstr ""
@ -2722,7 +2730,7 @@ msgid "Something went wrong! Please try again later."
msgstr ""
#: src/pages/providers/ProviderListPage.ts:91
#: src/pages/sources/SourcesListPage.ts:84
#: src/pages/sources/SourcesListPage.ts:99
msgid "Source"
msgstr ""
@ -3097,6 +3105,10 @@ msgstr ""
msgid "Sync"
msgstr ""
#: src/pages/admin-overview/cards/LDAPSyncStatusCard.ts:31
msgid "Sync failed."
msgstr ""
#: src/pages/sources/ldap/LDAPSourceForm.ts:93
msgid "Sync groups"
msgstr ""
@ -3138,6 +3150,14 @@ msgstr ""
msgid "Target"
msgstr ""
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:151
msgid "Task finished with errors"
msgstr ""
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:148
msgid "Task finished with warnings"
msgstr ""
#: src/pages/stages/email/EmailStageForm.ts:157
msgid "Template"
msgstr ""
@ -3345,7 +3365,7 @@ msgstr ""
#: src/pages/providers/oauth2/OAuth2ProviderViewPage.ts:129
#: src/pages/providers/proxy/ProxyProviderViewPage.ts:128
#: src/pages/providers/saml/SAMLProviderViewPage.ts:122
#: src/pages/sources/SourcesListPage.ts:66
#: src/pages/sources/SourcesListPage.ts:81
#: src/pages/sources/ldap/LDAPSourceViewPage.ts:106
#: src/pages/sources/oauth/OAuthSourceViewPage.ts:125
#: src/pages/sources/saml/SAMLSourceViewPage.ts:112
@ -3448,7 +3468,7 @@ msgstr ""
#: src/pages/policies/PolicyListPage.ts:80
#: src/pages/property-mappings/PropertyMappingListPage.ts:69
#: src/pages/providers/ProviderListPage.ts:76
#: src/pages/sources/SourcesListPage.ts:69
#: src/pages/sources/SourcesListPage.ts:84
#: src/pages/stages/StageListPage.ts:88
#: src/pages/users/UserActiveForm.ts:41
msgid "Update {0}"
@ -3708,6 +3728,10 @@ msgstr ""
msgid "You're currently impersonating {0}."
msgstr ""
#: src/pages/sources/SourcesListPage.ts:61
msgid "authentik Built-in"
msgstr ""
#: src/pages/stages/password/PasswordStageForm.ts:76
msgid "authentik Builtin Database"
msgstr ""

View File

@ -1,32 +1,40 @@
import { t } from "@lingui/macro";
import { customElement, html, property, TemplateResult } from "lit-element";
import { AdminStatus, AdminStatusCard } from "./AdminStatusCard";
import { SourcesApi } from "authentik-api";
import { SourcesApi, Task, TaskStatusEnum } from "authentik-api";
import { DEFAULT_CONFIG } from "../../../api/Config";
import "../../../elements/forms/ConfirmationForm";
@customElement("ak-admin-status-card-ldap-sync")
export class LDAPSyncStatusCard extends AdminStatusCard<Date | undefined> {
export class LDAPSyncStatusCard extends AdminStatusCard<Task> {
@property()
slug!: string;
getPrimaryValue(): Promise<Date | undefined> {
getPrimaryValue(): Promise<Task> {
return new SourcesApi(DEFAULT_CONFIG).sourcesLdapSyncStatus({
slug: this.slug
}).then((value) => {
return value.lastSync;
return value;
}).catch(() => {
return { status: TaskStatusEnum.Error } as Task;
});
}
renderValue(): TemplateResult {
return html`${t`Last sync: ${this.value?.toLocaleTimeString()}`}`;
return html`${t`Last sync: ${this.value?.taskFinishTimestamp.toLocaleTimeString()}`}`;
}
getStatus(value: Date | undefined): Promise<AdminStatus> {
getStatus(value: Task): Promise<AdminStatus> {
if (value.status !== TaskStatusEnum.Successful) {
return Promise.resolve<AdminStatus>({
icon: "fa fas fa-times-circle pf-m-danger",
message: t`Sync failed.`,
});
}
const now = new Date().getTime();
const maxDelta = 3600000; // 1 hour
if (!value || (now - value.getTime()) > maxDelta) {
if (!value || (now - value.taskFinishTimestamp.getTime()) > maxDelta) {
// No sync or last sync was over maxDelta ago
return Promise.resolve<AdminStatus>({
icon: "fa fa-exclamation-triangle pf-m-warning",

View File

@ -22,7 +22,7 @@ import "../../../elements/forms/ModalForm";
import "./LDAPSourceForm";
import { Page } from "../../../elements/Page";
import { until } from "lit-html/directives/until";
import { LDAPSource, SourcesApi } from "authentik-api";
import { LDAPSource, SourcesApi, TaskStatusEnum } from "authentik-api";
import { DEFAULT_CONFIG } from "../../../api/Config";
import { EVENT_REFRESH } from "../../../constants";
@ -143,16 +143,28 @@ export class LDAPSourceViewPage extends Page {
<p>${t`Sync status`}</p>
</div>
<div class="pf-c-card__body">
<p>
${until(new SourcesApi(DEFAULT_CONFIG).sourcesLdapSyncStatus({
slug: this.source.slug
}).then((ls) => {
if (!ls.lastSync) {
return t`Not synced in the last hour, check System tasks.`;
let header = html``;
if (ls.status === TaskStatusEnum.Warning) {
header = html`<p>${t`Task finished with warnings`}</p>`;
} else if (status === TaskStatusEnum.Error) {
header = html`<p>${t`Task finished with errors`}</p>`;
} else {
header = html`<p>${t`Last sync: ${ls.taskFinishTimestamp.toLocaleString()}`}</p>`;
}
return t`Last sync: ${ls.lastSync.toLocaleString()}`;
return html`
${header}
<ul>
${ls.messages.map(m => {
return html`<li>${m}</li>`;
})}
</ul>
`;
}).catch(() => {
return html`<p>${t`Not synced yet.`}</p>`;
}), "loading")}
</p>
</div>
<div class="pf-c-card__footer">
<ak-action-button