(dir: string, config: GlobalConfig = {})
| 451 | } |
| 452 | |
| 453 | export function CredentialsStore(dir: string, config: GlobalConfig = {}) { |
| 454 | const configPath = cliConfig.getAuthConfigFilePath(dir); |
| 455 | const cliAuthConfig = resolveCliAuthConfig(dir, config); |
| 456 | const tokenStorage = cliAuthConfig.credStorage; |
| 457 | |
| 458 | return { |
| 459 | configPath, |
| 460 | get(): Credentials { |
| 461 | switch (tokenStorage) { |
| 462 | case 'file': |
| 463 | return readFileStorageCredentials(configPath, cliAuthConfig); |
| 464 | case 'keyring': |
| 465 | return readKeyringStorageCredentials(configPath, cliAuthConfig); |
| 466 | case 'auto': |
| 467 | return readAutoStorageCredentials(configPath, cliAuthConfig); |
| 468 | } |
| 469 | |
| 470 | throw new Error(`Unsupported credStorage: ${tokenStorage}`); |
| 471 | }, |
| 472 | update(config: Partial<Credentials>): CredentialsStorageLocation | void { |
| 473 | if (config.skipWrite) return; |
| 474 | const parsedConfig = parseCredentials(config); |
| 475 | switch (tokenStorage) { |
| 476 | case 'file': |
| 477 | return writeFileStorageCredentials( |
| 478 | configPath, |
| 479 | parsedConfig, |
| 480 | cliAuthConfig |
| 481 | ); |
| 482 | case 'keyring': |
| 483 | return writeKeyringStorageCredentials( |
| 484 | configPath, |
| 485 | parsedConfig, |
| 486 | cliAuthConfig |
| 487 | ); |
| 488 | case 'auto': |
| 489 | return writeAutoStorageCredentials( |
| 490 | configPath, |
| 491 | parsedConfig, |
| 492 | cliAuthConfig |
| 493 | ); |
| 494 | } |
| 495 | |
| 496 | throw new Error(`Unsupported credStorage: ${tokenStorage}`); |
| 497 | }, |
| 498 | delete(): void { |
| 499 | switch (tokenStorage) { |
| 500 | case 'file': |
| 501 | deleteFileStorageCredentials(configPath, cliAuthConfig); |
| 502 | break; |
| 503 | case 'keyring': |
| 504 | deleteKeyringStorageCredentials(configPath, cliAuthConfig); |
| 505 | break; |
| 506 | case 'auto': |
| 507 | deleteAutoStorageCredentials(configPath, cliAuthConfig); |
| 508 | break; |
| 509 | } |
| 510 | }, |
no test coverage detected