giticious 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +48 -0
- data/LICENSE +25 -0
- data/Rakefile +1 -0
- data/Vagrantfile +12 -0
- data/bin/giticious +12 -0
- data/giticious.gemspec +30 -0
- data/install/ubuntu-vivid.sh +9 -0
- data/lib/giticious/check.rb +47 -0
- data/lib/giticious/cli/main.rb +58 -0
- data/lib/giticious/cli/pubkey.rb +56 -0
- data/lib/giticious/cli/repo.rb +102 -0
- data/lib/giticious/cli/user.rb +44 -0
- data/lib/giticious/model/permission.rb +8 -0
- data/lib/giticious/model/repository.rb +7 -0
- data/lib/giticious/model/user.rb +7 -0
- data/lib/giticious/service/pubkey.rb +99 -0
- data/lib/giticious/service/repository.rb +127 -0
- data/lib/giticious/service/user.rb +43 -0
- data/lib/giticious/setup.rb +44 -0
- data/lib/giticious/version.rb +3 -0
- data/lib/giticious.rb +35 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6d514ef61f14192a657a7b868e2508dea4dac0bf
|
4
|
+
data.tar.gz: 8ff3a3cec1c9c53c990f1260376ca86c50534db7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 863decc9dc894b3e839a570553ba045d2f64823667eeff1fc48b8b6b00c85827d9be64dc81433c8af22f6de7673463afcace3e3e756dbc38f9fb4bce2fc44a9f
|
7
|
+
data.tar.gz: 0f30e5c058b9f053b35ae5b15f0f2a53bb67ff0eb08b3d526cee9225057545c942386e9094b45bf7e816ea2e84544e8fbd423f0a9cdebec95d674d8f6a9d3bae
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
giticious (0.8.0)
|
5
|
+
activerecord (~> 4.2.0)
|
6
|
+
sqlite3 (~> 1.3.0)
|
7
|
+
terminal-table (~> 1.4.5)
|
8
|
+
thor (~> 0.19.1)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activemodel (4.2.5)
|
14
|
+
activesupport (= 4.2.5)
|
15
|
+
builder (~> 3.1)
|
16
|
+
activerecord (4.2.5)
|
17
|
+
activemodel (= 4.2.5)
|
18
|
+
activesupport (= 4.2.5)
|
19
|
+
arel (~> 6.0)
|
20
|
+
activesupport (4.2.5)
|
21
|
+
i18n (~> 0.7)
|
22
|
+
json (~> 1.7, >= 1.7.7)
|
23
|
+
minitest (~> 5.1)
|
24
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
25
|
+
tzinfo (~> 1.1)
|
26
|
+
arel (6.0.3)
|
27
|
+
builder (3.2.2)
|
28
|
+
i18n (0.7.0)
|
29
|
+
json (1.8.3)
|
30
|
+
minitest (5.8.3)
|
31
|
+
rake (10.4.2)
|
32
|
+
sqlite3 (1.3.11)
|
33
|
+
terminal-table (1.4.5)
|
34
|
+
thor (0.19.1)
|
35
|
+
thread_safe (0.3.5)
|
36
|
+
tzinfo (1.2.2)
|
37
|
+
thread_safe (~> 0.1)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
bundler (~> 1.7)
|
44
|
+
giticious!
|
45
|
+
rake (~> 10.0)
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
1.10.6
|
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2015 David Prandzioch
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
15
|
+
all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
25
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/Vagrantfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Vagrant.configure(2) do |config|
|
2
|
+
config.vm.box = "ubuntu/vivid64"
|
3
|
+
config.vm.network "private_network", ip: "192.168.33.10"
|
4
|
+
|
5
|
+
config.vm.provision "shell", inline: <<-SHELL
|
6
|
+
sudo apt-get update
|
7
|
+
sudo apt-get install -y git ruby ruby-dev libsqlite3-dev build-essential
|
8
|
+
sudo gem install rake bundler
|
9
|
+
cd /vagrant
|
10
|
+
sudo bundle install
|
11
|
+
SHELL
|
12
|
+
end
|
data/bin/giticious
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
THIS_FILE = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
5
|
+
require File.join(File.dirname(THIS_FILE), '../lib/giticious.rb')
|
6
|
+
|
7
|
+
require File.join(File.dirname(THIS_FILE), '../lib/giticious/cli/repo.rb')
|
8
|
+
require File.join(File.dirname(THIS_FILE), '../lib/giticious/cli/pubkey.rb')
|
9
|
+
require File.join(File.dirname(THIS_FILE), '../lib/giticious/cli/user.rb')
|
10
|
+
require File.join(File.dirname(THIS_FILE), '../lib/giticious/cli/main.rb')
|
11
|
+
|
12
|
+
Giticious::Cli::Main.start(ARGV)
|
data/giticious.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'giticious/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'giticious'
|
8
|
+
spec.version = Giticious::VERSION
|
9
|
+
spec.authors = ['David Prandzioch']
|
10
|
+
spec.email = ['kontakt@davidprandzioch.de']
|
11
|
+
spec.summary = %q{Giticious is a simple Git with user management}
|
12
|
+
spec.description = ''
|
13
|
+
spec.homepage = 'http://dprandzioch.github.io/giticious/'
|
14
|
+
spec.license = 'MIT Expat'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = ['giticious']
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.0.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
|
26
|
+
spec.add_dependency 'terminal-table', '~> 1.4'
|
27
|
+
spec.add_dependency 'thor', '~> 0.19'
|
28
|
+
spec.add_dependency 'sqlite3', '~> 1.3'
|
29
|
+
spec.add_dependency 'activerecord', '~> 4.2'
|
30
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
sudo apt-get update
|
4
|
+
sudo apt-get install -y git ruby ruby-dev libsqlite3-dev build-essential
|
5
|
+
sudo gem install giticious
|
6
|
+
|
7
|
+
echo "Please start SSH service on port 22 and enable PubkeyAuthentication."
|
8
|
+
echo "Now create a user called 'git', log in and run 'giticious init'."
|
9
|
+
echo "From then on, your Git server can be managed through the giticious CLI util."
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
module Giticious
|
5
|
+
class Check
|
6
|
+
|
7
|
+
def self.run
|
8
|
+
if self.git_installed? == false
|
9
|
+
raise RuntimeError, "Git is not installed"
|
10
|
+
end
|
11
|
+
|
12
|
+
if self.repository_dir_exists? == false
|
13
|
+
raise RuntimeError, "Repository dir not found! Please run the init command"
|
14
|
+
end
|
15
|
+
|
16
|
+
if self.ssh_alive? == false
|
17
|
+
raise RuntimeError, "SSH service not listening on Port 22! Please enable it and use public key auth"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
def self.git_installed?
|
23
|
+
`which git 2>/dev/null` and $?.success?
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.repository_dir_exists?
|
27
|
+
Dir.exists?("#{Dir.home}/repositories")
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.ssh_alive?
|
31
|
+
begin
|
32
|
+
Timeout::timeout(5) do
|
33
|
+
begin
|
34
|
+
s = TCPSocket.new("127.0.0.1", 22)
|
35
|
+
s.close
|
36
|
+
return true
|
37
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
rescue Timeout::Error
|
42
|
+
end
|
43
|
+
|
44
|
+
false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Giticious
|
2
|
+
module Cli
|
3
|
+
class Main < Thor
|
4
|
+
package_name 'Giticious'
|
5
|
+
|
6
|
+
desc "version", "Prints versioning information"
|
7
|
+
def version
|
8
|
+
puts "Giticious: #{Giticious::VERSION}"
|
9
|
+
puts "Ruby: #{RUBY_VERSION}"
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "check", "Checks if the Giticious installation is healthy"
|
13
|
+
def check
|
14
|
+
begin
|
15
|
+
Giticious::Check.run
|
16
|
+
puts "Everything looks fine!"
|
17
|
+
rescue => e
|
18
|
+
$stderr.puts e.message
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "init", "Initializes the Git server"
|
24
|
+
def init
|
25
|
+
begin
|
26
|
+
Giticious::Setup.run
|
27
|
+
rescue => e
|
28
|
+
$stderr.puts e.message
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "gitserve", "Hidden task to serve git ssh requests", hide: true
|
34
|
+
def gitserve(user)
|
35
|
+
abort unless user
|
36
|
+
|
37
|
+
command_match = ENV["SSH_ORIGINAL_COMMAND"].match(/(git\-upload\-pack|git\-receive\-pack) \'([A-Za-z0-9\-_\.]+)\.git\'/)
|
38
|
+
abort "Project not found / Command invalid" if command_match.nil?
|
39
|
+
|
40
|
+
repo = command_match[2]
|
41
|
+
perms = Giticious::Service::Repository.new.permissions_for(repo, user)
|
42
|
+
abort "You have no access to #{repo}" if perms == false
|
43
|
+
|
44
|
+
command = "#{command_match[1]} 'repositories/#{command_match[2]}.git'"
|
45
|
+
|
46
|
+
abort "Read access denied" unless perms.perm_read
|
47
|
+
abort "Write access denied" unless action == "git-receive-pack" and perms.perm_write
|
48
|
+
|
49
|
+
Kernel.exec "git", "shell", "-c", command
|
50
|
+
end
|
51
|
+
|
52
|
+
register(Giticious::Cli::Repo, "repo", "repo COMMAND", "Manage repositories")
|
53
|
+
register(Giticious::Cli::User, "user", "user COMMAND", "Manage users")
|
54
|
+
register(Giticious::Cli::Pubkey, "pubkey", "pubkey COMMAND", "Manage pubkeys")
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Giticious
|
2
|
+
module Cli
|
3
|
+
class Pubkey < Thor
|
4
|
+
|
5
|
+
desc "add USERNAME PUBKEY", "Adds a public key to a user"
|
6
|
+
def add(username, pubkey)
|
7
|
+
begin
|
8
|
+
if Giticious::Service::User.new.exists?(username) == false
|
9
|
+
$stderr.puts "A user with this name does not exist"
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
giticious_path = File.realpath(File.join(Giticious::LIBDIR, "..", "..", "bin", "giticious"))
|
14
|
+
|
15
|
+
if Giticious::Service::Pubkey.new.add(username, pubkey, giticious_path)
|
16
|
+
puts "Public key \"#{pubkey.split(//).last(80).join}\" for user #{username} has been added!"
|
17
|
+
end
|
18
|
+
|
19
|
+
list(username)
|
20
|
+
rescue => e
|
21
|
+
$stderr.puts e.message
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "delete PUBKEY", "Removes a public key from user (a part of the key is enough, but make it unique)"
|
27
|
+
def delete(pubkey)
|
28
|
+
begin
|
29
|
+
Giticious::Service::Pubkey.new.delete(pubkey)
|
30
|
+
rescue => e
|
31
|
+
$stderr.puts e.message
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "list USERNAME", "List registered public keys for user"
|
37
|
+
def list(username)
|
38
|
+
begin
|
39
|
+
rows = []
|
40
|
+
|
41
|
+
Giticious::Service::Pubkey.new.user_pubkeys(username).each do |pubkey|
|
42
|
+
rows << [ username, pubkey.split(//).last(80).join ]
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
table = Terminal::Table.new :headings => ["Username", "Public key (last 80 chars)"], :rows => rows
|
47
|
+
puts table
|
48
|
+
rescue => e
|
49
|
+
$stderr.puts e.message
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Giticious
|
2
|
+
module Cli
|
3
|
+
class Repo < Thor
|
4
|
+
|
5
|
+
desc "create NAME", "Create a new repository"
|
6
|
+
def create(name)
|
7
|
+
begin
|
8
|
+
if Giticious::Service::Repository.new.create(name) == false
|
9
|
+
$stderr.puts "Could not create repository"
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
puts "The repository has been created"
|
14
|
+
|
15
|
+
list()
|
16
|
+
rescue => e
|
17
|
+
$stderr.puts e.message
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "delete", "Removes a repository"
|
23
|
+
def delete(name)
|
24
|
+
begin
|
25
|
+
Giticious::Service::Repository.new.delete(name)
|
26
|
+
rescue => e
|
27
|
+
$stderr.puts e.message
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "list", "List all repositories"
|
33
|
+
def list
|
34
|
+
begin
|
35
|
+
rows = []
|
36
|
+
|
37
|
+
Giticious::Service::Repository.new.list.each do |repo|
|
38
|
+
rows << [ repo.name, repo.path, "#{Etc.getlogin}@xxx:#{repo.name}.git" ]
|
39
|
+
end
|
40
|
+
|
41
|
+
table = Terminal::Table.new :headings => ["Name", "Path", "SSH URL"], :rows => rows
|
42
|
+
puts table
|
43
|
+
rescue => e
|
44
|
+
$stderr.puts e.message
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "users REPO", "List all users with access to a repository"
|
50
|
+
def users(repo)
|
51
|
+
begin
|
52
|
+
rows = []
|
53
|
+
|
54
|
+
Giticious::Service::Repository.new.permissions(repo).each do |perm|
|
55
|
+
rows << [ repo, perm.user.username, perm.perm_read, perm.perm_write ]
|
56
|
+
end
|
57
|
+
|
58
|
+
table = Terminal::Table.new :headings => ["Repository", "User", "Read", "Write"], :rows => rows
|
59
|
+
puts table
|
60
|
+
rescue => e
|
61
|
+
$stderr.puts e.message
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "permit REPO USERNAME ACCESS", "Gives a user permissions to access a repository (access: r,w,rw)"
|
67
|
+
def permit(repo, username, permissions)
|
68
|
+
begin
|
69
|
+
if Giticious::Service::Repository.new.add_user(repo, username, permissions) == false
|
70
|
+
$stderr.puts "Could not grant permissions to this user"
|
71
|
+
exit 1
|
72
|
+
end
|
73
|
+
|
74
|
+
puts "Permission granted!"
|
75
|
+
|
76
|
+
users(repo)
|
77
|
+
rescue => e
|
78
|
+
$stderr.puts e.message
|
79
|
+
exit 1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "revoke REPO USERNAME", "Revokes user it's permissions to the repository"
|
84
|
+
def revoke(repo, username)
|
85
|
+
begin
|
86
|
+
if Giticious::Service::Repository.new.delete_user(repo, username) == false
|
87
|
+
$stderr.puts "Could not revoke permissions from this user"
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
|
91
|
+
puts "Permission revoked!"
|
92
|
+
|
93
|
+
users(repo)
|
94
|
+
rescue => e
|
95
|
+
$stderr.puts e.message
|
96
|
+
exit 1
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Giticious
|
2
|
+
module Cli
|
3
|
+
class User < Thor
|
4
|
+
|
5
|
+
desc "create USERNAME", "Creates a new user"
|
6
|
+
def create(username)
|
7
|
+
begin
|
8
|
+
if Giticious::Service::User.new.create(username)
|
9
|
+
puts "User #{username} has been created!"
|
10
|
+
end
|
11
|
+
|
12
|
+
list()
|
13
|
+
rescue => e
|
14
|
+
$stderr.puts e.message
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "delete USERNAME", "Deletes a user"
|
20
|
+
def delete(username)
|
21
|
+
begin
|
22
|
+
Giticious::Service::User.new.delete_by_username(username)
|
23
|
+
rescue => e
|
24
|
+
$stderr.puts e.message
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "list", "Lists all users"
|
30
|
+
def list
|
31
|
+
begin
|
32
|
+
rows = Giticious::Service::User.new.list.map { |result| result.values }
|
33
|
+
|
34
|
+
table = Terminal::Table.new :headings => ["#", "Username"], :rows => rows
|
35
|
+
puts table
|
36
|
+
rescue => e
|
37
|
+
$stderr.puts e.message
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Giticious
|
2
|
+
module Service
|
3
|
+
class Pubkey
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@filename = "#{Dir.home}/.ssh/authorized_keys"
|
7
|
+
|
8
|
+
if false == File.exists?(@filename)
|
9
|
+
FileUtils.touch(@filename)
|
10
|
+
end
|
11
|
+
|
12
|
+
if false == File.owned?(@filename)
|
13
|
+
raise RuntimeError, "File #{@filename} is not owned by the current user"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def exists?(pubkey)
|
18
|
+
File.open(@filename) do |file|
|
19
|
+
file.each_line do |line|
|
20
|
+
return true if line.include?(pubkey)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def add(user, pubkey, giticious_path)
|
28
|
+
if exists?(pubkey)
|
29
|
+
raise RuntimeError, "This public key does already exist"
|
30
|
+
end
|
31
|
+
|
32
|
+
append_line('command="' + giticious_path + ' gitserve ' + user + '",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ' + pubkey)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(pubkey)
|
36
|
+
delete_matches(pubkey)
|
37
|
+
end
|
38
|
+
|
39
|
+
def all
|
40
|
+
matches = {}
|
41
|
+
|
42
|
+
File.open(@filename) do |file|
|
43
|
+
file.each_line do |line|
|
44
|
+
res = line.match(/gitserve ([A-Za-z0-9_]+)\".*no\-pty (.*)/)
|
45
|
+
|
46
|
+
if res.nil? == false
|
47
|
+
username = res[1]
|
48
|
+
key = res[2]
|
49
|
+
|
50
|
+
if matches.has_key?(username) == false
|
51
|
+
matches[username] = []
|
52
|
+
end
|
53
|
+
|
54
|
+
matches[username] << key
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
matches
|
60
|
+
end
|
61
|
+
|
62
|
+
def user_pubkeys(user)
|
63
|
+
pubkeys = all()
|
64
|
+
|
65
|
+
if pubkeys.has_key?(user)
|
66
|
+
return pubkeys[user]
|
67
|
+
end
|
68
|
+
|
69
|
+
return []
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
def file_contents
|
74
|
+
File.read(@filename)
|
75
|
+
end
|
76
|
+
|
77
|
+
def append_line(line)
|
78
|
+
IO.write(@filename, "#{line}\n", mode: "a")
|
79
|
+
end
|
80
|
+
|
81
|
+
def delete_matches(search)
|
82
|
+
if search == ""
|
83
|
+
return nil
|
84
|
+
end
|
85
|
+
|
86
|
+
new_file = ""
|
87
|
+
|
88
|
+
File.open(@filename) do |file|
|
89
|
+
file.each_line do |line|
|
90
|
+
new_file += "#{line}" unless line.include?(search)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
IO.write(@filename, new_file, mode: "w+")
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module Giticious
|
2
|
+
module Service
|
3
|
+
class Repository
|
4
|
+
|
5
|
+
def list
|
6
|
+
Giticious::Model::Repository.all
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(name)
|
10
|
+
path = "#{Dir.home}/repositories/#{name}.git"
|
11
|
+
|
12
|
+
if init_repository(path) == false
|
13
|
+
raise RuntimeError, "Could not initi Git repository"
|
14
|
+
end
|
15
|
+
|
16
|
+
repo = Giticious::Model::Repository.new
|
17
|
+
repo.name = name
|
18
|
+
repo.path = path
|
19
|
+
|
20
|
+
repo.save!
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(name)
|
24
|
+
repo = Giticious::Model::Repository.find_by_name(name)
|
25
|
+
|
26
|
+
if repo.nil?
|
27
|
+
raise ArgumentError, "The selected repository does not exist"
|
28
|
+
end
|
29
|
+
|
30
|
+
Giticious::Model::Permission.where(repository_id: repo.id).delete_all
|
31
|
+
FileUtils.rm_rf("#{Dir.home}/repositories/#{repo.name}.git")
|
32
|
+
|
33
|
+
repo.delete
|
34
|
+
end
|
35
|
+
|
36
|
+
def permissions(repo)
|
37
|
+
repo = Giticious::Model::Repository.find_by_name(repo)
|
38
|
+
|
39
|
+
if repo.nil?
|
40
|
+
raise ArgumentError, "The selected repository does not exist"
|
41
|
+
end
|
42
|
+
|
43
|
+
repo.permissions
|
44
|
+
end
|
45
|
+
|
46
|
+
def permissions_for(repo_name, username)
|
47
|
+
repo = Giticious::Model::Repository.find_by_name(repo_name)
|
48
|
+
|
49
|
+
if repo.nil?
|
50
|
+
raise ArgumentError, "The selected repository does not exist"
|
51
|
+
end
|
52
|
+
|
53
|
+
user = Giticious::Model::User.find_by_username(username)
|
54
|
+
|
55
|
+
if user.nil?
|
56
|
+
raise ArgumentError, "The selected user does not exist"
|
57
|
+
end
|
58
|
+
|
59
|
+
permissions = Giticious::Model::Permission.where(user_id: user.id, repository_id: repo.id)
|
60
|
+
|
61
|
+
if permissions.empty?
|
62
|
+
return false
|
63
|
+
end
|
64
|
+
|
65
|
+
return permissions.first!
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_user(repo_name, username)
|
69
|
+
repo = Giticious::Model::Repository.find_by_name(repo_name)
|
70
|
+
|
71
|
+
if repo.nil?
|
72
|
+
raise ArgumentError, "The selected repository does not exist"
|
73
|
+
end
|
74
|
+
|
75
|
+
user = Giticious::Model::User.find_by_username(username)
|
76
|
+
|
77
|
+
if user.nil?
|
78
|
+
raise ArgumentError, "The selected user does not exist"
|
79
|
+
end
|
80
|
+
|
81
|
+
perms = Giticious::Model::Permission.where(user_id: user.id, repository_id: repo.id)
|
82
|
+
|
83
|
+
if perms.empty?
|
84
|
+
raise ArgumentError, "This user does not have permissions"
|
85
|
+
end
|
86
|
+
|
87
|
+
perms.delete_all
|
88
|
+
end
|
89
|
+
|
90
|
+
def add_user(repo_name, username, permissions)
|
91
|
+
repo = Giticious::Model::Repository.find_by_name(repo_name)
|
92
|
+
|
93
|
+
if repo.nil?
|
94
|
+
raise ArgumentError, "The selected repository does not exist"
|
95
|
+
end
|
96
|
+
|
97
|
+
user = Giticious::Model::User.find_by_username(username)
|
98
|
+
|
99
|
+
if user.nil?
|
100
|
+
raise ArgumentError, "The selected user does not exist"
|
101
|
+
end
|
102
|
+
|
103
|
+
if Giticious::Model::Permission.where(user_id: user.id, repository_id: repo.id).empty? == false
|
104
|
+
raise ArgumentError, "This user does already have permissions"
|
105
|
+
end
|
106
|
+
|
107
|
+
perm = Giticious::Model::Permission.new
|
108
|
+
perm.repository_id = repo.id
|
109
|
+
perm.user_id = user.id
|
110
|
+
perm.perm_read = permissions.include?("r")
|
111
|
+
perm.perm_write = permissions.include?("w")
|
112
|
+
|
113
|
+
perm.save!
|
114
|
+
end
|
115
|
+
|
116
|
+
protected
|
117
|
+
def init_repository(path)
|
118
|
+
if Dir.exists?(path)
|
119
|
+
raise ArgumentError, "repo path #{path} does already exist"
|
120
|
+
end
|
121
|
+
|
122
|
+
`git init --bare #{path}` and $?.success?
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Giticious
|
2
|
+
module Service
|
3
|
+
class User
|
4
|
+
|
5
|
+
def list
|
6
|
+
users = []
|
7
|
+
|
8
|
+
Giticious::Model::User.all.each do |user|
|
9
|
+
users << {
|
10
|
+
id: user.id,
|
11
|
+
username: user.username,
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
users
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(username)
|
19
|
+
if Giticious::Model::User.find_by_username(username).nil? == false
|
20
|
+
raise ArgumentError, "a user with this name does already exist"
|
21
|
+
end
|
22
|
+
|
23
|
+
user = Giticious::Model::User.new
|
24
|
+
user.username = username
|
25
|
+
|
26
|
+
user.save!
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_by_username(username)
|
30
|
+
user = Giticious::Model::User.find_by_user(username).first!
|
31
|
+
|
32
|
+
Giticious::Model::Permission.find_by_user_id(user.id).delete_all!
|
33
|
+
|
34
|
+
user.destroy!
|
35
|
+
end
|
36
|
+
|
37
|
+
def exists?(username)
|
38
|
+
Giticious::Model::User.find_by_username(username).nil? == false
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Giticious
|
2
|
+
class Setup
|
3
|
+
|
4
|
+
def self.run
|
5
|
+
self.create_config_dir
|
6
|
+
self.create_repo_dir
|
7
|
+
self.migrate_db
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
def self.migrate_db
|
12
|
+
ActiveRecord::Schema.define do
|
13
|
+
create_table :repositories do |table|
|
14
|
+
table.column :name, :string, :unique => true
|
15
|
+
table.column :path, :string
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :users do |table|
|
19
|
+
table.column :username, :string, :unique => true
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :permissions do |table|
|
23
|
+
table.column :user_id, :integer
|
24
|
+
table.column :repository_id, :integer
|
25
|
+
table.column :perm_read, :boolean
|
26
|
+
table.column :perm_write, :boolean
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.create_config_dir
|
32
|
+
config_dir = "#{Dir.home}/.giticious"
|
33
|
+
|
34
|
+
FileUtils.mkdir(config_dir) unless Dir.exists?(config_dir)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.create_repo_dir
|
38
|
+
repo_dir = "#{Dir.home}/repositories"
|
39
|
+
|
40
|
+
FileUtils.mkdir(repo_dir) unless Dir.exists?(repo_dir)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/giticious.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'terminal-table'
|
2
|
+
require 'open3'
|
3
|
+
require 'resolv'
|
4
|
+
require 'logger'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'sqlite3'
|
7
|
+
require 'active_record'
|
8
|
+
require 'etc'
|
9
|
+
|
10
|
+
#ActiveRecord::Base.logger = Logger.new(STDERR)
|
11
|
+
|
12
|
+
ActiveRecord::Base.establish_connection(
|
13
|
+
:adapter => "sqlite3",
|
14
|
+
:database => "#{Dir.home}/.giticious/database.sqlite"
|
15
|
+
)
|
16
|
+
|
17
|
+
require File.join(File.dirname(__FILE__), 'giticious/version')
|
18
|
+
|
19
|
+
require File.join(File.dirname(__FILE__), 'giticious/model/user')
|
20
|
+
require File.join(File.dirname(__FILE__), 'giticious/model/repository')
|
21
|
+
require File.join(File.dirname(__FILE__), 'giticious/model/permission')
|
22
|
+
|
23
|
+
require File.join(File.dirname(__FILE__), 'giticious/service/pubkey')
|
24
|
+
require File.join(File.dirname(__FILE__), 'giticious/service/user')
|
25
|
+
require File.join(File.dirname(__FILE__), 'giticious/service/repository')
|
26
|
+
|
27
|
+
require File.join(File.dirname(__FILE__), 'giticious/check')
|
28
|
+
require File.join(File.dirname(__FILE__), 'giticious/setup')
|
29
|
+
|
30
|
+
module Giticious
|
31
|
+
LIBNAME = 'giticious'
|
32
|
+
LIBDIR = File.expand_path("../#{LIBNAME}", __FILE__)
|
33
|
+
|
34
|
+
# build params
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: giticious
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Prandzioch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: terminal-table
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.19'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.19'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.2'
|
97
|
+
description: ''
|
98
|
+
email:
|
99
|
+
- kontakt@davidprandzioch.de
|
100
|
+
executables:
|
101
|
+
- giticious
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- LICENSE
|
108
|
+
- Rakefile
|
109
|
+
- Vagrantfile
|
110
|
+
- bin/giticious
|
111
|
+
- giticious.gemspec
|
112
|
+
- install/ubuntu-vivid.sh
|
113
|
+
- lib/giticious.rb
|
114
|
+
- lib/giticious/check.rb
|
115
|
+
- lib/giticious/cli/main.rb
|
116
|
+
- lib/giticious/cli/pubkey.rb
|
117
|
+
- lib/giticious/cli/repo.rb
|
118
|
+
- lib/giticious/cli/user.rb
|
119
|
+
- lib/giticious/model/permission.rb
|
120
|
+
- lib/giticious/model/repository.rb
|
121
|
+
- lib/giticious/model/user.rb
|
122
|
+
- lib/giticious/service/pubkey.rb
|
123
|
+
- lib/giticious/service/repository.rb
|
124
|
+
- lib/giticious/service/user.rb
|
125
|
+
- lib/giticious/setup.rb
|
126
|
+
- lib/giticious/version.rb
|
127
|
+
homepage: http://dprandzioch.github.io/giticious/
|
128
|
+
licenses:
|
129
|
+
- MIT Expat
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 2.0.0
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.4.8
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Giticious is a simple Git with user management
|
151
|
+
test_files: []
|