Sha256: 257d1789b02aba4b541aec8d405872c6976717b1ea70d4bfeff091ac6227274a

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require 'uuidtools'

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vault-tools-0.0.10 lib/vault-tools/app.rb
vault-tools-0.0.7 lib/vault-tools/app.rb