Skip to content

Commit

Permalink
Process commands with Gitaly if a flag is passed from the app
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadsherif committed Dec 27, 2016
1 parent a3712cc commit 7d7bde9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/gitlab_access_status.rb
@@ -1,17 +1,18 @@
require 'json'

class GitAccessStatus
attr_reader :message, :repository_path
attr_reader :message, :repository_path, :gitaly_address

def initialize(status, message, repository_path)
def initialize(status, message, repository_path, gitaly_address = nil)
@status = status
@message = message
@repository_path = repository_path
@gitaly_address = gitaly_address
end

def self.create_from_json(json)
values = JSON.parse(json)
self.new(values["status"], values["message"], values["repository_path"])
self.new(values["status"], values["message"], values["repository_path"], values["gitaly_address"])
end

def allowed?
Expand Down
14 changes: 12 additions & 2 deletions lib/gitlab_shell.rb
Expand Up @@ -13,7 +13,7 @@ class InvalidRepositoryPathError < StandardError; end
API_COMMANDS = %w(2fa_recovery_codes)
GL_PROTOCOL = 'ssh'.freeze

attr_accessor :key_id, :repo_name, :command, :git_access
attr_accessor :key_id, :repo_name, :command, :git_access, :gitaly_address
attr_reader :repo_path

def initialize(key_id)
Expand Down Expand Up @@ -98,6 +98,7 @@ def verify_access
raise AccessDeniedError, status.message unless status.allowed?

self.repo_path = status.repository_path
self.gitaly_address = status.gitaly_address
end

def process_cmd(args)
Expand Down Expand Up @@ -126,9 +127,14 @@ def process_cmd(args)
$logger.info "gitlab-shell: Processing LFS authentication for #{log_username}."
lfs_authenticate
end
else
end

if gitaly_address.nil?
$logger.info "gitlab-shell: executing git command <#{@command} #{repo_path}> for #{log_username}."
exec_cmd(@command, repo_path)
else
$logger.info "gitlab-shell: processing with gitaly <#{gitaly_address}> command: <#{@command}> repo: <#{repo_path}> for <#{log_username}>."
process_cmd_with_gitaly(@command, repo_path)
end
end

Expand Down Expand Up @@ -165,6 +171,10 @@ def exec_cmd(*args)
Kernel::exec(env, *args, unsetenv_others: true)
end

def process_cmd_with_gitaly(cmd, repo_path)
# To be implemented
end

def api
GitlabNet.new
end
Expand Down

0 comments on commit 7d7bde9

Please sign in to comment.