summaryrefslogtreecommitdiff
path: root/lib/gitlab/gitaly_client.rb
blob: b981a629fb0a00f83f9a628595667bca32ee427c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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