Sha256: 55083cdf6e2158ff73d5b6341752688310e93f2966f5c718121a6049db553787

Contents?: true

Size: 1.62 KB

Versions: 21

Compression:

Stored size: 1.62 KB

Contents

require 'uuidtools'

module Vault
  module User
    # Convert a user ID into a Heroku user ID.
    #
    # @param user_id [Fixnum] A user ID.
    # @return [String] A Heroku ID that uniquely represents the user.
    def self.id_to_hid(user_id)
      "user#{user_id}@heroku.com"
    end

    # Convert a user ID into a v5 UUID.
    #
    # @param user_id [Fixnum] A user ID.
    # @return [String] A v5 UUID that uniquely represents the user.
    def self.id_to_uuid(user_id)
      url = "https://vault.heroku.com/users/#{user_id}"
      UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
    end

    # Convert a Heroku user ID into a core user ID.
    #
    # @param heroku_id [String] A Heroku user ID, such as
    #   `user1234@heroku.com`.
    # @raise [ArgumentError] Raised if a malformed Heroku ID is provided.
    # @return [Fixnum] The core user ID that uniquely represents the user.
    def self.hid_to_id(heroku_id)
      if user_id = heroku_id.slice(/^user(\d+)\@heroku\.com$/, 1)
        user_id.to_i
      else
        raise ArgumentError,"#{heroku_id} is not a valid Heroku user ID."
      end
    end

    # Convert a Heroku user ID into a v5 UUID.
    #
    # @param heroku_id [String] A Heroku user ID, such as
    #   `user1234@heroku.com`.
    # @raise [ArgumentError] Raised if a malformed Heroku ID is provided.
    # @return [String] A v5 UUID that uniquely represents the user.
    def self.hid_to_uuid(heroku_id)
      if user_id = heroku_id.slice(/^user(\d+)\@heroku\.com$/, 1)
        id_to_uuid(user_id)
      else
        raise ArgumentError,"#{heroku_id} is not a valid Heroku user ID."
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
vault-tools-0.4.6 lib/vault-tools/user.rb
vault-tools-0.4.5 lib/vault-tools/user.rb
vault-tools-0.4.4 lib/vault-tools/user.rb
vault-tools-0.4.3 lib/vault-tools/user.rb
vault-tools-0.4.2 lib/vault-tools/user.rb
vault-tools-0.4.1 lib/vault-tools/user.rb
vault-tools-0.4.0 lib/vault-tools/user.rb
vault-tools-0.3.11 lib/vault-tools/user.rb
vault-tools-0.3.10 lib/vault-tools/user.rb
vault-tools-0.3.9 lib/vault-tools/user.rb
vault-tools-0.3.8 lib/vault-tools/user.rb
vault-tools-0.3.7 lib/vault-tools/user.rb
vault-tools-0.3.6 lib/vault-tools/user.rb
vault-tools-0.3.5 lib/vault-tools/user.rb
vault-tools-0.3.4 lib/vault-tools/user.rb
vault-tools-0.3.3 lib/vault-tools/user.rb
vault-tools-0.3.2 lib/vault-tools/user.rb
vault-tools-0.3.1 lib/vault-tools/user.rb
vault-tools-0.3.0 lib/vault-tools/user.rb
vault-tools-0.2.1 lib/vault-tools/user.rb