Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of push and pull over ssh #303

Merged
merged 16 commits into from
Aug 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ vendor

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
tmp/

#Ignore swapfiles created by vim
*~
Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ gem 'cancancan', '~> 1.10'
# ruby implementation of git-http-backend
gem 'gitlab-grack', '~> 2.0.2', require: 'grack'

# used for api used by gitlab-shell
gem 'grape'

group :development, :test do
# https://github.com/rspec/rspec-rails/issues/1273
Expand All @@ -83,6 +85,7 @@ group :test do
gem 'launchy'
gem 'rubocop', require: false
gem 'haml-lint', require: false
gem 'shoulda-matchers'
end

# To use ActiveModel has_secure_password
Expand All @@ -92,7 +95,7 @@ end
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'
gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'
Expand Down
42 changes: 41 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ GEM
ast (2.0.0)
astrolabe (1.3.0)
parser (>= 2.2.0.pre.3, < 3.0)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.10)
better_errors (2.1.1)
coderay (>= 1.0.0)
Expand All @@ -70,6 +74,8 @@ GEM
celluloid (0.16.0)
timers (~> 4.0.0)
coderay (1.1.0)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
Expand All @@ -84,6 +90,8 @@ GEM
delayed_job_active_record (4.0.3)
activerecord (>= 3.0, < 5.0)
delayed_job (>= 3.0, < 4.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (3.4.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand All @@ -92,6 +100,7 @@ GEM
thread_safe (~> 0.1)
warden (~> 1.2.3)
diff-lcs (1.2.5)
equalizer (0.0.11)
erubis (2.7.0)
escape (0.0.4)
execjs (2.4.0)
Expand All @@ -108,6 +117,16 @@ GEM
formatador (0.2.5)
gitlab-grack (2.0.2)
rack (~> 1.5.1)
grape (0.12.0)
activesupport
builder
hashie (>= 2.1.0)
multi_json (>= 1.3.2)
multi_xml (>= 0.5.2)
rack (>= 1.3.0)
rack-accept
rack-mount
virtus (>= 1.0.0)
guard (2.12.4)
formatador (>= 0.2.4)
listen (~> 2.7)
Expand Down Expand Up @@ -135,6 +154,7 @@ GEM
hike (1.2.3)
hitimes (1.2.2)
i18n (0.7.0)
ice_nine (0.11.1)
jquery-rails (3.1.2)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
Expand All @@ -143,6 +163,7 @@ GEM
turbolinks
json (1.8.2)
jwt (1.4.1)
kgio (2.9.3)
launchy (2.4.3)
addressable (~> 2.3)
libv8 (3.16.14.7)
Expand Down Expand Up @@ -216,6 +237,10 @@ GEM
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.5.2)
rack-accept (0.4.5)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
Expand All @@ -239,6 +264,7 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
raindrops (0.15.0)
rake (10.4.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
Expand Down Expand Up @@ -293,6 +319,8 @@ GEM
sass-rails (~> 5.0.0.beta1)
sprockets (>= 2.3.0)
shellany (0.0.1)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
sketchily (4.0.1)
nokogiri
rails (>= 3.1)
Expand Down Expand Up @@ -325,6 +353,15 @@ GEM
uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
unicorn (4.9.0)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
warden (1.2.3)
rack (>= 1.0)
will_paginate (3.0.7)
Expand Down Expand Up @@ -352,6 +389,7 @@ DEPENDENCIES
factory_girl_rails
faker
gitlab-grack (~> 2.0.2)
grape
guard-rspec
guard-rubocop (~> 1.2.0)
haml
Expand Down Expand Up @@ -381,13 +419,15 @@ DEPENDENCIES
rugged (~> 0.21)
sass-rails
sass-rails-source-maps
shoulda-matchers
sketchily
sqlite3
test-unit
therubyracer
turbolinks
uglifier
unicorn
will_paginate

BUNDLED WITH
1.10.2
1.10.5
2 changes: 1 addition & 1 deletion app/assets/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $("document").ready( function(){
if(articleContent === "login"){
$(".wrapper nav").css("display", "none");
}
var toolbarDivs = $("section.toolbar div, section.action div");
var toolbarDivs = $("section.toolbar div, section.action div, aside nav ul li");
toolbarDivs.each(function(){
if($(this).attr("data") === articleContent){
$(this).addClass("active");
Expand Down
7 changes: 3 additions & 4 deletions app/assets/stylesheets/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ $nprogress-color: red;
}
}
}

table {
width: 100%;
}
section{
background-color: white;
padding: 0.25em;
Expand Down Expand Up @@ -100,9 +102,6 @@ $nprogress-color: red;
}
}
}
table {
width: 100%;
}
}
}
aside{
Expand Down
38 changes: 38 additions & 0 deletions app/controllers/keys_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class KeysController < ApplicationController
before_filter :authenticate_user!

def index
@key = current_user.keys.new
current_user.keys.delete @key # remove new key from collection
@keys = current_user.keys
end

def create
@key = current_user.keys.new(key_params)

if @key.save
redirect_to keys_path
else
# remove unsaved key from collection
current_user.keys.delete @key
@keys = current_user.keys
render 'index'
end
end

def destroy
@key = current_user.keys.find(params[:id])
if @key.destroy
redirect_to :back
else
flash[:alert] = 'Something went wrong. Please retry after some time.'
redirect_to :back
end
end

private

def key_params
params.require(:key).permit(:title, :key)
end
end
49 changes: 49 additions & 0 deletions app/models/key.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'digest/md5'

class Key < ActiveRecord::Base

belongs_to :user

before_validation :strip_white_space, :generate_fingerprint

validates :title, presence: true, length: { within: 0..255 }
validates :key, presence: true,
length: { within: 0..5000 },
format: { with: /\A(ssh|ecdsa)-.*\Z/ },
uniqueness: true
validates :key, format: { without: /\n|\r/, message: 'not a single line' }
validates :fingerprint, uniqueness: true,
presence: { message: 'cannot be generated' }

after_create :add_to_shell
after_destroy :remove_from_shell

def shell_id
"key-#{id}"
end

private

def generate_fingerprint
self.fingerprint = nil

return unless key.present?

self.fingerprint = Gg::KeyFingerprint.new(key).fingerprint
end

# add the key to authorized file and limit access to git
# only commands
def add_to_shell
Gg::Shell.add_key(shell_id, key)
end

# remove key from authorized files after key is deleted
def remove_from_shell
Gg::Shell.remove_key(shell_id, key)
end

def strip_white_space
self.key = key.strip unless key.blank?
end
end
14 changes: 14 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def init
if parent.nil?
Rugged::Repository.init_at barerepopath, :bare
Rugged::Repository.clone_at barerepopath, satelliterepopath
sym_hook
else # it's a fork, therefore:
Rugged::Repository.init_at barerepopath, :bare
Rugged::Repository.clone_at parent.satelliterepopath, satelliterepopath
Expand All @@ -429,4 +430,17 @@ def init

pushtobare unless satelliterepo.empty?
end

# makes a symlink to hooks in gitlab-shell in each project
# dir structure:
# |--home/username
# |--GlitterGallery
# |--gitlab-shell
def sym_hook
local_hooks_directory = File.join(barerepopath, 'hooks')
shell_hook_dir = File.join(Glitter::Application.config.shell_path, 'hooks')
new_dir_name = "#{local_hooks_directory}.old.#{Time.now.to_i}"
FileUtils.mv(local_hooks_directory, new_dir_name)
FileUtils.ln_s(shell_hook_dir, local_hooks_directory)
end
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class User < ActiveRecord::Base
has_many :member_projects, through: :project_members,
source: :member_project
has_many :issues
# authorization of ssh access
has_many :keys

VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

Expand Down
16 changes: 16 additions & 0 deletions app/views/devise/registrations/_user_aside.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%aside
%h1
User Settings
%nav
%ul
%li{ data: 'profile' }
= link_to 'Profile', edit_user_registration_path
%li{ data: 'identities' }
= link_to 'Identities', identities_path
%li{ data: 'keys' }
= link_to 'SSH Keys', keys_path
-#
%li
= link_to 'Passwords'
%li
= link_to 'Projects', identities_path
19 changes: 2 additions & 17 deletions app/views/devise/registrations/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- content_for :title do
= current_user.username.titleize

%article
%article.user{ data: 'profile' }
%header
%h1
= avatar current_user.email
Expand Down Expand Up @@ -37,19 +37,4 @@
%div
= f.submit 'Update'

%aside
%h1
User Settings
%nav
%ul
%li.active
= link_to 'Profile', edit_user_registration_path
%li
= link_to 'Identities', identities_path
-#
%li
= link_to 'Passwords'
%li
= link_to 'SSH Keys', identities_path
%li
= link_to 'Projects', identities_path
= render 'user_aside'
Loading