|
| 1 | +/** |
| 2 | + * Copyright (c) HashiCorp, Inc. |
| 3 | + * SPDX-License-Identifier: BUSL-1.1 |
| 4 | + */ |
| 5 | + |
| 6 | +import { baseResourceFactory } from 'vault/resources/base-factory'; |
| 7 | +import { service } from '@ember/service'; |
| 8 | +import { supportedTypes } from 'vault/utils/supported-login-methods'; |
| 9 | +import engineDisplayData from 'vault/helpers/engines-display-data'; |
| 10 | + |
| 11 | +import type { SecretsEngine } from 'vault/secrets/engine'; |
| 12 | +import type VersionService from 'vault/services/version'; |
| 13 | +import type NamespaceService from 'vault/services/namespace'; |
| 14 | +import type { PathInfo } from 'vault/utils/openapi-helpers'; |
| 15 | + |
| 16 | +export default class AuthMethodResource extends baseResourceFactory<SecretsEngine>() { |
| 17 | + @service declare readonly version: VersionService; |
| 18 | + @service declare readonly namespace: NamespaceService; |
| 19 | + |
| 20 | + id: string; |
| 21 | + declare paths: PathInfo; |
| 22 | + |
| 23 | + constructor(data: SecretsEngine, context: unknown) { |
| 24 | + super(data, context); |
| 25 | + // strip trailing slash from path for id since it is used in routing |
| 26 | + this.id = data.path.replace(/\/$/, ''); |
| 27 | + } |
| 28 | + |
| 29 | + // namespaces introduced types with a `ns_` prefix for built-in engines |
| 30 | + // so we need to strip that to normalize the type |
| 31 | + get methodType() { |
| 32 | + return this.type.replace(/^ns_/, ''); |
| 33 | + } |
| 34 | + |
| 35 | + get icon() { |
| 36 | + // methodType refers to the backend type (e.g., "aws", "azure") |
| 37 | + const engineData = engineDisplayData(this.methodType); |
| 38 | + return engineData?.glyph || 'users'; |
| 39 | + } |
| 40 | + |
| 41 | + get directLoginLink() { |
| 42 | + const ns = this.namespace.path; |
| 43 | + const nsQueryParam = ns ? `namespace=${encodeURIComponent(ns)}&` : ''; |
| 44 | + const isSupported = supportedTypes(this.version.isEnterprise).includes(this.methodType); |
| 45 | + return isSupported |
| 46 | + ? `${window.origin}/ui/vault/auth?${nsQueryParam}with=${encodeURIComponent(this.path)}` |
| 47 | + : ''; |
| 48 | + } |
| 49 | + |
| 50 | + // used when the `auth` prefix is important, |
| 51 | + // currently only when setting perf mount filtering |
| 52 | + get apiPath() { |
| 53 | + return `auth/${this.path}`; |
| 54 | + } |
| 55 | + |
| 56 | + get localDisplay() { |
| 57 | + return this.local ? 'local' : 'replicated'; |
| 58 | + } |
| 59 | + |
| 60 | + get supportsUserLockoutConfig() { |
| 61 | + return ['approle', 'ldap', 'userpass'].includes(this.methodType); |
| 62 | + } |
| 63 | +} |
0 commit comments