Module: Vault::App

Defined in:
lib/vault-tools/app.rb

Constant Summary collapse

ID_CAPTURE =
/\Aapp(\d+)\@[\w\.]+com\z/

Class Method Summary collapse

Class Method Details

.hid_to_id(heroku_id) ⇒ Integer

Convert a Heroku app ID into a core app ID.

Parameters:

Returns:

  • (Integer)

    The core app ID that uniquely represents the app.

Raises:

  • (ArgumentError)

    Raised if a malformed Heroku ID is provided.



28
29
30
31
32
33
34
# File 'lib/vault-tools/app.rb', line 28

def self.hid_to_id(heroku_id)
  if app_id = heroku_id.slice(ID_CAPTURE, 1)
    app_id.to_i
  else
    raise ArgumentError,"#{heroku_id} is not a valid Heroku app ID."
  end
end

.hid_to_uuid(heroku_id) ⇒ String

Convert a Heroku app ID into a v5 UUID.

Parameters:

Returns:

  • (String)

    A v5 UUID that uniquely represents the app.

Raises:

  • (ArgumentError)

    Raised if a malformed Heroku ID is provided.



41
42
43
44
45
46
47
# File 'lib/vault-tools/app.rb', line 41

def self.hid_to_uuid(heroku_id)
  if app_id = heroku_id.slice(ID_CAPTURE, 1)
    id_to_uuid(app_id)
  else
    raise ArgumentError, "#{heroku_id} is not a valid Heroku app ID."
  end
end

.id_to_hid(app_id) ⇒ String

Convert a core app ID into a Heroku app ID.

Parameters:

  • app_id (Integer)

    A core app ID.

Returns:

  • (String)

    A Heroku ID that uniquely represents the app.



10
11
12
# File 'lib/vault-tools/app.rb', line 10

def self.id_to_hid(app_id)
  "app#{app_id}@heroku.com"
end

.id_to_uuid(app_id) ⇒ String

Convert a core app ID into a v5 UUID.

Parameters:

Returns:

  • (String)

    A v5 UUID that uniquely represents the app.



18
19
20
21
# File 'lib/vault-tools/app.rb', line 18

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