Class: GitAclShell::Shell
- Inherits:
-
Object
- Object
- GitAclShell::Shell
- Defined in:
- lib/git_acl_shell/shell.rb
Constant Summary collapse
- COMMAND_WHITELIST =
See git-scm.com/docs/git-shell#_commands
(git push) (git fetch) (git archive) %w(git-receive-pack git-upload-pack git-upload-archive).freeze
Instance Method Summary collapse
- #exec(command) ⇒ Object
-
#initialize(key_id, acl:, directory:, kernel: Kernel, stderr: $stderr) ⇒ Shell
constructor
A new instance of Shell.
Constructor Details
#initialize(key_id, acl:, directory:, kernel: Kernel, stderr: $stderr) ⇒ Shell
10 11 12 13 14 15 16 |
# File 'lib/git_acl_shell/shell.rb', line 10 def initialize(key_id, acl:, directory:, kernel: Kernel, stderr: $stderr) @key_id = key_id @acl = acl @directory = directory @kernel = kernel @stderr = stderr end |
Instance Method Details
#exec(command) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/git_acl_shell/shell.rb', line 18 def exec(command) if command.nil? @stderr.puts("OH HAI! U HAS LOGGD IN BUT WE DOAN PROVIDE SHELL ACCES. KTHXBAI!") return false end args = Shellwords.shellwords(command) if whitelist?(args) repo_path = args.pop repo_extension = File.extname(repo_path) repo_alias = File.basename(repo_path, repo_extension) begin repo_name = @directory.lookup(repo_alias) repo_path = File.join(File.dirname(repo_path), "#{repo_name}#{repo_extension}") args.push(repo_path) rescue UnknownAlias @stderr.puts("Not found") return false end if @acl.(@key_id, repo_name) @kernel.exec(*args) true else @stderr.puts("You've successfully authenticated, but you don't have access to this repo") false end else @stderr.puts("OH HAI! I CAN ONLY HALP U WIF GIT COMMANDZ, SRY! KTHXBAI!") false end end |