vault-tools 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  Gemfile.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
+ bin/*
9
10
  coverage
10
11
  doc/
11
12
  lib/bundler/man
@@ -16,5 +17,5 @@ test/tmp
16
17
  test/version_tmp
17
18
  tmp
18
19
  test.profile*
19
- bin/*
20
20
  test/.test.profile*
21
+ vendor
data/README.md CHANGED
@@ -1,6 +1,23 @@
1
- # Vault Tools
1
+ # Vault::Tools
2
+
3
+ Tooling for the Heroku Vault team to enable faster bootstrapping for
4
+ Ruby projects.
5
+
6
+ ## Setting up a development environment
7
+
8
+ Install the dependencies:
9
+
10
+ bundle install --binstubs vendor/bin
11
+ rbenv rehash
12
+
13
+ Run the tests:
14
+
15
+ vendor/bin/t
16
+
17
+ Generate the API documentation:
18
+
19
+ vendor/bin/d
2
20
 
3
- Tooling for the Heroku Vault team to enable faster bootstrapping for Ruby projects.
4
21
 
5
22
  ## Installation
6
23
 
@@ -8,6 +25,7 @@ Add this line to your application's Gemfile:
8
25
 
9
26
  gem 'vault-tools'
10
27
 
28
+
11
29
  ## Usage
12
30
 
13
31
  ### Logging
@@ -20,7 +38,7 @@ Add this line to your application's Gemfile:
20
38
  # => "measure=true at=foo"
21
39
  ```
22
40
 
23
- ### Sinatra Base Class
41
+ ### Sinatra base class
24
42
 
25
43
  Includes request logging and health endpoints
26
44
 
data/lib/vault-tools.rb CHANGED
@@ -11,7 +11,11 @@ module Vault
11
11
  end
12
12
  end
13
13
 
14
- require 'vault-tools/sinatra_helpers/html_serializer'
14
+ require 'vault-tools/app'
15
+ require 'vault-tools/config'
16
+ require 'vault-tools/hid'
15
17
  require 'vault-tools/log'
18
+ require 'vault-tools/product'
19
+ require 'vault-tools/sinatra_helpers/html_serializer'
20
+ require 'vault-tools/user'
16
21
  require 'vault-tools/web'
17
- require 'vault-tools/config'
@@ -0,0 +1,35 @@
1
+ require 'uuidtools'
2
+
3
+ module Vault
4
+ module App
5
+ # Convert an app ID into a Heroku app ID.
6
+ #
7
+ # @param app_id [Fixnum] An app ID.
8
+ # @return [String] A Heroku ID that uniquely represents the app.
9
+ def self.id_to_hid(app_id)
10
+ "app#{app_id}@heroku.com"
11
+ end
12
+
13
+ # Convert an app ID into a v5 UUID.
14
+ #
15
+ # @param app_id [Fixnum] An app ID.
16
+ # @return [String] A v5 UUID that uniquely represents the app.
17
+ def self.id_to_uuid(app_id)
18
+ url = "https://vault.heroku.com/apps/#{app_id}"
19
+ UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
20
+ end
21
+
22
+ # Convert a Heroku app ID into a v5 UUID.
23
+ #
24
+ # @param heroku_id [String] A Heroku app ID, such as `app1234@heroku.com`.
25
+ # @raise [ArgumentError] Raised if a malformed Heroku ID is provided.
26
+ # @return [String] A v5 UUID that uniquely represents the app.
27
+ def self.hid_to_uuid(heroku_id)
28
+ if app_id = heroku_id.slice(/^app(\d+)\@heroku\.com$/, 1)
29
+ id_to_uuid(app_id)
30
+ else
31
+ raise ArgumentError, "#{heroku_id} is not a valid Heroku app ID."
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ require 'uuidtools'
2
+
3
+ module Vault
4
+ module HID
5
+ # Convert a Heroku app ID or user ID into a v5 UUID.
6
+ #
7
+ # @param heroku_id [String] A Heroku app ID over user ID
8
+ # @raise [ArgumentError] Raised if a malformed Heroku ID is provided.
9
+ # @return [String] A v5 UUID that uniquely represents the app.
10
+ def self.hid_to_uuid(string)
11
+ case string
12
+ when /^user/
13
+ User.hid_to_uuid(string)
14
+ when /^app/
15
+ App.hid_to_uuid(string)
16
+ else
17
+ raise ArgumentError, "#{string} is not a valid Heroku app or user ID."
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ require 'uuidtools'
2
+
3
+ module Vault
4
+ module Product
5
+ # Convert a product name into a v5 UUID.
6
+ #
7
+ # @param name [String] A product name.
8
+ # @raise [RuntimeError] Raised if the product name is empty or contains
9
+ # illegal characters. A product name may only contain 'a-z', '0-9' and
10
+ # ':' characters.
11
+ # @return [String] A v5 UUID that uniquely represents the product.
12
+ def self.name_to_uuid(name)
13
+ unless name =~ /[a-z,0-9,:]+/
14
+ raise "Product name empty or contains illegal characters."
15
+ end
16
+ url = "https://vault.heroku.com/products/#{name}"
17
+ UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ require 'uuidtools'
2
+
3
+ module Vault
4
+ module User
5
+ # Convert a user ID into a Heroku user ID.
6
+ #
7
+ # @param user_id [Fixnum] A user ID.
8
+ # @return [String] A Heroku ID that uniquely represents the user.
9
+ def self.id_to_hid(user_id)
10
+ "user#{user_id}@heroku.com"
11
+ end
12
+
13
+ # Convert a user ID into a v5 UUID.
14
+ #
15
+ # @param user_id [Fixnum] A user ID.
16
+ # @return [String] A v5 UUID that uniquely represents the user.
17
+ def self.id_to_uuid(user_id)
18
+ url = "https://vault.heroku.com/users/#{user_id}"
19
+ UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
20
+ end
21
+
22
+ # Convert a Heroku user ID into a v5 UUID.
23
+ #
24
+ # @param heroku_id [String] A Heroku user ID, such as
25
+ # `user1234@heroku.com`.
26
+ # @raise [ArgumentError] Raised if a malformed Heroku ID is provided.
27
+ # @return [String] A v5 UUID that uniquely represents the user.
28
+ def self.hid_to_uuid(heroku_id)
29
+ if user_id = heroku_id.slice(/^user(\d+)\@heroku\.com$/, 1)
30
+ id_to_uuid(user_id)
31
+ else
32
+ raise ArgumentError,"#{heroku_id} is not a valid Heroku user ID."
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,5 @@
1
1
  module Vault
2
2
  module Tools
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
data/test/app_test.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'helper'
2
+ require 'uuidtools'
3
+
4
+ class AppTest < Vault::TestCase
5
+ # App.id_to_hid converts an app ID to a Heroku app ID.
6
+ def test_id_to_hid
7
+ assert_equal('app1234@heroku.com', Vault::App.id_to_hid(1234))
8
+ end
9
+
10
+ # App.id_to_uuid converts an app ID to a v5 UUID based on a URL scheme.
11
+ def test_id_to_uuid
12
+ url = "https://vault.heroku.com/apps/1234"
13
+ uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
14
+ assert_equal(uuid, Vault::App.id_to_uuid(1234))
15
+ end
16
+
17
+ # App.hid_to_uuid converts a Heroku app ID to a v5 UUID based on a URL
18
+ # scheme.
19
+ def test_hid_to_uuid
20
+ url = "https://vault.heroku.com/apps/1234"
21
+ uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
22
+ assert_equal(uuid, Vault::App.hid_to_uuid('app1234@heroku.com'))
23
+ end
24
+
25
+ # App.hid_to_uuid raises a ArgumentError if the specified ID doesn't match
26
+ # the expected format.
27
+ def test_hid_to_uuid_with_invalid_heroku_id
28
+ error = assert_raises(ArgumentError) do
29
+ Vault::App.hid_to_uuid('invalid1234@heroku.com')
30
+ end
31
+ assert_equal('invalid1234@heroku.com is not a valid Heroku app ID.',
32
+ error.message)
33
+ end
34
+ end
data/test/hid_test.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'helper'
2
+ require 'uuidtools'
3
+
4
+ class HIDTest < Vault::TestCase
5
+
6
+ # HID.hid_to_uuid converts an app ID to a v5 UUID based on a URL scheme.
7
+ def test_app_id_to_uuid
8
+ url = "https://vault.heroku.com/apps/1234"
9
+ uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
10
+ assert_equal(uuid, Vault::HID.hid_to_uuid('app1234@heroku.com'))
11
+ end
12
+
13
+ # HID.hid_to_uuid converts a Heroku app ID to a v5 UUID based on a URL
14
+ # scheme.
15
+ def test_user_id_to_uuid
16
+ url = "https://vault.heroku.com/users/1234"
17
+ uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
18
+ assert_equal(uuid, Vault::HID.hid_to_uuid('user1234@heroku.com'))
19
+ end
20
+
21
+ # HID.hid_to_uuid raises a ArgumentError if the specified ID doesn't match
22
+ # the expected format.
23
+ def test_hid_to_uuid_with_invalid_heroku_id
24
+ error = assert_raises(ArgumentError) do
25
+ Vault::HID.hid_to_uuid('invalid1234@heroku.com')
26
+ end
27
+ assert_equal('invalid1234@heroku.com is not a valid Heroku app or user ID.',
28
+ error.message)
29
+ end
30
+
31
+ # HID.hid_to_uuid raises a ArgumentError if the specified ID doesn't match
32
+ # the expected format.
33
+ def test_hid_to_uuid_with_subtly_invalid_heroku_id
34
+ error = assert_raises(ArgumentError) do
35
+ Vault::HID.hid_to_uuid('app1234--afasd-afas')
36
+ end
37
+ assert_equal('app1234--afasd-afas is not a valid Heroku app ID.',
38
+ error.message)
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+ require 'uuidtools'
3
+
4
+ class ProductTest < Vault::TestCase
5
+ # Product.name_to_uuid converts a product name to a v5 UUID based on a URL
6
+ # scheme.
7
+ def test_name_to_uuid
8
+ url = 'https://vault.heroku.com/products/platform:dyno:logical'
9
+ uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
10
+ assert_equal(uuid, Vault::Product.name_to_uuid('platform:dyno:logical'))
11
+ end
12
+
13
+ # Product.name_to_uuid raises a RuntimeError if an empty name is provided.
14
+ def test_name_to_uuid_with_empty_name
15
+ error = assert_raises(RuntimeError) do
16
+ Vault::Product.name_to_uuid('')
17
+ end
18
+ assert_equal("Product name empty or contains illegal characters.",
19
+ error.message)
20
+ end
21
+
22
+ # Product.name_to_uuid raises a RuntimeError if the product name contains
23
+ # illegal characters.
24
+ def test_name_to_uuid_with_illegal_characters
25
+ assert_raises(RuntimeError) { Vault::Product.name_to_uuid('!') }
26
+ assert_raises(RuntimeError) { Vault::Product.name_to_uuid(' ') }
27
+ assert_raises(RuntimeError) { Vault::Product.name_to_uuid('A') }
28
+ end
29
+ end
data/test/user_test.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'helper'
2
+ require 'uuidtools'
3
+
4
+ class UserTest < Vault::TestCase
5
+ # User.id_to_hid converts a user ID to a Heroku user ID.
6
+ def test_id_to_hid
7
+ assert_equal('user1234@heroku.com', Vault::User.id_to_hid(1234))
8
+ end
9
+
10
+ # User.id_to_uuid converts a user ID to a v5 UUID based on a URL scheme.
11
+ def test_id_to_uuid
12
+ url = "https://vault.heroku.com/users/1234"
13
+ uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
14
+ assert_equal(uuid, Vault::User.id_to_uuid(1234))
15
+ end
16
+
17
+ # User.hid_to_uuid converts a Heroku user ID to a v5 UUID based on a URL
18
+ # scheme.
19
+ def test_hid_to_uuid
20
+ url = "https://vault.heroku.com/users/1234"
21
+ uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
22
+ assert_equal(uuid, Vault::User.hid_to_uuid('user1234@heroku.com'))
23
+ end
24
+
25
+ # User.hid_to_uuid raises a ArgumentError if the specified ID doesn't match
26
+ # the expected format.
27
+ def test_hid_to_uuid_with_invalid_heroku_id
28
+ error = assert_raises(ArgumentError) do
29
+ Vault::User.hid_to_uuid('invalid1234@heroku.com')
30
+ end
31
+ assert_equal('invalid1234@heroku.com is not a valid Heroku user ID.',
32
+ error.message)
33
+ end
34
+ end
data/vault-tools.gemspec CHANGED
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'vault-tools/version'
@@ -7,15 +8,17 @@ Gem::Specification.new do |gem|
7
8
  gem.name = "vault-tools"
8
9
  gem.version = Vault::Tools::VERSION
9
10
  gem.authors = ["Chris Continanza", "Jamu Kakar"]
10
- gem.email = ["chriscontinanza@gmail.com", "csquared@heroku.com", "jkakar@heroku.com"]
11
- gem.description = %q{Basic tools for Heroku Vault's Ruby projects}
12
- gem.summary = %q{Test classes, base web classes, and helpers - oh my!}
11
+ gem.email = ["chriscontinanza@gmail.com", "csquared@heroku.com",
12
+ "jkakar@heroku.com"]
13
+ gem.description = "Basic tools for Heroku Vault's Ruby projects"
14
+ gem.summary = "Test classes, base web classes, and helpers - oh my!"
13
15
  gem.homepage = ""
14
16
 
15
17
  gem.files = `git ls-files`.split($/)
16
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.test_files = gem.files.grep('^(test|spec|features)/')
17
19
  gem.require_paths = ["lib"]
18
20
 
19
- gem.add_dependency 'sinatra'
20
21
  gem.add_dependency 'scrolls'
22
+ gem.add_dependency 'sinatra'
23
+ gem.add_dependency 'uuidtools'
21
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vault-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-13 00:00:00.000000000 Z
13
+ date: 2013-01-17 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: scrolls
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
15
31
  - !ruby/object:Gem::Dependency
16
32
  name: sinatra
17
33
  requirement: !ruby/object:Gem::Requirement
@@ -29,7 +45,7 @@ dependencies:
29
45
  - !ruby/object:Gem::Version
30
46
  version: '0'
31
47
  - !ruby/object:Gem::Dependency
32
- name: scrolls
48
+ name: uuidtools
33
49
  requirement: !ruby/object:Gem::Requirement
34
50
  none: false
35
51
  requirements:
@@ -68,14 +84,22 @@ files:
68
84
  - bin/turn
69
85
  - bin/vault-tools
70
86
  - lib/vault-tools.rb
87
+ - lib/vault-tools/app.rb
71
88
  - lib/vault-tools/config.rb
89
+ - lib/vault-tools/hid.rb
72
90
  - lib/vault-tools/log.rb
91
+ - lib/vault-tools/product.rb
73
92
  - lib/vault-tools/sinatra_helpers/html_serializer.rb
93
+ - lib/vault-tools/user.rb
74
94
  - lib/vault-tools/version.rb
75
95
  - lib/vault-tools/web.rb
96
+ - test/app_test.rb
76
97
  - test/config_test.rb
77
98
  - test/helper.rb
99
+ - test/hid_test.rb
100
+ - test/product_test.rb
78
101
  - test/test_spec.rb
102
+ - test/user_test.rb
79
103
  - vault-tools.gemspec
80
104
  homepage: ''
81
105
  licenses: []
@@ -91,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
115
  version: '0'
92
116
  segments:
93
117
  - 0
94
- hash: 3663262642643653617
118
+ hash: 233434446101266212
95
119
  required_rubygems_version: !ruby/object:Gem::Requirement
96
120
  none: false
97
121
  requirements:
@@ -100,15 +124,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
124
  version: '0'
101
125
  segments:
102
126
  - 0
103
- hash: 3663262642643653617
127
+ hash: 233434446101266212
104
128
  requirements: []
105
129
  rubyforge_project:
106
130
  rubygems_version: 1.8.23
107
131
  signing_key:
108
132
  specification_version: 3
109
133
  summary: Test classes, base web classes, and helpers - oh my!
110
- test_files:
111
- - test/config_test.rb
112
- - test/helper.rb
113
- - test/test_spec.rb
134
+ test_files: []
114
135
  has_rdoc: