<commit_before>'use strict';

const EventEmitter = require('events').EventEmitter;
const STATUS = require('./utils/status');

/**
 * The LeaseManager maintains state about a token or secret. It leverages a
 * SecretProvider object to handle interaction with Vault.
 */
class LeaseManager extends EventEmitter {
  /**
   * Create a new instance of a LeaseManager with the given SecretProvider
   * @param {TokenProvider|GenericProvider} provider
   */
  constructor(provider) {
    super();

    this.status = STATUS.PENDING;
    this.data = null;
    this.lease_duration = 0;
    this.provider = provider;
    this.error = null;
  }

  /**
   * Initialize the SecretProvider
   * @returns {Promise}
   */
  initialize() {
    return this.provider.initialize().then((result) => {
      this.status = STATUS.READY;
      this.data = result.data;
      this.lease_duration = result.lease_duration;
      this.emit('ready');
      this.error = null;
      this._renew();
      return Promise.resolve(this);
    }).catch((err) => {
      this.status = STATUS.PENDING;
      this.data = null;<commit_msg>Added TODO to note how bad LeaseManager#initialize() is.<commit_after>'use strict';

const EventEmitter = require('events').EventEmitter;
const STATUS = require('./utils/status');

/**
 * The LeaseManager maintains state about a token or secret. It leverages a
 * SecretProvider object to handle interaction with Vault.
 */
class LeaseManager extends EventEmitter {
  /**
   * Create a new instance of a LeaseManager with the given SecretProvider
   * @param {TokenProvider|GenericProvider} provider
   */
  constructor(provider) {
    super();

    this.status = STATUS.PENDING;
    this.data = null;
    this.lease_duration = 0;
    this.provider = provider;
    this.error = null;
  }

  /**
   * Initialize the SecretProvider
   *
   * TODO: Make this method way less problematic
   *
   * @returns {Promise}
   */
  initialize() {
    return this.provider.initialize().then((result) => {
      this.status = STATUS.READY;
      this.data = result.data;
      this.lease_duration = result.lease_duration;
      this.emit('ready');
      this.error = null;
      this._renew();
      return Promise.resolve(this);
    }).catch((err) => {
      this.status = STATUS.PENDING;
      this.data = null;
{'fraction_non_alphanumeric': 0.12097476066144473, 'fraction_numerical': 0.0008703220191470844, 'mean_word_length': 3.0475352112676055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1835156', 'n_tokens_mistral': 665, 'n_tokens_neox': 662, 'n_words': 177}