wildcloud-git 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ ## 0.0.1 (10.1.2012)
2
+
3
+ * first gemmed version
data/LICENSE ADDED
@@ -0,0 +1,174 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
@@ -0,0 +1,7 @@
1
+ # Wildcloud - Git
2
+
3
+ Responsible for managing repositories, authentication information for OpenSSH, authorization.
4
+
5
+ ## License
6
+
7
+ Project is licensed under the terms of the Apache 2 license.
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright 2011 Marek Jelen
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ $: << File.expand_path('../../lib', __FILE__)
18
+
19
+ require 'rubygems'
20
+
21
+ require 'eventmachine'
22
+
23
+ require 'wildcloud/git/server'
24
+
25
+ EventMachine.run do
26
+ Wildcloud::Git::Server.start
27
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright 2011 Marek Jelen
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'rubygems'
18
+
19
+ require 'wildcloud/configuration'
20
+
21
+ require File.expand_path('../../lib/wildcloud/git/client', __FILE__)
22
+
23
+ module Wildcloud
24
+ module Git
25
+
26
+ def self.configuration
27
+ return @configuration if @configuration
28
+ @configuration = Wildcloud::Configuration.load('git').configuration
29
+ end
30
+
31
+ end
32
+ end
33
+
34
+ git = Wildcloud::Git::Client.new
35
+ git.check_command
36
+ git.parse_information
37
+ git.setup_environment
38
+ git.authorize
39
+ git.run_git
@@ -0,0 +1,13 @@
1
+ # Copyright 2011 Marek Jelen
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
@@ -0,0 +1,69 @@
1
+ # Copyright 2011 Marek Jelen
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'socket'
16
+
17
+ module Wildcloud
18
+ module Git
19
+ class Client
20
+
21
+ def initialize
22
+ end
23
+
24
+ # Message helper
25
+ def message(level, message)
26
+ $stderr << "#{level.to_s.upcase}: #{message}\n"
27
+ exit(1) if [:error].include?(level)
28
+ end
29
+
30
+ # Was the right command issued?
31
+ def check_command
32
+ @command = /^git-(upload|receive)-pack '([^']*)'$/.match(ENV['SSH_ORIGINAL_COMMAND'])
33
+ message(:error, 'Invalid command.') unless @command
34
+ end
35
+
36
+ def parse_information
37
+ message(:info, 'Parsing request')
38
+ @repositories = Git.configuration['paths']['repositories']
39
+ @action = @command[1]
40
+ @repository = @command[2]
41
+ @user = ARGV[0]
42
+ end
43
+
44
+ def setup_environment
45
+ message(:info, 'Setting up environment')
46
+ ENV['GIT_USERNAME'] = @user
47
+ end
48
+
49
+ def authorize
50
+ message(:info, 'Checking authorization')
51
+ socket = UNIXSocket.new(Git.configuration['paths']['socket'])
52
+ socket.write("auth|#{@user}|#{@repository}|#{@action}\n")
53
+ unless socket.getc.to_s == '1'
54
+ message(:error, 'Invalid authorization.')
55
+ end
56
+ socket.close
57
+ end
58
+
59
+ def run_git
60
+ path = File.join(@repositories, @repository)
61
+ unless File.exists?(path)
62
+ message(:error, 'Invalid repository.')
63
+ end
64
+ exec("git #{@action}-pack #{path}")
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,32 @@
1
+ # Copyright 2011 Marek Jelen
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'wildcloud/configuration'
16
+
17
+ require 'wildcloud/git/logger'
18
+
19
+ module Wildcloud
20
+ module Git
21
+
22
+ def self.configuration
23
+ return @configuration if @configuration
24
+ config = Wildcloud::Configuration.load('git')
25
+ config.sources.each do |source|
26
+ self.logger.info('Configuration', "Loaded configuration from #{source}")
27
+ end
28
+ @configuration = config.configuration
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,155 @@
1
+ # Copyright 2011 Marek Jelen
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'wildcloud/git/configuration'
16
+ require 'wildcloud/git/logger'
17
+
18
+ require 'amqp'
19
+ require 'json'
20
+
21
+ module Wildcloud
22
+ module Git
23
+ class Core
24
+
25
+ def initialize
26
+ Git.logger.info('Core', 'Starting')
27
+
28
+ # Define basic variables
29
+ @access = {}
30
+ @keys = {}
31
+
32
+ # Connect to AMQP
33
+ Git.logger.info('Core', 'Connecting to broker')
34
+ @amqp = AMQP.connect(Git.configuration['amqp'])
35
+ Git.logger_add_amqp(@amqp)
36
+
37
+ # Communication infrastructure
38
+ @channel = AMQP::Channel.new(@amqp)
39
+ @topic = @channel.topic('wildcloud.git')
40
+ @queue = @channel.queue("wildcloud.git.#{Git.configuration['node']['name']}")
41
+ @queue.bind(@topic, :routing_key => 'nodes')
42
+ @queue.bind(@topic, :routing_key => "node.#{Git.configuration['node']['name']}")
43
+
44
+ # Request synchronization
45
+ Git.logger.info('Core', 'Requesting synchronization')
46
+ publish({ :node => Git.configuration['node']['name'], :type => :sync })
47
+
48
+ # Listen for task
49
+ @queue.subscribe do |metadata, message|
50
+ handle(metadata, message)
51
+ end
52
+ end
53
+
54
+ def authorize(username, repository, action)
55
+ return 1 if username == 'wildcloud.platform.master.key'
56
+ return 0 unless @access[username] && @access[username].include?(repository)
57
+ 1
58
+ end
59
+
60
+ def handle(metadata, message)
61
+ Git.logger.debug('Core', "Got message: #{message}")
62
+ message = JSON.parse(message)
63
+ method = "handle_#{message['type']}".to_sym
64
+ if respond_to?(method)
65
+ send(method, message)
66
+ else
67
+
68
+ end
69
+ end
70
+
71
+ def handle_sync(data)
72
+ @access = data['access']
73
+ @keys = data['keys']
74
+ sync_keys
75
+ end
76
+
77
+ def handle_add_key(data)
78
+ (@keys[data['username']] ||= []) << data['key']
79
+ sync_keys
80
+ end
81
+
82
+ def handle_remove_key(data)
83
+ keys = @keys[data['username']]
84
+ if keys
85
+ keys.delete(data['key'])
86
+ sync_keys
87
+ end
88
+ end
89
+
90
+ def handle_add_platform_key(data)
91
+ @platform_keys ||= []
92
+ @platform_keys << data['key'] unless @platform_keys.include?(data['key'])
93
+ sync_keys
94
+ end
95
+
96
+ def handle_remove_platform_key(data)
97
+ (@platform_keys ||= []).delete(data['key'])
98
+ sync_keys
99
+ end
100
+
101
+ def handle_create_repository(data)
102
+ path = File.join(Git.configuration['paths']['repositories'], data['repository'])
103
+ `git init --bare #{path} --template #{File.expand_path('../../template', __FILE__)}`
104
+ pre_receive = File.read(File.expand_path('../pre-receive.rb', __FILE__))
105
+ pre_receive = "#!#{Git.configuration['paths']['ruby']}\n#{pre_receive}"
106
+ hook_path = File.join(path, 'hooks', 'pre-receive')
107
+ File.open(hook_path, 'w') do |file|
108
+ file.write(pre_receive)
109
+ end
110
+ File.chmod(0700, hook_path)
111
+ end
112
+
113
+ def handle_destroy_repository(data)
114
+ `rm -rf #{File.join(Git.configuration['paths']['repositories'], data['repository'])}`
115
+ end
116
+
117
+ def handle_authorize_repository(data)
118
+ (@access[data['username']] ||= []) << data['repository']
119
+ end
120
+
121
+ def handle_unauthorize_repository(data)
122
+ repos = @access[data['username']]
123
+ repos.delete(data['repository']) if repos
124
+ end
125
+
126
+ def sync_keys
127
+ Git.logger.info('Core', 'Synchronizing keys')
128
+ data = ""
129
+ client = File.expand_path('../client.rb', __FILE__)
130
+ ks = us = 0
131
+ @platform_keys.each do |key|
132
+ data << "command=\"source /etc/profile && wildcloud-git-client 'wildcloud.platform.master.key'\" #{key}\n"
133
+ end if @platform_keys
134
+ @keys.each do |username, keys|
135
+ us += 1
136
+ keys.each do |key|
137
+ data << "command=\"source /etc/profile && wildcloud-git-client #{username}\" #{key}\n"
138
+ ks += 1
139
+ end
140
+ end if @keys
141
+ File.open('./.ssh/authorized_keys', 'w') do |file|
142
+ file.write(data)
143
+ end
144
+ Git.logger.info('Core', "Data synchronized (#{us} users, #{ks} keys)")
145
+ end
146
+
147
+ def publish(message)
148
+ Git.logger.debug('Core', "Publishing #{message.inspect}")
149
+ @topic.publish(JSON.dump(message), :routing_key => 'master')
150
+ end
151
+
152
+ end
153
+ end
154
+ end
155
+
@@ -0,0 +1,43 @@
1
+ # Copyright 2011 Marek Jelen
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'wildcloud/logger'
16
+ require 'wildcloud/logger/middleware/console'
17
+ require 'wildcloud/logger/middleware/amqp'
18
+ require 'wildcloud/logger/middleware/json'
19
+
20
+ require 'wildcloud/git/configuration'
21
+
22
+ module Wildcloud
23
+ module Git
24
+
25
+ def self.logger
26
+ return @logger if @logger
27
+ @logger = Wildcloud::Logger::Logger.new
28
+ @logger.application = ['wildcloud', 'git', self.configuration['node']['name']].join('.')
29
+ @logger.level = self.configuration['logger']['level'].to_s.to_sym if self.configuration['logger'] && self.configuration['logger']['level']
30
+ @logger.add(Wildcloud::Logger::Middleware::Console)
31
+ @logger
32
+ end
33
+
34
+ def self.logger_add_amqp(amqp)
35
+ @logger.add(Wildcloud::Logger::Middleware::Json)
36
+ @logger.add(Wildcloud::Logger::Middleware::Amqp,
37
+ :exchange => AMQP::Channel.new(amqp).topic('wildcloud.logger'),
38
+ :routing_key => proc { |message| message[:application] }
39
+ )
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,34 @@
1
+ # Copyright 2011 Marek Jelen
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'yaml'
16
+ require 'socket'
17
+
18
+ $: << File.expand_path('../../..', __FILE__)
19
+ require 'wildcloud/git/configuration'
20
+
21
+ # Constants
22
+ repositories = Wildcloud::Git.configuration['paths']['repositories']
23
+ user = ENV['GIT_USERNAME']
24
+ socket = UNIXSocket.new(Wildcloud::Git.configuration['paths']['socket'])
25
+
26
+ # One line per ref
27
+ $stdin.each_line do |line|
28
+ from, to, ref = line.split(' ')
29
+ ref.sub!('refs/heads/', '')
30
+ repo = File.expand_path('.').sub(repositories, '')
31
+ socket.write("push|#{user}|#{to}|#{ref}|#{repo}\n")
32
+ end
33
+
34
+ socket.close
@@ -0,0 +1,48 @@
1
+ # Copyright 2011 Marek Jelen
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Wildcloud
16
+ module Git
17
+ module Protocol
18
+
19
+ include EventMachine::Protocols::LineText2
20
+
21
+ def initialize(core)
22
+ @core = core
23
+ end
24
+
25
+ def receive_line(data)
26
+ type, data = data.split("|", 2)
27
+ method = "handle_#{type}".to_sym
28
+ if respond_to?(method)
29
+ send(method, data)
30
+ else
31
+ close_connection
32
+ end
33
+ end
34
+
35
+ def handle_auth(data)
36
+ username, repository, action = data.split("|", 3)
37
+ send_data(@core.authorize(username, repository, action))
38
+ close_connection_after_writing
39
+ end
40
+
41
+ def handle_push(data)
42
+ user, commit, ref, repository = data.split("|", 4)
43
+ @core.publish({ :type => 'push', :user => user, :commit => commit, :ref => ref, :repository => repository })
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,36 @@
1
+ # Copyright 2011 Marek Jelen
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'amqp'
16
+ require 'json'
17
+
18
+ require 'wildcloud/git/configuration'
19
+ require 'wildcloud/git/logger'
20
+ require 'wildcloud/git/core'
21
+ require 'wildcloud/git/protocol'
22
+
23
+ module Wildcloud
24
+ module Git
25
+ class Server
26
+
27
+ def self.start
28
+ Git.logger.info('Server', 'Starting')
29
+ @core = Wildcloud::Git::Core.new
30
+ EventMachine.start_server(Git.configuration['paths']['socket'], Wildcloud::Git::Protocol, @core)
31
+ Git.logger.info('Server', 'Started')
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ # Copyright 2011 Marek Jelen
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Wildcloud
16
+ module Git
17
+ VERSION = '0.0.1' unless const_defined?(:VERSION)
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ Template repository
@@ -0,0 +1,6 @@
1
+ # git ls-files --others --exclude-from=.git/info/exclude
2
+ # Lines that start with '#' are comments.
3
+ # For a project mostly in C, the following would be a good set of
4
+ # exclude patterns (uncomment them if you want to use them):
5
+ # *.[oa]
6
+ # *~
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wildcloud-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marek Jelen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: amqp
16
+ requirement: &2156400000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2156400000
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &2156398800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.4
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2156398800
36
+ - !ruby/object:Gem::Dependency
37
+ name: wildcloud-logger
38
+ requirement: &2156396560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - =
42
+ - !ruby/object:Gem::Version
43
+ version: 0.0.2
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2156396560
47
+ - !ruby/object:Gem::Dependency
48
+ name: wildcloud-configuration
49
+ requirement: &2156395880 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - =
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.1
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2156395880
58
+ description: Manages git repositories, authentication information for OpenSSH and
59
+ authorization.
60
+ email:
61
+ - marek@jelen.biz
62
+ executables:
63
+ - wildcloud-git
64
+ - wildcloud-git-client
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - bin/wildcloud-git
69
+ - bin/wildcloud-git-client
70
+ - lib/wildcloud/git/client.rb
71
+ - lib/wildcloud/git/configuration.rb
72
+ - lib/wildcloud/git/core.rb
73
+ - lib/wildcloud/git/logger.rb
74
+ - lib/wildcloud/git/pre-receive.rb
75
+ - lib/wildcloud/git/protocol.rb
76
+ - lib/wildcloud/git/server.rb
77
+ - lib/wildcloud/git/version.rb
78
+ - lib/wildcloud/git.rb
79
+ - lib/wildcloud/template/description
80
+ - lib/wildcloud/template/info/exclude
81
+ - LICENSE
82
+ - README.md
83
+ - CHANGELOG.md
84
+ homepage: http://github.com/wildcloud
85
+ licenses:
86
+ - Apache2
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: 1.3.6
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.10
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Git repositories management
109
+ test_files: []