add-to-org 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: 18dc2fd4a2e9a3e0b5d5739198d12a7ad9a53686
4
+ data.tar.gz: 8a138d7e82808d71f3888865efd662640f95ae58
5
+ SHA512:
6
+ metadata.gz: 2b34675089ad04b79b4a476357ad47ed53716c0ce3d7ed1aac6684528782b24997dcfed7f98beb896b31f936084df4ba200c5a2a4f2574156a5ccf1ede789a9b
7
+ data.tar.gz: 1c11908e629090694077d386cf4ea7264fd64be932969a5469e7ba32b4bfb754d9d1f898ca592f91d9b020e5bae701f9fef3db1dbde657cb9206058da6c3c24c
@@ -0,0 +1,53 @@
1
+ module AddToOrg
2
+ class App < Sinatra::Base
3
+
4
+ use Rack::Session::Cookie, {
5
+ :http_only => true,
6
+ :secret => ENV['SESSION_SECRET'] || SecureRandom.hex
7
+ }
8
+
9
+ register Sinatra::Auth::Github
10
+
11
+ set :views, File.expand_path("views", File.dirname(__FILE__))
12
+
13
+ # require ssl
14
+ configure :production do
15
+ require 'rack-ssl-enforcer'
16
+ use Rack::SslEnforcer
17
+ end
18
+
19
+ # dat auth
20
+ before do
21
+ session[:return_to] = request.url #store requested URL for post-auth redirect
22
+ authenticate!
23
+ end
24
+
25
+ def success(locals={})
26
+ erb :success, locals
27
+ end
28
+
29
+ def forbidden
30
+ status 403
31
+ erb :forbidden
32
+ end
33
+
34
+ def error
35
+ status 500
36
+ erb :error
37
+ end
38
+
39
+ # request a GitHub (authenticated) URL
40
+ get "/*" do
41
+
42
+ path = request.path || "/#{team_id}"
43
+ halt redirect "https://github.com#{path}", 302 if member?
44
+ forbidden unless valid?
45
+
46
+ if add
47
+ success({ :redirect => "https://github.com#{path}" })
48
+ else
49
+ error
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module AddToOrg
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ <html>
2
+ <head>
3
+ <style>
4
+ body { padding: 20px; }
5
+ </style>
6
+ </head>
7
+ <body>
8
+ <h1>Ruh roh</h1>
9
+ <p>Looks like something went wrong.</p>
10
+ <p>Please contact <a href="mailto:<%= ENV['CONTACT_EMAIL'] %>"><%= ENV['CONTACT_EMAIL'] %></a>.</p>
11
+ </body>
12
+ </html>
@@ -0,0 +1,12 @@
1
+ <html>
2
+ <head>
3
+ <style>
4
+ body { padding: 20px; }
5
+ </style>
6
+ </head>
7
+ <body>
8
+ <h1>Sorry Charlie</h1>
9
+ <p>We're unable to verify your eligibility at this time.</p>
10
+ <p>Please contact <a href="mailto:<%= ENV['CONTACT_EMAIL'] %>"><%= ENV['CONTACT_EMAIL'] %></a> if you believe this is in error.</p>
11
+ </body>
12
+ </html>
@@ -0,0 +1,16 @@
1
+ <html>
2
+ <head>
3
+ <style>
4
+ body { padding: 20px; }
5
+ </style>
6
+ </head>
7
+ <body>
8
+ <h1>You're all set</h1>
9
+ <p>You should be <a href="<%= ERB::Util.html_escape(redirect) %>">redirected</a> automatically...</h1>
10
+ <script>
11
+ setTimeout(function () {
12
+ window.location.href = "<%= ERB::Util.html_escape(redirect) %>";
13
+ }, 5000);
14
+ </script>
15
+ </body>
16
+ </html>
data/lib/add-to-org.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'octokit'
2
+ require 'sinatra_auth_github'
3
+ require 'dotenv'
4
+ require_relative 'add-to-org/server'
5
+
6
+ Dotenv.load
7
+
8
+ module AddToOrg
9
+ class App < Sinatra::Base
10
+
11
+ set :github_options, {
12
+ :scopes => "user,user:email",
13
+ :secret => ENV['GITHUB_CLIENT_SECRET'],
14
+ :client_id => ENV['GITHUB_CLIENT_ID']
15
+ }
16
+
17
+ def user
18
+ env['warden'].user
19
+ end
20
+
21
+ # user client
22
+ def client
23
+ @client ||= Octokit::Client.new :access_token => user.token
24
+ end
25
+
26
+ # new org admin client
27
+ def sudo_client
28
+ @sudo_client ||= Octokit::Client.new :access_token => ENV['GITHUB_TOKEN']
29
+ end
30
+
31
+ # query api for the user's verified emails
32
+ def verified_emails
33
+ emails = client.emails :accept => 'application/vnd.github.v3'
34
+ emails.select { |email| email.verified }
35
+ end
36
+
37
+ # true if user is already a member of the org
38
+ def member?
39
+ client.organization_member? org_id, user.login
40
+ end
41
+
42
+ def valid?
43
+ raise "You must define a custom valid? method to determine eligibility"
44
+ end
45
+
46
+ def team_id
47
+ ENV['GITHUB_TEAM_ID']
48
+ end
49
+
50
+ def org_id
51
+ ENV['GITHUB_ORG_ID']
52
+ end
53
+
54
+ # the main event...
55
+ def add
56
+ sudo_client.add_team_member team_id, user.login
57
+ end
58
+
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: add-to-org
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Balter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: warden-github
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: sinatra_auth_github
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: octokit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: rack-ssl-enforcer
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ''
84
+ email: ben.balter@github.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - lib/add-to-org.rb
90
+ - lib/add-to-org/server.rb
91
+ - lib/add-to-org/version.rb
92
+ - lib/add-to-org/views/error.erb
93
+ - lib/add-to-org/views/forbidden.erb
94
+ - lib/add-to-org/views/success.erb
95
+ homepage: https://github.com/benbalter/add-to-org
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.0
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: ''
119
+ test_files: []