async getPassword()

in src/core/swa-cli-persistence-plugin/impl/credentials-store.ts [38:79]


  async getPassword(service: string, account: string): Promise<string | null> {
    logger.silly("Getting credentials from native keychain");

    const keychain = await this.requireKeychain();
    logger.silly("Got native keychain reference");

    const credentials = await keychain.getPassword(service, account);
    logger.silly("Got credentials from native keychain: " + (credentials ? "<hidden>" : "<empty>"));

    if (credentials) {
      logger.silly("Credentials found in native keychain");

      try {
        let { content, hasNextChunk }: ChunkedData = JSON.parse(credentials);

        if (!content || !hasNextChunk) {
          return credentials;
        }

        logger.silly("Credentials is chunked. Reading all chunks...");

        let index = 1;
        while (hasNextChunk) {
          const nextChunk = await keychain.getPassword(service, `${account}-${index}`);
          const result: ChunkedData = JSON.parse(nextChunk!);
          content += result.content;
          hasNextChunk = result.hasNextChunk;
          index++;
        }

        logger.silly("Got all chunks successfully");
        return content;
      } catch {
        logger.silly("Credentials is not chunked");
        logger.silly("Returning credentials as is");
        return credentials;
      }
    }

    logger.silly("Credentials not found in native keychain");
    return credentials;
  }