diff options
author | Alejandro RodrÃguez <alejorro70@gmail.com> | 2017-02-05 15:04:23 -0300 |
---|---|---|
committer | Alejandro RodrÃguez <alejorro70@gmail.com> | 2017-03-01 18:46:59 -0300 |
commit | f8fa6e6f472179cfd9261a35d309d986f8db8ebd (patch) | |
tree | dcbaa836cbc91c15fc0aa77e5610a23f874b1934 /lib | |
parent | b6a945b39354ec2b2c09fc5f6904dfbf8990df26 (diff) | |
download | gitlab-ce-f8fa6e6f472179cfd9261a35d309d986f8db8ebd.tar.gz |
Add internal endpoint to notify post-receive to Gitalygitaly-post-receive
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/internal.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 29 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/notifications.rb | 17 |
3 files changed, 58 insertions, 0 deletions
diff --git a/lib/api/internal.rb b/lib/api/internal.rb index d235977fbd8..7eed93aba00 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -132,6 +132,18 @@ module API { success: true, recovery_codes: codes } end + + post "/notify_post_receive" do + status 200 + + return unless Gitlab::GitalyClient.enabled? + + begin + Gitlab::GitalyClient::Notifications.new.post_receive(params[:repo_path]) + rescue GRPC::Unavailable => e + render_api_error(e, 500) + end + end end end end diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb new file mode 100644 index 00000000000..b981a629fb0 --- /dev/null +++ b/lib/gitlab/gitaly_client.rb @@ -0,0 +1,29 @@ +require 'gitaly' + +module Gitlab + module GitalyClient + def self.gitaly_address + if Gitlab.config.gitaly.socket_path + "unix://#{Gitlab.config.gitaly.socket_path}" + end + end + + def self.channel + return @channel if defined?(@channel) + + @channel = + if enabled? + # NOTE: Gitaly currently runs on a Unix socket, so permissions are + # handled using the file system and no additional authentication is + # required (therefore the :this_channel_is_insecure flag) + GRPC::Core::Channel.new(gitaly_address, {}, :this_channel_is_insecure) + else + nil + end + end + + def self.enabled? + gitaly_address.present? + end + end +end diff --git a/lib/gitlab/gitaly_client/notifications.rb b/lib/gitlab/gitaly_client/notifications.rb new file mode 100644 index 00000000000..b827a56207f --- /dev/null +++ b/lib/gitlab/gitaly_client/notifications.rb @@ -0,0 +1,17 @@ +module Gitlab + module GitalyClient + class Notifications + attr_accessor :stub + + def initialize + @stub = Gitaly::Notifications::Stub.new(nil, nil, channel_override: GitalyClient.channel) + end + + def post_receive(repo_path) + repository = Gitaly::Repository.new(path: repo_path) + request = Gitaly::PostReceiveRequest.new(repository: repository) + stub.post_receive(request) + end + end + end +end |