heroku_addon_provider 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6f0e7100554699cdf5c9d07e754cd8ba9979b5e
4
+ data.tar.gz: 8e36ccc36a4d140548b63dafe64f47fae48399ea
5
+ SHA512:
6
+ metadata.gz: 392591e7c5a3de61972c765ef9d4c3ec173878e8017b698dcae8f26e52887df3397248941c84c0f6e42821cb0f38fb8b330ec586c476854208f59c5a30a1abed
7
+ data.tar.gz: 69fab726fe0cc2b81a6bc941e3e7df7f4c061f1a8083258cabd56df52ab76122a566d15c6fab59842b63c32318bf862037e86c61ab437883b0a7a1de38c439b4
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - jruby-19mode
8
+ notifications:
9
+ email:
10
+ - adam.v.duke@gmail.com
11
+ - stefan.natchev@gmail.com
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in heroku_addon_provider.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ heroku_addon_provider (0.0.1)
5
+ faraday (~> 0.8.5)
6
+ faraday_middleware (~> 0.9.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ faraday (0.8.9)
12
+ multipart-post (~> 1.2.0)
13
+ faraday_middleware (0.9.0)
14
+ faraday (>= 0.7.4, < 0.9)
15
+ minitest (4.7.5)
16
+ multipart-post (1.2.0)
17
+ rake (10.0.4)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ heroku_addon_provider!
24
+ minitest (~> 4.7.0)
25
+ rake (~> 10.0.3)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Symmetric Infinity LLC
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ ## Installation
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ gem 'heroku_addon_provider'
6
+
7
+ And then execute:
8
+
9
+ $ bundle
10
+
11
+ Or install it yourself as:
12
+
13
+ $ gem install heroku_addon_provider
14
+
15
+ ## Usage
16
+
17
+
18
+ ## Contributing
19
+
20
+ 1. Fork it
21
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
22
+ 1. Write tests for your feature
23
+ 1. Commit your changes (`git commit -am 'Add some feature'`)
24
+ 1. Push to the branch (`git push origin my-new-feature`)
25
+ 1. Create new Pull Request
26
+
27
+ ## License
28
+
29
+ Copyright (c) 2014 Symmetric Infinity LLC
30
+
31
+ MIT License
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ "Software"), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
47
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
48
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
49
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
50
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "rake/testtask"
2
+ require "bundler/gem_tasks"
3
+
4
+ task default: :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib' << 'spec'
8
+ t.test_files = Dir["spec/**/*_spec.rb"]
9
+ t.verbose = true
10
+ end
11
+
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'heroku_addon_provider/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "heroku_addon_provider"
8
+ gem.version = HerokuAddonProvider::VERSION
9
+ gem.authors = ["Stefan Natchev", "Adam Duke"]
10
+ gem.email = ["stefan.natchev@gmail.com", "adam.v.duke@gmail.com"]
11
+ gem.summary = %q{A gem for abstracting common addon provider concerns}
12
+ gem.description = %q{A gem for abstracting common heroku addon provider concerns}
13
+ gem.homepage = "https://github.com/SymmetricInfinity/heroku_addon_provider"
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ gem.required_ruby_version = '>= 1.9'
21
+
22
+ gem.add_dependency "faraday", "~> 0.8.5"
23
+ gem.add_dependency "faraday_middleware", "~> 0.9.0"
24
+
25
+ gem.add_development_dependency 'minitest', '~> 4.7.0'
26
+ gem.add_development_dependency 'rake', '~> 10.0.3'
27
+ end
@@ -0,0 +1,3 @@
1
+ class HerokuAddonProvider
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,73 @@
1
+ require 'digest'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+ require 'heroku_addon_provider/version'
5
+ require 'json'
6
+
7
+ class HerokuAddonProvider
8
+
9
+ class << self
10
+
11
+ attr_accessor :manifest_path
12
+
13
+ def manifest
14
+ if manifest_path
15
+ @manifest ||= JSON.load(File.read(manifest_path))
16
+ elsif (defined?(Rails) && File.exists?("#{Rails.root}/addon-manifest.json"))
17
+ @manifest ||= JSON.load(File.read("#{Rails.root}/addon-manifest.json"))
18
+ else
19
+ raise 'Addon manifest not found'
20
+ end
21
+ end
22
+
23
+ def provider_id
24
+ manifest['id']
25
+ end
26
+
27
+ def password
28
+ manifest['api']['password']
29
+ end
30
+
31
+ def sso_salt
32
+ manifest['api']['sso_salt']
33
+ end
34
+
35
+ def sso_token(user_id, timestamp)
36
+ pre_token = "#{user_id}:#{sso_salt}:#{timestamp}"
37
+ Digest::SHA1.hexdigest(pre_token).to_s
38
+ end
39
+
40
+ def installed_applications
41
+ faraday.get('/vendor/apps').body
42
+ end
43
+
44
+ def application_info(heroku_id)
45
+ faraday.get("/vendor/apps/#{heroku_id}").body
46
+ end
47
+
48
+ def owner_email(heroku_id)
49
+ info = application_info(heroku_id)
50
+ info['owner_email']
51
+ end
52
+
53
+ def owner_emails
54
+ installed_applications.map do |app|
55
+ owner_email(app['heroku_id'])
56
+ end
57
+ end
58
+
59
+ def configure(&block)
60
+ yield self
61
+ end
62
+
63
+ private
64
+ def faraday
65
+ Faraday.new(url: 'https://api.heroku.com') do |c|
66
+ c.request :basic_auth, provider_id, password
67
+ c.response :json, :content_type => /\bjson$/
68
+ c.adapter Faraday.default_adapter
69
+ end
70
+ end
71
+ end
72
+ end
73
+
@@ -0,0 +1,17 @@
1
+ {
2
+ "id": "my-heroku-addon",
3
+ "api": {
4
+ "config_vars": [ "CONFIG_VAR_1", "CONFIG_VAR_2" ],
5
+ "regions": [ "us" ],
6
+ "password": "this is not a secure password",
7
+ "sso_salt": "this is not a secure salt",
8
+ "production": {
9
+ "base_url": "https://my-heroku-addon.com/heroku/resources",
10
+ "sso_url": "https://my-heroku-addon.com/heroku/sso"
11
+ },
12
+ "test": {
13
+ "base_url": "http://localhost:3000/heroku/resources",
14
+ "sso_url": "http://localhost:3000/heroku/sso"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "callback_url": "https://api.heroku.com/vendor/apps/app11111111%40heroku.com",
3
+ "config": {
4
+ "ZEROPUSH_DEV_TOKEN": "AAAAAAAAAAAAAAAAAAAA",
5
+ "ZEROPUSH_PROD_TOKEN": "BBBBBBBBBBBBBBBBBBBB"
6
+ },
7
+ "domains": [
8
+ "my-heroku-app.herokuapp.com"
9
+ ],
10
+ "id": "app11111111@heroku.com",
11
+ "logplex_token": "",
12
+ "name": "my-heroku-app",
13
+ "owner_email": "owner@my-heroku-app.com",
14
+ "region": "amazon-web-services::us-east-1"
15
+ }
@@ -0,0 +1,26 @@
1
+ [
2
+ {
3
+ "callback_url": "https://api.heroku.com/vendor/apps/app11111111%40heroku.com",
4
+ "heroku_id": "app11111111@heroku.com",
5
+ "plan": "test",
6
+ "provider_id": "1"
7
+ },
8
+ {
9
+ "callback_url": "https://api.heroku.com/vendor/apps/app222222222%40heroku.com",
10
+ "heroku_id": "app222222222@heroku.com",
11
+ "plan": "test",
12
+ "provider_id": "2"
13
+ },
14
+ {
15
+ "callback_url": "https://api.heroku.com/vendor/apps/app333333333%40heroku.com",
16
+ "heroku_id": "app333333333@heroku.com",
17
+ "plan": "test",
18
+ "provider_id": "3"
19
+ },
20
+ {
21
+ "callback_url": "https://api.heroku.com/vendor/apps/app4444444444%40heroku.com",
22
+ "heroku_id": "app4444444444@heroku.com",
23
+ "plan": "test",
24
+ "provider_id": "4"
25
+ }
26
+ ]
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe HerokuAddonProvider do
4
+
5
+ before do
6
+ HerokuAddonProvider.manifest_path = 'spec/fixtures/addon-manifest.json'
7
+ end
8
+
9
+ describe 'manifest operations' do
10
+ it 'should return the provider id' do
11
+ HerokuAddonProvider.provider_id.must_equal 'my-heroku-addon'
12
+ end
13
+
14
+ it 'should return the password' do
15
+ HerokuAddonProvider.password.must_equal 'this is not a secure password'
16
+ end
17
+
18
+ it 'should return the sso salt' do
19
+ HerokuAddonProvider.sso_salt.must_equal 'this is not a secure salt'
20
+ end
21
+
22
+ it 'should return a computed sso_token' do
23
+ time = Time.parse('Thu Nov 29 14:33:20 GMT 2001')
24
+ HerokuAddonProvider.sso_token(10, time.to_i).must_equal 'c209b926738298059f642fd260abb87e5029a539'
25
+ end
26
+ end
27
+
28
+ describe 'provider api' do
29
+ it 'should return the list of installed applications' do
30
+ apps = HerokuAddonProvider.installed_applications
31
+ apps.length.must_equal 4
32
+ apps.first.keys.must_equal(['callback_url', 'heroku_id', 'plan', 'provider_id'])
33
+ end
34
+
35
+ it 'should return the application info' do
36
+ app = HerokuAddonProvider.application_info('app11111111@heroku.com')
37
+ app.keys.must_include('owner_email')
38
+ end
39
+ end
40
+
41
+ describe 'class configuration' do
42
+ it 'should set the manifest path' do
43
+ HerokuAddonProvider.configure do |config|
44
+ config.manifest_path = '/path/to/addon-manifest.json'
45
+ end
46
+ HerokuAddonProvider.manifest_path.must_equal '/path/to/addon-manifest.json'
47
+ end
48
+
49
+ it 'should read the manifest from Rails.root if Rails is defined' do
50
+ class Rails
51
+ def self.root
52
+ 'spec/fixtures/'
53
+ end
54
+ end
55
+ HerokuAddonProvider.manifest['id'].must_equal 'my-heroku-addon'
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,20 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'heroku_addon_provider'
4
+
5
+ class HerokuAddonProvider
6
+ def self.faraday
7
+ Faraday::Connection.new do |c|
8
+ c.use Faraday::Adapter::Test do |stub|
9
+ stub.get '/vendor/apps' do
10
+ [200, {}, File.read('spec/fixtures/installed_applications.json')]
11
+ end
12
+ stub.get '/vendor/apps/app11111111@heroku.com' do
13
+ [200, {}, File.read('spec/fixtures/application_info.json')]
14
+ end
15
+ end
16
+ c.response :json
17
+ end
18
+ end
19
+ end
20
+
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku_addon_provider
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stefan Natchev
8
+ - Adam Duke
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 0.8.5
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.8.5
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday_middleware
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 0.9.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 0.9.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 4.7.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 4.7.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 10.0.3
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 10.0.3
70
+ description: A gem for abstracting common heroku addon provider concerns
71
+ email:
72
+ - stefan.natchev@gmail.com
73
+ - adam.v.duke@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .travis.yml
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - heroku_addon_provider.gemspec
86
+ - lib/heroku_addon_provider.rb
87
+ - lib/heroku_addon_provider/version.rb
88
+ - spec/fixtures/addon-manifest.json
89
+ - spec/fixtures/application_info.json
90
+ - spec/fixtures/installed_applications.json
91
+ - spec/heroku_addon_provider_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: https://github.com/SymmetricInfinity/heroku_addon_provider
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '1.9'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.1.11
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A gem for abstracting common addon provider concerns
117
+ test_files:
118
+ - spec/fixtures/addon-manifest.json
119
+ - spec/fixtures/application_info.json
120
+ - spec/fixtures/installed_applications.json
121
+ - spec/heroku_addon_provider_spec.rb
122
+ - spec/spec_helper.rb