Skip to content

Commit af51bfa

Browse files
committed
script delete fix
1 parent ae86c15 commit af51bfa

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

KeeperSdk/src/pam/rotation/rotationScriptHelpers.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Auth, DRecord } from '@keeper-security/keeperapi'
44
import type { InMemoryStorage } from '../../storage/InMemoryStorage'
55
import { VaultObjectKind } from '../../folders/folderHelpers'
66
import { getRecordTitle, getRecordType } from '../../records/RecordUtils'
7+
import { PAM_RESOURCES_FIELD_TYPE } from '../config/configConstants'
78
import { updateRecord } from '../../records/RecordOperations'
89
import { KeeperSdkError, ResultCodes } from '../../utils'
910
import { SCRIPT_FIELD_TYPE } from './rotationConstants'
@@ -25,11 +26,7 @@ export function findPamRecordsByName(storage: InMemoryStorage, searchText: strin
2526
for (const record of allRecords) {
2627
if (!record) continue
2728

28-
const recordType = getRecordType(record)
29-
if (recordType !== 'pamUser' && recordType !== 'pamDirectory') {
30-
continue
31-
}
32-
if (!isPamRecord(record)) continue
29+
if (!isPamRotationRecord(record)) continue
3330

3431
const title = getRecordTitle(record) || ''
3532
if (
@@ -56,6 +53,17 @@ export function isPamRecord(record: DRecord): record is PamRecord {
5653
return isPamRecordData(record.data)
5754
}
5855

56+
function isPamRotationRecord(record: DRecord): record is PamRecord {
57+
if (!isPamRecord(record)) return false
58+
59+
const recordType = getRecordType(record)
60+
return (
61+
recordType === 'pamUser' ||
62+
recordType === 'pamDirectory' ||
63+
record.data.fields.some((field) => field?.type === PAM_RESOURCES_FIELD_TYPE)
64+
)
65+
}
66+
5967
export function getSinglePamRecord(storage: InMemoryStorage, recordName: string): PamRecord {
6068
const recordNameTrimmed = recordName?.trim()
6169
if (!recordNameTrimmed) {
@@ -75,15 +83,7 @@ export function getSinglePamRecord(storage: InMemoryStorage, recordName: string)
7583
}
7684

7785
const record = records[0]
78-
const recordType = getRecordType(record)
79-
if (recordType !== 'pamUser' && recordType !== 'pamDirectory') {
80-
throw new KeeperSdkError(
81-
`Record "${recordNameTrimmed}" is not a PAM record (pamUser/pamDirectory)`,
82-
ResultCodes.PAM_CONFIG_INVALID
83-
)
84-
}
85-
86-
if (!isPamRecord(record)) {
86+
if (!isPamRotationRecord(record)) {
8787
throw new KeeperSdkError(
8888
`PAM record "${recordNameTrimmed}" has invalid record data`,
8989
ResultCodes.PAM_CONFIG_INVALID

0 commit comments

Comments
 (0)