( baseName: string, existingSecretIds: Iterable<string>, fallbackId = "secret", )
| 25 | } |
| 26 | |
| 27 | export function getUniqueSecretId( |
| 28 | baseName: string, |
| 29 | existingSecretIds: Iterable<string>, |
| 30 | fallbackId = "secret", |
| 31 | ): string { |
| 32 | const baseId = slugifyForSecretId(baseName) || fallbackId; |
| 33 | if (!baseId) return ""; |
| 34 | if (!isSecretIdTaken(baseId, existingSecretIds)) return baseId; |
| 35 | |
| 36 | let suffix = 2; |
| 37 | while (isSecretIdTaken(`${baseId}-${suffix}`, existingSecretIds)) { |
| 38 | suffix += 1; |
| 39 | } |
| 40 | return `${baseId}-${suffix}`; |
| 41 | } |
no test coverage detected