2023-12-10 15:40:13 +00:00
|
|
|
// Copyright (C) 2023 Nicola Murino
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
// by the Free Software Foundation, version 3.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2023-12-12 17:04:14 +00:00
|
|
|
"encoding/json"
|
2023-12-10 15:40:13 +00:00
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// localization id for the Web frontend
|
|
|
|
const (
|
2023-12-30 18:12:22 +00:00
|
|
|
I18nSetupTitle = "title.setup"
|
2023-12-10 15:40:13 +00:00
|
|
|
I18nLoginTitle = "title.login"
|
|
|
|
I18nShareLoginTitle = "title.share_login"
|
|
|
|
I18nFilesTitle = "title.files"
|
|
|
|
I18nSharesTitle = "title.shares"
|
|
|
|
I18nShareAddTitle = "title.add_share"
|
|
|
|
I18nShareUpdateTitle = "title.update_share"
|
|
|
|
I18nProfileTitle = "title.profile"
|
2024-01-14 08:41:39 +00:00
|
|
|
I18nUsersTitle = "title.users"
|
|
|
|
I18nGroupsTitle = "title.groups"
|
|
|
|
I18nFoldersTitle = "title.folders"
|
2023-12-10 15:40:13 +00:00
|
|
|
I18nChangePwdTitle = "title.change_password"
|
|
|
|
I18n2FATitle = "title.two_factor_auth"
|
|
|
|
I18nEditFileTitle = "title.edit_file"
|
|
|
|
I18nViewFileTitle = "title.view_file"
|
|
|
|
I18nForgotPwdTitle = "title.recovery_password"
|
|
|
|
I18nResetPwdTitle = "title.reset_password"
|
|
|
|
I18nSharedFilesTitle = "title.shared_files"
|
|
|
|
I18nShareUploadTitle = "title.upload_to_share"
|
|
|
|
I18nShareDownloadTitle = "title.download_shared_file"
|
|
|
|
I18nShareAccessErrorTitle = "title.share_access_error"
|
|
|
|
I18nInvalidAuthReqTitle = "title.invalid_auth_request"
|
|
|
|
I18nError403Title = "title.error403"
|
|
|
|
I18nError400Title = "title.error400"
|
2023-12-12 17:04:14 +00:00
|
|
|
I18nError404Title = "title.error404"
|
2023-12-10 15:40:13 +00:00
|
|
|
I18nError416Title = "title.error416"
|
|
|
|
I18nError429Title = "title.error429"
|
|
|
|
I18nError500Title = "title.error500"
|
|
|
|
I18nErrorPDFTitle = "title.errorPDF"
|
|
|
|
I18nErrorEditorTitle = "title.error_editor"
|
2024-01-09 18:54:08 +00:00
|
|
|
I18nAddUserTitle = "title.add_user"
|
|
|
|
I18nUpdateUserTitle = "title.update_user"
|
2024-01-22 19:22:41 +00:00
|
|
|
I18nAddAdminTitle = "title.add_admin"
|
|
|
|
I18nUpdateAdminTitle = "title.update_admin"
|
2024-01-09 18:54:08 +00:00
|
|
|
I18nTemplateUserTitle = "title.template_user"
|
2024-01-18 18:18:57 +00:00
|
|
|
I18nMaintenanceTitle = "title.maintenance"
|
|
|
|
I18nConfigsTitle = "title.configs"
|
|
|
|
I18nOAuth2Title = "title.oauth2_success"
|
|
|
|
I18nOAuth2ErrorTitle = "title.oauth2_error"
|
2024-01-20 14:35:05 +00:00
|
|
|
I18nSessionsTitle = "title.connections"
|
2024-01-21 15:49:04 +00:00
|
|
|
I18nRolesTitle = "title.roles"
|
2024-01-22 19:22:41 +00:00
|
|
|
I18nAdminsTitle = "title.admins"
|
2024-01-24 18:23:15 +00:00
|
|
|
I18nIPListsTitle = "title.ip_lists"
|
|
|
|
I18nAddIPListTitle = "title.add_ip_list"
|
|
|
|
I18nUpdateIPListTitle = "title.update_ip_list"
|
|
|
|
I18nDefenderTitle = "title.defender"
|
2024-01-28 18:38:01 +00:00
|
|
|
I18nEventsTitle = "title.logs"
|
2024-01-31 19:49:25 +00:00
|
|
|
I18nActionsTitle = "title.event_actions"
|
2024-02-01 19:32:43 +00:00
|
|
|
I18nRulesTitle = "title.event_rules"
|
2024-01-31 19:49:25 +00:00
|
|
|
I18nAddActionTitle = "title.add_action"
|
|
|
|
I18nUpdateActionTitle = "title.update_action"
|
2024-02-01 19:32:43 +00:00
|
|
|
I18nAddRuleTitle = "title.add_rule"
|
|
|
|
I18nUpdateRuleTitle = "title.update_rule"
|
2024-01-25 18:26:51 +00:00
|
|
|
I18nStatusTitle = "status.desc"
|
2023-12-30 18:12:22 +00:00
|
|
|
I18nErrorSetupInstallCode = "setup.install_code_mismatch"
|
2023-12-10 15:40:13 +00:00
|
|
|
I18nInvalidAuth = "general.invalid_auth_request"
|
|
|
|
I18nError429Message = "general.error429"
|
|
|
|
I18nError400Message = "general.error400"
|
|
|
|
I18nError403Message = "general.error403"
|
|
|
|
I18nError404Message = "general.error404"
|
|
|
|
I18nError416Message = "general.error416"
|
|
|
|
I18nError500Message = "general.error500"
|
|
|
|
I18nErrorPDFMessage = "general.errorPDF"
|
|
|
|
I18nErrorInvalidToken = "general.invalid_token"
|
|
|
|
I18nErrorInvalidForm = "general.invalid_form"
|
|
|
|
I18nErrorInvalidCredentials = "general.invalid_credentials"
|
|
|
|
I18nErrorInvalidCSRF = "general.invalid_csrf"
|
|
|
|
I18nErrorFsGeneric = "fs.err_generic"
|
|
|
|
I18nErrorDirListGeneric = "fs.dir_list.err_generic"
|
|
|
|
I18nErrorDirList403 = "fs.dir_list.err_403"
|
|
|
|
I18nErrorDirList429 = "fs.dir_list.err_429"
|
|
|
|
I18nErrorDirListUser = "fs.dir_list.err_user"
|
|
|
|
I18nErrorFsValidation = "fs.err_validation"
|
|
|
|
I18nErrorChangePwdRequiredFields = "change_pwd.required_fields"
|
|
|
|
I18nErrorChangePwdNoMatch = "change_pwd.no_match"
|
|
|
|
I18nErrorChangePwdGeneric = "change_pwd.generic"
|
|
|
|
I18nErrorChangePwdNoDifferent = "change_pwd.no_different"
|
|
|
|
I18nErrorChangePwdCurrentNoMatch = "change_pwd.current_no_match"
|
|
|
|
I18nErrorChangePwdRequired = "change_pwd.required"
|
|
|
|
I18nErrorUsernameRequired = "general.username_required"
|
2024-01-18 18:18:57 +00:00
|
|
|
I18nErrorPasswordRequired = "general.password_required"
|
|
|
|
I18nErrorPermissionsRequired = "general.permissions_required"
|
2023-12-10 15:40:13 +00:00
|
|
|
I18nErrorGetUser = "general.err_user"
|
|
|
|
I18nErrorPwdResetForbidded = "login.reset_pwd_forbidden"
|
|
|
|
I18nErrorPwdResetNoEmail = "login.reset_pwd_no_email"
|
|
|
|
I18nErrorPwdResetSendEmail = "login.reset_pwd_send_email_err"
|
|
|
|
I18nErrorPwdResetGeneric = "login.reset_pwd_err_generic"
|
|
|
|
I18nErrorProtocolForbidden = "general.err_protocol_forbidden"
|
|
|
|
I18nErrorPwdLoginForbidden = "general.pwd_login_forbidden"
|
|
|
|
I18nErrorIPForbidden = "general.ip_forbidden"
|
|
|
|
I18nErrorConnectionForbidden = "general.connection_forbidden"
|
|
|
|
I18nErrorReservedUsername = "user.username_reserved"
|
|
|
|
I18nErrorInvalidEmail = "general.email_invalid"
|
|
|
|
I18nErrorInvalidUser = "user.username_invalid"
|
2024-02-03 11:42:05 +00:00
|
|
|
I18nErrorInvalidName = "general.name_invalid"
|
2023-12-10 15:40:13 +00:00
|
|
|
I18nErrorHomeRequired = "user.home_required"
|
|
|
|
I18nErrorHomeInvalid = "user.home_invalid"
|
|
|
|
I18nErrorPubKeyInvalid = "user.pub_key_invalid"
|
2024-02-25 10:12:57 +00:00
|
|
|
I18nErrorPrivKeyInvalid = "user.priv_key_invalid"
|
|
|
|
I18nErrorKeySizeInvalid = "user.key_invalid_size"
|
2023-12-10 15:40:13 +00:00
|
|
|
I18nErrorPrimaryGroup = "user.err_primary_group"
|
|
|
|
I18nErrorDuplicateGroup = "user.err_duplicate_group"
|
|
|
|
I18nErrorNoPermission = "user.no_permissions"
|
|
|
|
I18nErrorNoRootPermission = "user.no_root_permissions"
|
|
|
|
I18nErrorGenericPermission = "user.err_permissions_generic"
|
|
|
|
I18nError2FAInvalid = "user.2fa_invalid"
|
|
|
|
I18nErrorRecoveryCodesInvalid = "user.recovery_codes_invalid"
|
|
|
|
I18nErrorFolderNameRequired = "general.foldername_required"
|
|
|
|
I18nErrorFolderMountPathRequired = "user.folder_path_required"
|
|
|
|
I18nErrorDuplicatedFolders = "user.folder_duplicated"
|
|
|
|
I18nErrorOverlappedFolders = "user.folder_overlapped"
|
|
|
|
I18nErrorFolderQuotaSizeInvalid = "user.folder_quota_size_invalid"
|
|
|
|
I18nErrorFolderQuotaFileInvalid = "user.folder_quota_file_invalid"
|
|
|
|
I18nErrorFolderQuotaInvalid = "user.folder_quota_invalid"
|
|
|
|
I18nErrorPasswordComplexity = "general.err_password_complexity"
|
|
|
|
I18nErrorIPFiltersInvalid = "user.ip_filters_invalid"
|
|
|
|
I18nErrorSourceBWLimitInvalid = "user.src_bw_limits_invalid"
|
|
|
|
I18nErrorShareExpirationInvalid = "user.share_expiration_invalid"
|
|
|
|
I18nErrorFilePatternPathInvalid = "user.file_pattern_path_invalid"
|
|
|
|
I18nErrorFilePatternDuplicated = "user.file_pattern_duplicated"
|
|
|
|
I18nErrorFilePatternInvalid = "user.file_pattern_invalid"
|
|
|
|
I18nErrorDisableActive2FA = "user.disable_active_2fa"
|
|
|
|
I18nErrorPwdChangeConflict = "user.pwd_change_conflict"
|
2024-02-22 17:20:51 +00:00
|
|
|
I18nError2FAConflict = "user.two_factor_conflict"
|
2023-12-10 15:40:13 +00:00
|
|
|
I18nErrorLoginAfterReset = "login.reset_ok_login_error"
|
|
|
|
I18nErrorShareScope = "share.scope_invalid"
|
|
|
|
I18nErrorShareMaxTokens = "share.max_tokens_invalid"
|
|
|
|
I18nErrorShareExpiration = "share.expiration_invalid"
|
|
|
|
I18nErrorShareNoPwd = "share.err_no_password"
|
|
|
|
I18nErrorShareExpirationOutOfRange = "share.expiration_out_of_range"
|
|
|
|
I18nErrorShareGeneric = "share.generic"
|
|
|
|
I18nErrorNameRequired = "general.name_required"
|
|
|
|
I18nErrorSharePathRequired = "share.path_required"
|
|
|
|
I18nErrorShareWriteScope = "share.path_write_scope"
|
|
|
|
I18nErrorShareNestedPaths = "share.nested_paths"
|
|
|
|
I18nErrorShareExpirationPast = "share.expiration_past"
|
|
|
|
I18nErrorInvalidIPMask = "general.allowed_ip_mask_invalid"
|
|
|
|
I18nErrorShareUsage = "share.usage_exceed"
|
|
|
|
I18nErrorShareExpired = "share.expired"
|
|
|
|
I18nErrorLoginFromIPDenied = "login.ip_not_allowed"
|
|
|
|
I18nError2FARequired = "login.two_factor_required"
|
2024-02-21 19:45:10 +00:00
|
|
|
I18nError2FARequiredGeneric = "login.two_factor_required_generic"
|
2023-12-10 15:40:13 +00:00
|
|
|
I18nErrorNoOIDCFeature = "general.no_oidc_feature"
|
|
|
|
I18nErrorNoPermissions = "general.no_permissions"
|
|
|
|
I18nErrorShareBrowsePaths = "share.browsable_multiple_paths"
|
|
|
|
I18nErrorShareBrowseNoDir = "share.browsable_non_dir"
|
2023-12-28 17:43:07 +00:00
|
|
|
I18nErrorShareInvalidPath = "share.invalid_path"
|
2023-12-10 15:40:13 +00:00
|
|
|
I18nErrorPathInvalid = "general.path_invalid"
|
|
|
|
I18nErrorQuotaRead = "general.err_quota_read"
|
|
|
|
I18nErrorEditDir = "general.error_edit_dir"
|
|
|
|
I18nErrorEditSize = "general.error_edit_size"
|
|
|
|
I18nProfileUpdated = "general.profile_updated"
|
|
|
|
I18nShareLoginOK = "general.share_ok"
|
|
|
|
I18n2FADisabled = "2fa.disabled"
|
2023-12-12 17:04:14 +00:00
|
|
|
I18nOIDCTokenExpired = "oidc.token_expired"
|
|
|
|
I18nOIDCTokenInvalidAdmin = "oidc.token_invalid_webadmin"
|
|
|
|
I18nOIDCTokenInvalidUser = "oidc.token_invalid_webclient"
|
|
|
|
I18nOIDCErrTokenExchange = "oidc.token_exchange_err"
|
|
|
|
I18nOIDCTokenInvalid = "oidc.token_invalid"
|
|
|
|
I18nOIDCTokenInvalidRoleAdmin = "oidc.role_admin_err"
|
|
|
|
I18nOIDCTokenInvalidRoleUser = "oidc.role_user_err"
|
|
|
|
I18nOIDCErrGetUser = "oidc.get_user_err"
|
2024-01-09 18:54:08 +00:00
|
|
|
I18nErrorInvalidQuotaSize = "user.invalid_quota_size"
|
2024-03-17 10:30:03 +00:00
|
|
|
I18nErrorTimeOfDayInvalid = "user.time_of_day_invalid"
|
|
|
|
I18nErrorTimeOfDayConflict = "user.time_of_day_conflict"
|
2024-01-09 18:54:08 +00:00
|
|
|
I18nErrorInvalidMaxFilesize = "filters.max_upload_size_invalid"
|
2024-01-11 18:26:13 +00:00
|
|
|
I18nErrorInvalidHomeDir = "storage.home_dir_invalid"
|
|
|
|
I18nErrorBucketRequired = "storage.bucket_required"
|
|
|
|
I18nErrorRegionRequired = "storage.region_required"
|
|
|
|
I18nErrorKeyPrefixInvalid = "storage.key_prefix_invalid"
|
|
|
|
I18nErrorULPartSizeInvalid = "storage.ul_part_size_invalid"
|
|
|
|
I18nErrorDLPartSizeInvalid = "storage.dl_part_size_invalid"
|
|
|
|
I18nErrorULConcurrencyInvalid = "storage.ul_concurrency_invalid"
|
|
|
|
I18nErrorDLConcurrencyInvalid = "storage.dl_concurrency_invalid"
|
|
|
|
I18nErrorAccessKeyRequired = "storage.access_key_required"
|
|
|
|
I18nErrorAccessSecretRequired = "storage.access_secret_required"
|
|
|
|
I18nErrorFsCredentialsRequired = "storage.credentials_required"
|
|
|
|
I18nErrorContainerRequired = "storage.container_required"
|
|
|
|
I18nErrorAccountNameRequired = "storage.account_name_required"
|
|
|
|
I18nErrorSASURLInvalid = "storage.sas_url_invalid"
|
|
|
|
I18nErrorPassphraseRequired = "storage.passphrase_required"
|
|
|
|
I18nErrorEndpointInvalid = "storage.endpoint_invalid"
|
|
|
|
I18nErrorEndpointRequired = "storage.endpoint_required"
|
|
|
|
I18nErrorFsUsernameRequired = "storage.username_required"
|
2024-01-14 08:09:42 +00:00
|
|
|
I18nAddGroupTitle = "title.add_group"
|
|
|
|
I18nUpdateGroupTitle = "title.update_group"
|
2024-01-21 16:19:25 +00:00
|
|
|
I18nRoleAddTitle = "title.add_role"
|
|
|
|
I18nRoleUpdateTitle = "title.update_role"
|
2024-01-14 20:36:23 +00:00
|
|
|
I18nErrorInvalidTLSCert = "user.tls_cert_invalid"
|
2024-01-16 18:51:37 +00:00
|
|
|
I18nAddFolderTitle = "title.add_folder"
|
|
|
|
I18nUpdateFolderTitle = "title.update_folder"
|
|
|
|
I18nTemplateFolderTitle = "title.template_folder"
|
2024-01-17 16:36:35 +00:00
|
|
|
I18nErrorDuplicatedUsername = "general.duplicated_username"
|
|
|
|
I18nErrorDuplicatedName = "general.duplicated_name"
|
2024-01-24 18:23:15 +00:00
|
|
|
I18nErrorDuplicatedIPNet = "ip_list.duplicated"
|
2024-01-18 18:18:57 +00:00
|
|
|
I18nErrorRoleAdminPerms = "admin.role_permissions"
|
2024-01-26 20:03:41 +00:00
|
|
|
I18nBackupOK = "maintenance.backup_ok"
|
2024-01-18 18:18:57 +00:00
|
|
|
I18nErrorFolderTemplate = "virtual_folders.template_no_folder"
|
|
|
|
I18nErrorUserTemplate = "user.template_no_user"
|
|
|
|
I18nConfigsOK = "general.configs_saved"
|
|
|
|
I18nOAuth2ErrorVerifyState = "oauth2.auth_verify_error"
|
|
|
|
I18nOAuth2ErrorValidateState = "oauth2.auth_validation_error"
|
|
|
|
I18nOAuth2InvalidState = "oauth2.auth_invalid"
|
|
|
|
I18nOAuth2ErrTokenExchange = "oauth2.token_exchange_err"
|
|
|
|
I18nOAuth2ErrNoRefreshToken = "oauth2.no_refresh_token"
|
|
|
|
I18nOAuth2OK = "oauth2.success"
|
2024-01-22 19:22:41 +00:00
|
|
|
I18nErrorAdminSelfPerms = "admin.self_permissions"
|
|
|
|
I18nErrorAdminSelfDisable = "admin.self_disable"
|
|
|
|
I18nErrorAdminSelfRole = "admin.self_role"
|
2024-01-28 09:22:16 +00:00
|
|
|
I18nErrorIPInvalid = "ip_list.ip_invalid"
|
2024-01-24 18:23:15 +00:00
|
|
|
I18nErrorNetInvalid = "ip_list.net_invalid"
|
2024-01-25 18:26:51 +00:00
|
|
|
I18nFTPTLSDisabled = "status.tls_disabled"
|
|
|
|
I18nFTPTLSExplicit = "status.tls_explicit"
|
|
|
|
I18nFTPTLSImplicit = "status.tls_implicit"
|
|
|
|
I18nFTPTLSMixed = "status.tls_mixed"
|
2024-01-26 20:03:41 +00:00
|
|
|
I18nErrorBackupFile = "maintenance.backup_invalid_file"
|
|
|
|
I18nErrorRestore = "maintenance.restore_error"
|
2024-01-27 11:48:15 +00:00
|
|
|
I18nErrorACMEGeneric = "acme.generic_error"
|
|
|
|
I18nErrorSMTPRequiredFields = "smtp.err_required_fields"
|
|
|
|
I18nErrorSMTPClientIDRequired = "smtp.client_id_required"
|
|
|
|
I18nErrorSMTPClientSecretRequired = "smtp.client_secret_required"
|
|
|
|
I18nErrorSMTPRefreshTokenRequired = "smtp.refresh_token_required"
|
2024-01-31 19:49:25 +00:00
|
|
|
I18nErrorURLRequired = "actions.http_url_required"
|
|
|
|
I18nErrorURLInvalid = "actions.http_url_invalid"
|
|
|
|
I18nErrorHTTPPartNameRequired = "actions.http_part_name_required"
|
|
|
|
I18nErrorHTTPPartBodyRequired = "actions.http_part_body_required"
|
|
|
|
I18nErrorMultipartBody = "actions.http_multipart_body_error"
|
|
|
|
I18nErrorMultipartCType = "actions.http_multipart_ctype_error"
|
|
|
|
I18nErrorPathDuplicated = "actions.path_duplicated"
|
|
|
|
I18nErrorCommandRequired = "actions.command_required"
|
|
|
|
I18nErrorCommandInvalid = "actions.command_invalid"
|
|
|
|
I18nErrorEmailRecipientRequired = "actions.email_recipient_required"
|
|
|
|
I18nErrorEmailSubjectRequired = "actions.email_subject_required"
|
|
|
|
I18nErrorEmailBodyRequired = "actions.email_body_required"
|
|
|
|
I18nErrorRetentionDirRequired = "actions.retention_directory_required"
|
|
|
|
I18nErrorPathRequired = "actions.path_required"
|
|
|
|
I18nErrorSourceDestMatch = "actions.source_dest_different"
|
|
|
|
I18nErrorRootNotAllowed = "actions.root_not_allowed"
|
|
|
|
I18nErrorArchiveNameRequired = "actions.archive_name_required"
|
|
|
|
I18nErrorIDPTemplateRequired = "actions.idp_template_required"
|
|
|
|
I18nActionTypeHTTP = "actions.types.http"
|
|
|
|
I18nActionTypeEmail = "actions.types.email"
|
|
|
|
I18nActionTypeBackup = "actions.types.backup"
|
|
|
|
I18nActionTypeUserQuotaReset = "actions.types.user_quota_reset"
|
|
|
|
I18nActionTypeFolderQuotaReset = "actions.types.folder_quota_reset"
|
|
|
|
I18nActionTypeTransferQuotaReset = "actions.types.transfer_quota_reset"
|
|
|
|
I18nActionTypeDataRetentionCheck = "actions.types.data_retention_check"
|
|
|
|
I18nActionTypeFilesystem = "actions.types.filesystem"
|
|
|
|
I18nActionTypePwdExpirationCheck = "actions.types.password_expiration_check"
|
|
|
|
I18nActionTypeUserExpirationCheck = "actions.types.user_expiration_check"
|
2024-03-04 18:48:10 +00:00
|
|
|
I18nActionTypeUserInactivityCheck = "actions.types.user_inactivity_check"
|
2024-01-31 19:49:25 +00:00
|
|
|
I18nActionTypeIDPCheck = "actions.types.idp_check"
|
|
|
|
I18nActionTypeCommand = "actions.types.command"
|
|
|
|
I18nActionFsTypeRename = "actions.fs_types.rename"
|
|
|
|
I18nActionFsTypeDelete = "actions.fs_types.delete"
|
|
|
|
I18nActionFsTypePathExists = "actions.fs_types.path_exists"
|
|
|
|
I18nActionFsTypeCompress = "actions.fs_types.compress"
|
|
|
|
I18nActionFsTypeCopy = "actions.fs_types.copy"
|
|
|
|
I18nActionFsTypeCreateDirs = "actions.fs_types.create_dirs"
|
2024-03-04 18:48:10 +00:00
|
|
|
I18nActionThresholdRequired = "actions.inactivity_threshold_required"
|
|
|
|
I18nActionThresholdsInvalid = "actions.inactivity_thresholds_invalid"
|
2024-02-01 19:32:43 +00:00
|
|
|
I18nTriggerFsEvent = "rules.triggers.fs_event"
|
|
|
|
I18nTriggerProviderEvent = "rules.triggers.provider_event"
|
|
|
|
I18nTriggerIPBlockedEvent = "rules.triggers.ip_blocked"
|
|
|
|
I18nTriggerCertificateRenewEvent = "rules.triggers.certificate_renewal"
|
|
|
|
I18nTriggerOnDemandEvent = "rules.triggers.on_demand"
|
|
|
|
I18nTriggerIDPLoginEvent = "rules.triggers.idp_login"
|
|
|
|
I18nTriggerScheduleEvent = "rules.triggers.schedule"
|
|
|
|
I18nErrorInvalidMinSize = "rules.invalid_fs_min_size"
|
|
|
|
I18nErrorInvalidMaxSize = "rules.invalid_fs_max_size"
|
|
|
|
I18nErrorRuleActionRequired = "rules.action_required"
|
|
|
|
I18nErrorRuleFsEventRequired = "rules.fs_event_required"
|
|
|
|
I18nErrorRuleProviderEventRequired = "rules.provider_event_required"
|
|
|
|
I18nErrorRuleScheduleRequired = "rules.schedule_required"
|
|
|
|
I18nErrorRuleScheduleInvalid = "rules.schedule_invalid"
|
|
|
|
I18nErrorRuleDuplicateActions = "rules.duplicate_actions"
|
|
|
|
I18nErrorEvSyncFailureActions = "rules.sync_failure_actions"
|
|
|
|
I18nErrorEvSyncUnsupported = "rules.sync_unsupported"
|
|
|
|
I18nErrorEvSyncUnsupportedFs = "rules.sync_unsupported_fs_event"
|
|
|
|
I18nErrorRuleFailureActionsOnly = "rules.only_failure_actions"
|
|
|
|
I18nErrorRuleSyncActionRequired = "rules.sync_action_required"
|
2023-12-10 15:40:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewI18nError returns a I18nError wrappring the provided error
|
2023-12-12 17:04:14 +00:00
|
|
|
func NewI18nError(err error, message string, options ...I18nErrorOption) *I18nError {
|
2023-12-10 15:40:13 +00:00
|
|
|
var errI18n *I18nError
|
|
|
|
if errors.As(err, &errI18n) {
|
|
|
|
return errI18n
|
|
|
|
}
|
2023-12-12 17:04:14 +00:00
|
|
|
errI18n = &I18nError{
|
|
|
|
err: err,
|
|
|
|
Message: message,
|
|
|
|
args: nil,
|
|
|
|
}
|
|
|
|
for _, opt := range options {
|
|
|
|
opt(errI18n)
|
|
|
|
}
|
|
|
|
return errI18n
|
|
|
|
}
|
|
|
|
|
|
|
|
// I18nErrorOption defines a functional option type that allows to configure the I18nError.
|
|
|
|
type I18nErrorOption func(*I18nError)
|
|
|
|
|
|
|
|
// I18nErrorArgs is a functional option to set I18nError arguments.
|
|
|
|
func I18nErrorArgs(args map[string]any) I18nErrorOption {
|
|
|
|
return func(e *I18nError) {
|
|
|
|
e.args = args
|
2023-12-10 15:40:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// I18nError is an error wrapper that add a message to use for localization.
|
|
|
|
type I18nError struct {
|
2023-12-12 17:04:14 +00:00
|
|
|
err error
|
|
|
|
Message string
|
|
|
|
args map[string]any
|
2023-12-10 15:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Error returns the wrapped error string.
|
|
|
|
func (e *I18nError) Error() string {
|
|
|
|
return e.err.Error()
|
|
|
|
}
|
|
|
|
|
2023-12-12 17:04:14 +00:00
|
|
|
// Unwrap returns the underlying error
|
|
|
|
func (e *I18nError) Unwrap() error {
|
|
|
|
return e.err
|
|
|
|
}
|
|
|
|
|
2023-12-10 15:40:13 +00:00
|
|
|
// Is reports if target matches
|
|
|
|
func (e *I18nError) Is(target error) bool {
|
|
|
|
if errors.Is(e.err, target) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
_, ok := target.(*I18nError)
|
|
|
|
return ok
|
|
|
|
}
|
2023-12-12 17:04:14 +00:00
|
|
|
|
|
|
|
// HasArgs returns true if the error has i18n args.
|
|
|
|
func (e *I18nError) HasArgs() bool {
|
|
|
|
return len(e.args) > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Args returns the provided args in JSON format
|
|
|
|
func (e *I18nError) Args() string {
|
|
|
|
if len(e.args) > 0 {
|
|
|
|
data, err := json.Marshal(e.args)
|
|
|
|
if err == nil {
|
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "{}"
|
|
|
|
}
|