info 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31e53f7a9fe86770c1708f0d3d1569a8d968e970
4
+ data.tar.gz: 4888fed4ece7745dfc387e35a61af05cc288b1d8
5
+ SHA512:
6
+ metadata.gz: 4589e198dd442e17426264078078fb73efb47427fa71fe39dc1abf256b1c09ee73f2a58da99bc026160354805d042187ccdf17491dd2d69792097558bd3bbf50
7
+ data.tar.gz: 9579c661cdc76ab5dc30af2f0cb0744ef61dbae5219edc67601a91affc13cf56af8fa00a48302c7910b10e011f56329c0979bcf8c16a55bbfc484953d0e82029
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Info
2
+
3
+ [![Build Status](https://travis-ci.org/fnando/info.svg)](https://travis-ci.org/fnando/info)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/info.png)](https://codeclimate.com/github/fnando/info)
5
+
6
+ Info a library that allows you collecting info about your application in a simple JSON endpoint.
7
+
8
+ ## Installation
9
+
10
+ Just the following line to your Gemfile:
11
+
12
+ gem "info"
13
+
14
+ ## Usage
15
+
16
+ To add your own collectors, just use the method `Info::Configuration#add`.
17
+
18
+ ```ruby
19
+ Info.setup do
20
+ add 'Rails', Rails.version
21
+ end
22
+ ```
23
+
24
+ You can also use `Info.add 'Rails', Rails.version`.
25
+
26
+ Info comes with some default information; just load the `info/rails` file. You can do it on a initializer file (`config/initializers/info.rb`) or your Gemfile.
27
+
28
+ ```ruby
29
+ gem 'info', require: 'info/rails'
30
+ ```
31
+
32
+ Rubygems that your app is using can be collected by loading the file `info/rubygems`.
33
+
34
+ You may need to clear all collectors; in this case just use `Info.collectors.clear`.
35
+
36
+ To view your collected info, just visit `/application/info`. This endpoint is public, so you can set authorization with two strategies: token and basic auth.
37
+
38
+ ### Authorization
39
+
40
+ To authorize the endpoint access with basic authentication, just provide a block that requires two arguments.
41
+
42
+ ```ruby
43
+ Info.setup do
44
+ authorize {|email, password| AdminUser.find_by_email(email).authenticate(password) }
45
+ end
46
+ ```
47
+
48
+ To authorize the endpoint access with token authentication, just provide a block that requires one argument.
49
+
50
+ ```ruby
51
+ Info.setup do
52
+ authorize {|token| AdminUser.find_by_token(token).present? }
53
+ end
54
+ ```
55
+
56
+ You can also use `Info.authorize(&block)`.
57
+
58
+ ## Maintainer
59
+
60
+ * Nando Vieira (<http://simplesideias.com.br>)
61
+
62
+ ## License:
63
+
64
+ (The MIT License)
65
+
66
+ Permission is hereby granted, free of charge, to any person obtaining
67
+ a copy of this software and associated documentation files (the
68
+ 'Software'), to deal in the Software without restriction, including
69
+ without limitation the rights to use, copy, modify, merge, publish,
70
+ distribute, sublicense, and/or sell copies of the Software, and to
71
+ permit persons to whom the Software is furnished to do so, subject to
72
+ the following conditions:
73
+
74
+ The above copyright notice and this permission notice shall be
75
+ included in all copies or substantial portions of the Software.
76
+
77
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
78
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
79
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
80
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
81
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
82
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
83
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
3
+ load 'rails/tasks/engine.rake'
4
+
5
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,27 @@
1
+ class InfoController < ActionController::Base
2
+ if respond_to?(:before_action, true)
3
+ before_action :authorize
4
+ else
5
+ before_filter :authorize
6
+ end
7
+
8
+ def show
9
+ if Info.configuration.enabled
10
+ render json: Info.collect
11
+ else
12
+ render nothing: true
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def authorize
19
+ authorizer = Info.configuration.authorizer
20
+ return unless authorizer
21
+
22
+ arity = authorizer.arity
23
+
24
+ authenticate_or_request_with_http_basic(&authorizer) if arity == 2
25
+ authenticate_or_request_with_http_token(&authorizer) if arity == 1
26
+ end
27
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ get 'application/info', to: 'info#show'
3
+ end
data/lib/info.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'forwardable'
2
+
3
+ require 'info/version'
4
+ require 'info/engine'
5
+ require 'info/configuration'
6
+
7
+ module Info
8
+ class << self
9
+ extend Forwardable
10
+
11
+ def_delegators :configuration,
12
+ :enabled?, :collect, :add, :enable!, :disable!, :authorize, :collectors
13
+ end
14
+
15
+ def self.setup(&block)
16
+ configuration.instance_eval(&block)
17
+ end
18
+
19
+ def self.configuration
20
+ @configuration ||= Configuration.new
21
+ end
22
+ end
@@ -0,0 +1,48 @@
1
+ module Info
2
+ class Configuration
3
+ attr_accessor :enabled
4
+ attr_accessor :authorizer
5
+
6
+ def collect(request = nil)
7
+ collectors.each_with_object({}) do |collector, buffer|
8
+ buffer[collector[:name]] = collect_value request, collector[:value]
9
+ end
10
+ end
11
+
12
+ def collectors
13
+ @collectors ||= []
14
+ end
15
+
16
+ def authorize(&block)
17
+ @authorizer = block
18
+ end
19
+
20
+ def enabled?
21
+ @enabled
22
+ end
23
+
24
+ def disable!
25
+ @enabled = false
26
+ end
27
+
28
+ def enable!
29
+ @enabled = true
30
+ end
31
+
32
+ def add(name, value)
33
+ collectors << {name: name, value: value}
34
+ end
35
+
36
+ private
37
+
38
+ def collect_value(request, value)
39
+ return value unless value.respond_to?(:call)
40
+
41
+ if value.arity == 0
42
+ value.call
43
+ else
44
+ value.call(request)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,4 @@
1
+ module Info
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
data/lib/info/rails.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'info'
2
+
3
+ Info.setup do
4
+ add 'Rails', Rails.version
5
+ add 'Database', ActiveRecord::Base.connection.adapter_name
6
+ add 'SSL', -> r { r.ssl? }
7
+ add 'Application Server', -> r { r.env['SERVER_SOFTWARE'] }
8
+ end
@@ -0,0 +1,7 @@
1
+ require 'info'
2
+
3
+ Info.setup do
4
+ add 'Rubygems', Gem.loaded_specs.map {|(_, spec)|
5
+ {name: spec.name, version: spec.version.to_s}
6
+ }
7
+ end
@@ -0,0 +1,3 @@
1
+ module Info
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: info
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nando Vieira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-meta
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A JSON endpoint with your Rails application info
70
+ email:
71
+ - fnando.vieira@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - app/controllers/info_controller.rb
80
+ - config/routes.rb
81
+ - lib/info.rb
82
+ - lib/info/configuration.rb
83
+ - lib/info/engine.rb
84
+ - lib/info/rails.rb
85
+ - lib/info/rubygems.rb
86
+ - lib/info/version.rb
87
+ homepage: http://github.com/fnando/info
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: A JSON endpoint with your Rails application info
111
+ test_files: []