summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb10
-rw-r--r--lib/api/files.rb42
-rw-r--r--lib/api/namespaces.rb2
-rw-r--r--lib/api/project_hooks.rb13
-rw-r--r--lib/api/projects.rb34
-rw-r--r--lib/api/users.rb2
-rw-r--r--lib/backup/database.rb10
-rw-r--r--lib/backup/manager.rb10
-rw-r--r--lib/backup/repository.rb14
-rw-r--r--lib/backup/uploads.rb2
-rw-r--r--lib/gitlab/backend/grack_auth.rb36
-rw-r--r--lib/gitlab/backend/grack_helpers.rb2
-rw-r--r--lib/gitlab/backend/shell.rb39
-rw-r--r--lib/gitlab/ldap/user.rb6
-rw-r--r--lib/gitlab/oauth/user.rb2
-rw-r--r--lib/gitlab/satellite/files/delete_file_action.rb50
-rw-r--r--lib/gitlab/satellite/files/edit_file_action.rb13
-rw-r--r--lib/gitlab/satellite/files/file_action.rb4
-rw-r--r--lib/gitlab/satellite/files/new_file_action.rb19
-rw-r--r--lib/gitlab/satellite/merge_action.rb2
-rw-r--r--lib/gitlab/satellite/satellite.rb2
-rw-r--r--lib/gitlab/upgrader.rb96
-rw-r--r--lib/gitlab/visibility_level.rb42
-rwxr-xr-xlib/support/deploy/deploy.sh9
-rwxr-xr-xlib/support/init.d/gitlab22
-rwxr-xr-xlib/support/init.d/gitlab.default.example14
-rw-r--r--lib/support/nginx/gitlab3
-rw-r--r--lib/tasks/gitlab/check.rake46
-rw-r--r--lib/tasks/gitlab/task_helpers.rake10
29 files changed, 463 insertions, 93 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 2bdcbdc8c7f..7daf8ace242 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -24,6 +24,10 @@ module API
expose :id, :url, :created_at
end
+ class ProjectHook < Hook
+ expose :project_id, :push_events, :issues_events, :merge_requests_events
+ end
+
class ForkedFromProject < Grape::Entity
expose :id
expose :name, :name_with_namespace
@@ -31,11 +35,13 @@ module API
end
class Project < Grape::Entity
- expose :id, :description, :default_branch, :public, :ssh_url_to_repo, :http_url_to_repo, :web_url
+ expose :id, :description, :default_branch
+ expose :public?, as: :public
+ expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url
expose :owner, using: Entities::UserBasic
expose :name, :name_with_namespace
expose :path, :path_with_namespace
- expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at, :public
+ expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at
expose :namespace
expose :forked_from_project, using: Entities::ForkedFromProject, :if => lambda{ | project, options | project.forked? }
end
diff --git a/lib/api/files.rb b/lib/api/files.rb
index e467b0f8e9a..6a5419a580f 100644
--- a/lib/api/files.rb
+++ b/lib/api/files.rb
@@ -8,8 +8,7 @@ module API
# Create new file in repository
#
# Parameters:
- # file_name (required) - The name of new file. Ex. class.rb
- # file_path (optional) - The path to new file. Ex. lib/
+ # file_path (optional) - The path to new file. Ex. lib/class.rb
# branch_name (required) - The name of branch
# content (required) - File content
# commit_message (required) - Commit message
@@ -18,8 +17,8 @@ module API
# POST /projects/:id/repository/files
#
post ":id/repository/files" do
- required_attributes! [:file_name, :branch_name, :content, :commit_message]
- attrs = attributes_for_keys [:file_name, :file_path, :branch_name, :content, :commit_message]
+ required_attributes! [:file_path, :branch_name, :content, :commit_message]
+ attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message]
branch_name = attrs.delete(:branch_name)
file_path = attrs.delete(:file_path)
result = ::Files::CreateContext.new(user_project, current_user, attrs, branch_name, file_path).execute
@@ -28,7 +27,6 @@ module API
status(201)
{
- file_name: attrs[:file_name],
file_path: file_path,
branch_name: branch_name
}
@@ -40,8 +38,7 @@ module API
# Update existing file in repository
#
# Parameters:
- # file_name (required) - The name of new file. Ex. class.rb
- # file_path (optional) - The path to new file. Ex. lib/
+ # file_path (optional) - The path to file. Ex. lib/class.rb
# branch_name (required) - The name of branch
# content (required) - File content
# commit_message (required) - Commit message
@@ -67,7 +64,36 @@ module API
render_api_error!(result[:error], 400)
end
end
+
+ # Delete existing file in repository
+ #
+ # Parameters:
+ # file_path (optional) - The path to file. Ex. lib/class.rb
+ # branch_name (required) - The name of branch
+ # content (required) - File content
+ # commit_message (required) - Commit message
+ #
+ # Example Request:
+ # DELETE /projects/:id/repository/files
+ #
+ delete ":id/repository/files" do
+ required_attributes! [:file_path, :branch_name, :commit_message]
+ attrs = attributes_for_keys [:file_path, :branch_name, :commit_message]
+ branch_name = attrs.delete(:branch_name)
+ file_path = attrs.delete(:file_path)
+ result = ::Files::DeleteContext.new(user_project, current_user, attrs, branch_name, file_path).execute
+
+ if result[:status] == :success
+ status(200)
+
+ {
+ file_path: file_path,
+ branch_name: branch_name
+ }
+ else
+ render_api_error!(result[:error], 400)
+ end
+ end
end
end
end
-
diff --git a/lib/api/namespaces.rb b/lib/api/namespaces.rb
index 3a9ab66957e..f9f2ed90ccc 100644
--- a/lib/api/namespaces.rb
+++ b/lib/api/namespaces.rb
@@ -12,7 +12,7 @@ module API
# Example Request:
# GET /namespaces
get do
- @namespaces = Namespace.scoped
+ @namespaces = Namespace.all
@namespaces = @namespaces.search(params[:search]) if params[:search].present?
@namespaces = paginate @namespaces
diff --git a/lib/api/project_hooks.rb b/lib/api/project_hooks.rb
index 738974955f3..c271dd8b61b 100644
--- a/lib/api/project_hooks.rb
+++ b/lib/api/project_hooks.rb
@@ -22,7 +22,7 @@ module API
# GET /projects/:id/hooks
get ":id/hooks" do
@hooks = paginate user_project.hooks
- present @hooks, with: Entities::Hook
+ present @hooks, with: Entities::ProjectHook
end
# Get a project hook
@@ -34,7 +34,7 @@ module API
# GET /projects/:id/hooks/:hook_id
get ":id/hooks/:hook_id" do
@hook = user_project.hooks.find(params[:hook_id])
- present @hook, with: Entities::Hook
+ present @hook, with: Entities::ProjectHook
end
@@ -47,10 +47,11 @@ module API
# POST /projects/:id/hooks
post ":id/hooks" do
required_attributes! [:url]
+ attrs = attributes_for_keys [:url, :push_events, :issues_events, :merge_requests_events]
+ @hook = user_project.hooks.new(attrs)
- @hook = user_project.hooks.new({"url" => params[:url]})
if @hook.save
- present @hook, with: Entities::Hook
+ present @hook, with: Entities::ProjectHook
else
if @hook.errors[:url].present?
error!("Invalid url given", 422)
@@ -70,10 +71,10 @@ module API
put ":id/hooks/:hook_id" do
@hook = user_project.hooks.find(params[:hook_id])
required_attributes! [:url]
+ attrs = attributes_for_keys [:url, :push_events, :issues_events, :merge_requests_events]
- attrs = attributes_for_keys [:url]
if @hook.update_attributes attrs
- present @hook, with: Entities::Hook
+ present @hook, with: Entities::ProjectHook
else
if @hook.errors[:url].present?
error!("Invalid url given", 422)
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 42560572046..003533fb59a 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -11,6 +11,13 @@ module API
end
not_found!
end
+
+ def map_public_to_visibility_level(attrs)
+ publik = attrs.delete(:public)
+ publik = [ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(publik)
+ attrs[:visibility_level] = Gitlab::VisibilityLevel::PUBLIC if !attrs[:visibility_level].present? && publik == true
+ attrs
+ end
end
# Get a projects list for authenticated user
@@ -31,6 +38,16 @@ module API
present @projects, with: Entities::Project
end
+ # Get all projects for admin user
+ #
+ # Example Request:
+ # GET /projects/all
+ get '/all' do
+ authenticated_as_admin!
+ @projects = paginate Project
+ present @projects, with: Entities::Project
+ end
+
# Get a single project
#
# Parameters:
@@ -66,7 +83,8 @@ module API
# wiki_enabled (optional)
# snippets_enabled (optional)
# namespace_id (optional) - defaults to user namespace
- # public (optional) - false by default
+ # public (optional) - if true same as setting visibility_level = 20
+ # visibility_level (optional) - 0 by default
# Example Request
# POST /projects
post do
@@ -80,7 +98,9 @@ module API
:wiki_enabled,
:snippets_enabled,
:namespace_id,
- :public]
+ :public,
+ :visibility_level]
+ attrs = map_public_to_visibility_level(attrs)
@project = ::Projects::CreateContext.new(current_user, attrs).execute
if @project.saved?
present @project, with: Entities::Project
@@ -104,7 +124,8 @@ module API
# merge_requests_enabled (optional)
# wiki_enabled (optional)
# snippets_enabled (optional)
- # public (optional)
+ # public (optional) - if true same as setting visibility_level = 20
+ # visibility_level (optional)
# Example Request
# POST /projects/user/:user_id
post "user/:user_id" do
@@ -118,7 +139,9 @@ module API
:merge_requests_enabled,
:wiki_enabled,
:snippets_enabled,
- :public]
+ :public,
+ :visibility_level]
+ attrs = map_public_to_visibility_level(attrs)
@project = ::Projects::CreateContext.new(user, attrs).execute
if @project.saved?
present @project, with: Entities::Project
@@ -280,7 +303,8 @@ module API
# GET /projects/search/:query
get "/search/:query" do
ids = current_user.authorized_projects.map(&:id)
- projects = Project.where("(id in (?) OR public = true) AND (name LIKE (?))", ids, "%#{params[:query]}%")
+ visibility_levels = [ Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC ]
+ projects = Project.where("(id in (?) OR visibility_level in (?)) AND (name LIKE (?))", ids, visibility_levels, "%#{params[:query]}%")
present paginate(projects), with: Entities::Project
end
end
diff --git a/lib/api/users.rb b/lib/api/users.rb
index 54d3aeecb70..475343a3edf 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -9,7 +9,7 @@ module API
# Example Request:
# GET /users
get do
- @users = User.scoped
+ @users = User.all
@users = @users.active if params[:active].present?
@users = @users.search(params[:search]) if params[:search].present?
@users = paginate @users
diff --git a/lib/backup/database.rb b/lib/backup/database.rb
index c4fb2e2e159..7af7140246a 100644
--- a/lib/backup/database.rb
+++ b/lib/backup/database.rb
@@ -13,20 +13,20 @@ module Backup
def dump
case config["adapter"]
when /^mysql/ then
- system("mysqldump #{mysql_args} #{config['database']} > #{db_file_name}")
+ system('mysqldump', *mysql_args, config['database'], out: db_file_name)
when "postgresql" then
pg_env
- system("pg_dump #{config['database']} > #{db_file_name}")
+ system('pg_dump', config['database'], out: db_file_name)
end
end
def restore
case config["adapter"]
when /^mysql/ then
- system("mysql #{mysql_args} #{config['database']} < #{db_file_name}")
+ system('mysql', *mysql_args, config['database'], in: db_file_name)
when "postgresql" then
pg_env
- system("psql #{config['database']} -f #{db_file_name}")
+ system('psql', config['database'], '-f', db_file_name)
end
end
@@ -45,7 +45,7 @@ module Backup
'encoding' => '--default-character-set',
'password' => '--password'
}
- args.map { |opt, arg| "#{arg}='#{config[opt]}'" if config[opt] }.compact.join(' ')
+ args.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
end
def pg_env
diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb
index 258a0fb2589..efaefa4ce44 100644
--- a/lib/backup/manager.rb
+++ b/lib/backup/manager.rb
@@ -1,5 +1,7 @@
module Backup
class Manager
+ BACKUP_CONTENTS = %w{repositories/ db/ uploads/ backup_information.yml}
+
def pack
# saving additional informations
s = {}
@@ -16,7 +18,7 @@ module Backup
# create archive
print "Creating backup archive: #{s[:backup_created_at].to_i}_gitlab_backup.tar ... "
- if Kernel.system("tar -cf #{s[:backup_created_at].to_i}_gitlab_backup.tar repositories/ db/ uploads/ backup_information.yml")
+ if Kernel.system('tar', '-cf', "#{s[:backup_created_at].to_i}_gitlab_backup.tar", *BACKUP_CONTENTS)
puts "done".green
else
puts "failed".red
@@ -25,7 +27,7 @@ module Backup
def cleanup
print "Deleting tmp directories ... "
- if Kernel.system("rm -rf repositories/ db/ uploads/ backup_information.yml")
+ if Kernel.system('rm', '-rf', *BACKUP_CONTENTS)
puts "done".green
else
puts "failed".red
@@ -44,7 +46,7 @@ module Backup
file_list.map! { |f| $1.to_i if f =~ /(\d+)_gitlab_backup.tar/ }
file_list.sort.each do |timestamp|
if Time.at(timestamp) < (Time.now - keep_time)
- if system("rm #{timestamp}_gitlab_backup.tar")
+ if Kernel.system(*%W(rm #{timestamp}_gitlab_backup.tar))
removed += 1
end
end
@@ -75,7 +77,7 @@ module Backup
end
print "Unpacking backup ... "
- unless Kernel.system("tar -xf #{tar_file}")
+ unless Kernel.system(*%W(tar -xf #{tar_file}))
puts "failed".red
exit 1
else
diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb
index 252201f11be..20fd5ba92a1 100644
--- a/lib/backup/repository.rb
+++ b/lib/backup/repository.rb
@@ -18,7 +18,7 @@ module Backup
# Create namespace dir if missing
FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.path)) if project.namespace
- if system("cd #{path_to_repo(project)} > /dev/null 2>&1 && git bundle create #{path_to_bundle(project)} --all > /dev/null 2>&1")
+ if system(*%W(git --git-dir=#{path_to_repo(project)} bundle create #{path_to_bundle(project)} --all), silent)
puts "[DONE]".green
else
puts "[FAILED]".red
@@ -30,7 +30,7 @@ module Backup
print " * #{wiki.path_with_namespace} ... "
if wiki.empty?
puts " [SKIPPED]".cyan
- elsif system("cd #{path_to_repo(wiki)} > /dev/null 2>&1 && git bundle create #{path_to_bundle(wiki)} --all > /dev/null 2>&1")
+ elsif system(*%W(git --git-dir=#{path_to_repo(wiki)} bundle create #{path_to_bundle(wiki)} --all), silent)
puts " [DONE]".green
else
puts " [FAILED]".red
@@ -53,7 +53,7 @@ module Backup
project.namespace.ensure_dir_exist if project.namespace
- if system("git clone --bare #{path_to_bundle(project)} #{path_to_repo(project)} > /dev/null 2>&1")
+ if system(*%W(git clone --bare #{path_to_bundle(project)} #{path_to_repo(project)}), silent)
puts "[DONE]".green
else
puts "[FAILED]".red
@@ -63,7 +63,7 @@ module Backup
if File.exists?(path_to_bundle(wiki))
print " * #{wiki.path_with_namespace} ... "
- if system("git clone --bare #{path_to_bundle(wiki)} #{path_to_repo(wiki)} > /dev/null 2>&1")
+ if system(*%W(git clone --bare #{path_to_bundle(wiki)} #{path_to_repo(wiki)}), silent)
puts " [DONE]".green
else
puts " [FAILED]".red
@@ -73,7 +73,7 @@ module Backup
print 'Put GitLab hooks in repositories dirs'.yellow
gitlab_shell_user_home = File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}")
- if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh #{Gitlab.config.gitlab_shell.repos_path}")
+ if system("#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh", Gitlab.config.gitlab_shell.repos_path)
puts " [DONE]".green
else
puts " [FAILED]".red
@@ -103,5 +103,9 @@ module Backup
FileUtils.rm_rf(backup_repos_path)
FileUtils.mkdir_p(backup_repos_path)
end
+
+ def silent
+ {err: '/dev/null', out: '/dev/null'}
+ end
end
end
diff --git a/lib/backup/uploads.rb b/lib/backup/uploads.rb
index 462d3f1e274..e79da7e8fd2 100644
--- a/lib/backup/uploads.rb
+++ b/lib/backup/uploads.rb
@@ -19,7 +19,7 @@ module Backup
FileUtils.cp_r(backup_uploads_dir, app_uploads_dir)
end
-
+
def backup_existing_uploads_dir
if File.exists?(app_uploads_dir)
FileUtils.mv(app_uploads_dir, Rails.root.join('public', "uploads.#{Time.now.to_i}"))
diff --git a/lib/gitlab/backend/grack_auth.rb b/lib/gitlab/backend/grack_auth.rb
index e09cf311972..c629144118c 100644
--- a/lib/gitlab/backend/grack_auth.rb
+++ b/lib/gitlab/backend/grack_auth.rb
@@ -58,7 +58,7 @@ module Grack
end
else
- return unauthorized unless project.public
+ return unauthorized unless project.public?
end
if authorized_git_request?
@@ -80,15 +80,19 @@ module Grack
def authorize_request(service)
case service
when 'git-upload-pack'
- project.public || can?(user, :download_code, project)
+ can?(user, :download_code, project)
when'git-receive-pack'
- action = if project.protected_branch?(ref)
- :push_code_to_protected_branches
- else
- :push_code
- end
+ refs.each do |ref|
+ action = if project.protected_branch?(ref)
+ :push_code_to_protected_branches
+ else
+ :push_code
+ end
+
+ return false unless can?(user, action, project)
+ end
- can?(user, action, project)
+ true
else
false
end
@@ -108,11 +112,11 @@ module Grack
@project ||= project_by_path(@request.path_info)
end
- def ref
- @ref ||= parse_ref
+ def refs
+ @refs ||= parse_refs
end
- def parse_ref
+ def parse_refs
input = if @env["HTTP_CONTENT_ENCODING"] =~ /gzip/
Zlib::GzipReader.new(@request.body).read
else
@@ -121,7 +125,15 @@ module Grack
# Need to reset seek point
@request.body.rewind
- /refs\/heads\/([\/\w\.-]+)/n.match(input.force_encoding('ascii-8bit')).to_a.last
+
+ # Parse refs
+ refs = input.force_encoding('ascii-8bit').scan(/refs\/heads\/([\/\w\.-]+)/n).flatten.compact
+
+ # Cleanup grabare from refs
+ # if push to multiple branches
+ refs.map do |ref|
+ ref.gsub(/00.*/, "")
+ end
end
end
end
diff --git a/lib/gitlab/backend/grack_helpers.rb b/lib/gitlab/backend/grack_helpers.rb
index 5ac9e9f325b..cb747fe0137 100644
--- a/lib/gitlab/backend/grack_helpers.rb
+++ b/lib/gitlab/backend/grack_helpers.rb
@@ -1,7 +1,7 @@
module Grack
module Helpers
def project_by_path(path)
- if m = /^\/([\w\.\/-]+)\.git/.match(path).to_a
+ if m = /^([\w\.\/-]+)\.git/.match(path).to_a
path_with_namespace = m.last
path_with_namespace.gsub!(/\.wiki$/, '')
diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb
index c819ce56ac9..7121c8e40d2 100644
--- a/lib/gitlab/backend/shell.rb
+++ b/lib/gitlab/backend/shell.rb
@@ -10,7 +10,7 @@ module Gitlab
# add_repository("gitlab/gitlab-ci")
#
def add_repository(name)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "add-project", "#{name}.git"
+ system "#{gitlab_shell_path}/bin/gitlab-projects", "add-project", "#{name}.git"
end
# Import repository
@@ -21,7 +21,7 @@ module Gitlab
# import_repository("gitlab/gitlab-ci", "https://github.com/randx/six.git")
#
def import_repository(name, url)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "import-project", "#{name}.git", url
+ system "#{gitlab_shell_path}/bin/gitlab-projects", "import-project", "#{name}.git", url
end
# Move repository
@@ -33,7 +33,7 @@ module Gitlab
# mv_repository("gitlab/gitlab-ci", "randx/gitlab-ci-new.git")
#
def mv_repository(path, new_path)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "mv-project", "#{path}.git", "#{new_path}.git"
+ system "#{gitlab_shell_path}/bin/gitlab-projects", "mv-project", "#{path}.git", "#{new_path}.git"
end
# Update HEAD for repository
@@ -45,7 +45,7 @@ module Gitlab
# update_repository_head("gitlab/gitlab-ci", "3-1-stable")
#
def update_repository_head(path, branch)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "update-head", "#{path}.git", branch
+ system "#{gitlab_shell_path}/bin/gitlab-projects", "update-head", "#{path}.git", branch
end
# Fork repository to new namespace
@@ -57,7 +57,7 @@ module Gitlab
# fork_repository("gitlab/gitlab-ci", "randx")
#
def fork_repository(path, fork_namespace)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "fork-project", "#{path}.git", fork_namespace
+ system "#{gitlab_shell_path}/bin/gitlab-projects", "fork-project", "#{path}.git", fork_namespace
end
# Remove repository from file system
@@ -68,7 +68,7 @@ module Gitlab
# remove_repository("gitlab/gitlab-ci")
#
def remove_repository(name)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-project", "#{name}.git"
+ system "#{gitlab_shell_path}/bin/gitlab-projects", "rm-project", "#{name}.git"
end
# Add repository branch from passed ref
@@ -81,7 +81,7 @@ module Gitlab
# add_branch("gitlab/gitlab-ci", "4-0-stable", "master")
#
def add_branch(path, branch_name, ref)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "create-branch", "#{path}.git", branch_name, ref
+ system "#{gitlab_shell_path}/bin/gitlab-projects", "create-branch", "#{path}.git", branch_name, ref
end
# Remove repository branch
@@ -93,7 +93,7 @@ module Gitlab
# rm_branch("gitlab/gitlab-ci", "4-0-stable")
#
def rm_branch(path, branch_name)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-branch", "#{path}.git", branch_name
+ system "#{gitlab_shell_path}/bin/gitlab-projects", "rm-branch", "#{path}.git", branch_name
end
# Add repository tag from passed ref
@@ -106,7 +106,7 @@ module Gitlab
# add_tag("gitlab/gitlab-ci", "v4.0", "master")
#
def add_tag(path, tag_name, ref)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "create-tag", "#{path}.git", tag_name, ref
+ system "#{gitlab_shell_path}/bin/gitlab-projects", "create-tag", "#{path}.git", tag_name, ref
end
# Remove repository tag
@@ -118,7 +118,7 @@ module Gitlab
# rm_tag("gitlab/gitlab-ci", "v4.0")
#
def rm_tag(path, tag_name)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-tag", "#{path}.git", tag_name
+ system "#{gitlab_shell_path}/bin/gitlab-projects", "rm-tag", "#{path}.git", tag_name
end
# Add new key to gitlab-shell
@@ -127,7 +127,7 @@ module Gitlab
# add_key("key-42", "sha-rsa ...")
#
def add_key(key_id, key_content)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-keys", "add-key", key_id, key_content
+ system "#{gitlab_shell_path}/bin/gitlab-keys", "add-key", key_id, key_content
end
# Remove ssh key from gitlab shell
@@ -136,7 +136,7 @@ module Gitlab
# remove_key("key-342", "sha-rsa ...")
#
def remove_key(key_id, key_content)
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-keys", "rm-key", key_id, key_content
+ system "#{gitlab_shell_path}/bin/gitlab-keys", "rm-key", key_id, key_content
end
# Remove all ssh keys from gitlab shell
@@ -145,7 +145,7 @@ module Gitlab
# remove_all_keys
#
def remove_all_keys
- system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-keys", "clear"
+ system "#{gitlab_shell_path}/bin/gitlab-keys", "clear"
end
# Add empty directory for storing repositories
@@ -196,8 +196,21 @@ module Gitlab
Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git"
end
+ # Return GitLab shell version
+ def version
+ gitlab_shell_version_file = "#{gitlab_shell_path}/VERSION"
+
+ if File.readable?(gitlab_shell_version_file)
+ File.read(gitlab_shell_version_file)
+ end
+ end
+
protected
+ def gitlab_shell_path
+ Gitlab.config.gitlab_shell.path
+ end
+
def gitlab_shell_user_home
File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}")
end
diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb
index 3d57f3a2e35..59f0fa64a6a 100644
--- a/lib/gitlab/ldap/user.rb
+++ b/lib/gitlab/ldap/user.rb
@@ -23,8 +23,8 @@ module Gitlab
# Look for user with same emails
#
# Possible cases:
- # * When user already has account and need to link his LDAP account.
- # * LDAP uid changed for user with same email and we need to update his uid
+ # * When user already has account and need to link their LDAP account.
+ # * LDAP uid changed for user with same email and we need to update their uid
#
user = find_user(email)
@@ -47,7 +47,7 @@ module Gitlab
user = model.find_by_email(email)
# If no user found and allow_username_or_email_login is true
- # we look for user by extracting part of his email
+ # we look for user by extracting part of their email
if !user && email && ldap_conf['allow_username_or_email_login']
uname = email.partition('@').first
user = model.find_by_username(uname)
diff --git a/lib/gitlab/oauth/user.rb b/lib/gitlab/oauth/user.rb
index ea9badba2c3..529753c4019 100644
--- a/lib/gitlab/oauth/user.rb
+++ b/lib/gitlab/oauth/user.rb
@@ -28,8 +28,8 @@ module Gitlab
}
user = model.build_user(opts, as: :admin)
+ user.skip_confirmation!
user.save!
- user.confirm!
log.info "(OAuth) Creating user #{email} from login with extern_uid => #{uid}"
if Gitlab.config.omniauth['block_auto_created_users'] && !ldap?
diff --git a/lib/gitlab/satellite/files/delete_file_action.rb b/lib/gitlab/satellite/files/delete_file_action.rb
new file mode 100644
index 00000000000..30462999aa3
--- /dev/null
+++ b/lib/gitlab/satellite/files/delete_file_action.rb
@@ -0,0 +1,50 @@
+require_relative 'file_action'
+
+module Gitlab
+ module Satellite
+ class DeleteFileAction < FileAction
+ # Deletes file and creates a new commit for it
+ #
+ # Returns false if committing the change fails
+ # Returns false if pushing from the satellite to bare repo failed or was rejected
+ # Returns true otherwise
+ def commit!(content, commit_message)
+ in_locked_and_timed_satellite do |repo|
+ prepare_satellite!(repo)
+
+ # create target branch in satellite at the corresponding commit from bare repo
+ repo.git.checkout({raise: true, timeout: true, b: true}, ref, "origin/#{ref}")
+
+ # update the file in the satellite's working dir
+ file_path_in_satellite = File.join(repo.working_dir, file_path)
+
+ # Prevent relative links
+ unless safe_path?(file_path_in_satellite)
+ Gitlab::GitLogger.error("FileAction: Relative path not allowed")
+ return false
+ end
+
+ File.delete(file_path_in_satellite)
+
+ # add removed file
+ repo.remove(file_path_in_satellite)
+
+ # commit the changes
+ # will raise CommandFailed when commit fails
+ repo.git.commit(raise: true, timeout: true, a: true, m: commit_message)
+
+
+ # push commit back to bare repo
+ # will raise CommandFailed when push fails
+ repo.git.push({raise: true, timeout: true}, :origin, ref)
+
+ # everything worked
+ true
+ end
+ rescue Grit::Git::CommandFailed => ex
+ Gitlab::GitLogger.error(ex.message)
+ false
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/satellite/files/edit_file_action.rb b/lib/gitlab/satellite/files/edit_file_action.rb
index 3747c6afc48..f410ecb7984 100644
--- a/lib/gitlab/satellite/files/edit_file_action.rb
+++ b/lib/gitlab/satellite/files/edit_file_action.rb
@@ -8,17 +8,24 @@ module Gitlab
#
# Returns false if the ref has been updated while editing the file
# Returns false if committing the change fails
- # Returns false if pushing from the satellite to Gitolite failed or was rejected
+ # Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns true otherwise
def commit!(content, commit_message)
in_locked_and_timed_satellite do |repo|
prepare_satellite!(repo)
- # create target branch in satellite at the corresponding commit from Gitolite
+ # create target branch in satellite at the corresponding commit from bare repo
repo.git.checkout({raise: true, timeout: true, b: true}, ref, "origin/#{ref}")
# update the file in the satellite's working dir
file_path_in_satellite = File.join(repo.working_dir, file_path)
+
+ # Prevent relative links
+ unless safe_path?(file_path_in_satellite)
+ Gitlab::GitLogger.error("FileAction: Relative path not allowed")
+ return false
+ end
+
File.open(file_path_in_satellite, 'w') { |f| f.write(content) }
# commit the changes
@@ -26,7 +33,7 @@ module Gitlab
repo.git.commit(raise: true, timeout: true, a: true, m: commit_message)
- # push commit back to Gitolite
+ # push commit back to bare repo
# will raise CommandFailed when push fails
repo.git.push({raise: true, timeout: true}, :origin, ref)
diff --git a/lib/gitlab/satellite/files/file_action.rb b/lib/gitlab/satellite/files/file_action.rb
index 7c08e292192..0f7afde647d 100644
--- a/lib/gitlab/satellite/files/file_action.rb
+++ b/lib/gitlab/satellite/files/file_action.rb
@@ -8,6 +8,10 @@ module Gitlab
@file_path = file_path
@ref = ref
end
+
+ def safe_path?(path)
+ File.absolute_path(path) == path
+ end
end
end
end
diff --git a/lib/gitlab/satellite/files/new_file_action.rb b/lib/gitlab/satellite/files/new_file_action.rb
index 97b19809c8d..57d101ff535 100644
--- a/lib/gitlab/satellite/files/new_file_action.rb
+++ b/lib/gitlab/satellite/files/new_file_action.rb
@@ -7,17 +7,28 @@ module Gitlab
#
# Returns false if the ref has been updated while editing the file
# Returns false if committing the change fails
- # Returns false if pushing from the satellite to Gitolite failed or was rejected
+ # Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns true otherwise
def commit!(content, commit_message)
in_locked_and_timed_satellite do |repo|
prepare_satellite!(repo)
- # create target branch in satellite at the corresponding commit from Gitolite
+ # create target branch in satellite at the corresponding commit from bare repo
repo.git.checkout({raise: true, timeout: true, b: true}, ref, "origin/#{ref}")
- # update the file in the satellite's working dir
file_path_in_satellite = File.join(repo.working_dir, file_path)
+ dir_name_in_satellite = File.dirname(file_path_in_satellite)
+
+ # Prevent relative links
+ unless safe_path?(file_path_in_satellite)
+ Gitlab::GitLogger.error("FileAction: Relative path not allowed")
+ return false
+ end
+
+ # Create dir if not exists
+ FileUtils.mkdir_p(dir_name_in_satellite)
+
+ # Write file
File.open(file_path_in_satellite, 'w') { |f| f.write(content) }
# add new file
@@ -28,7 +39,7 @@ module Gitlab
repo.git.commit(raise: true, timeout: true, a: true, m: commit_message)
- # push commit back to Gitolite
+ # push commit back to bare repo
# will raise CommandFailed when push fails
repo.git.push({raise: true, timeout: true}, :origin, ref)
diff --git a/lib/gitlab/satellite/merge_action.rb b/lib/gitlab/satellite/merge_action.rb
index d74d4194ff6..54afd6ab95c 100644
--- a/lib/gitlab/satellite/merge_action.rb
+++ b/lib/gitlab/satellite/merge_action.rb
@@ -28,7 +28,7 @@ module Gitlab
in_locked_and_timed_satellite do |merge_repo|
prepare_satellite!(merge_repo)
if merge_in_satellite!(merge_repo)
- # push merge back to Gitolite
+ # push merge back to bare repo
# will raise CommandFailed when push fails
merge_repo.git.push(default_options, :origin, merge_request.target_branch)
# remove source branch
diff --git a/lib/gitlab/satellite/satellite.rb b/lib/gitlab/satellite/satellite.rb
index 6cb7814fae5..353c3024aad 100644
--- a/lib/gitlab/satellite/satellite.rb
+++ b/lib/gitlab/satellite/satellite.rb
@@ -123,7 +123,7 @@ module Gitlab
remotes.each { |name| repo.git.remote(default_options,'rm', name)}
end
- # Updates the satellite from Gitolite
+ # Updates the satellite from bare repo
#
# Note: this will only update remote branches (i.e. origin/*)
def update_from_source!
diff --git a/lib/gitlab/upgrader.rb b/lib/gitlab/upgrader.rb
new file mode 100644
index 00000000000..1de681a97ff
--- /dev/null
+++ b/lib/gitlab/upgrader.rb
@@ -0,0 +1,96 @@
+require_relative "version_info"
+
+module Gitlab
+ class Upgrader
+ def execute
+ puts "GitLab #{current_version.major} upgrade tool"
+ puts "Your version is #{current_version}"
+ puts "Latest available version for GitLab #{current_version.major} is #{latest_version}"
+
+ if latest_version?
+ puts "You use latest GitLab version"
+ else
+ puts "Newer GitLab version is available"
+ answer = if ARGV.first == "-y"
+ "yes"
+ else
+ prompt("Do you want to upgrade (yes/no)? ", %w{yes no})
+ end
+
+ if answer == "yes"
+ upgrade
+ else
+ exit 0
+ end
+ end
+ end
+
+ def latest_version?
+ current_version >= latest_version
+ end
+
+ def current_version
+ @current_version ||= Gitlab::VersionInfo.parse(current_version_raw)
+ end
+
+ def latest_version
+ @latest_version ||= Gitlab::VersionInfo.parse(latest_version_raw)
+ end
+
+ def current_version_raw
+ File.read(File.join(gitlab_path, "VERSION")).strip
+ end
+
+ def latest_version_raw
+ git_tags = `git ls-remote --tags origin | grep tags\/v#{current_version.major}`
+ git_tags = git_tags.lines.to_a.select { |version| version =~ /v\d\.\d\.\d\Z/ }
+ last_tag = git_tags.last.match(/v\d\.\d\.\d/).to_s
+ end
+
+ def update_commands
+ {
+ "Stash changed files" => "git stash",
+ "Get latest code" => "git fetch",
+ "Switch to new version" => "git checkout -b v#{latest_version}",
+ "Install gems" => "bundle",
+ "Migrate DB" => "bundle exec rake db:migrate RAILS_ENV=production",
+ "Recompile assets" => "bundle exec rake assets:clean assets:precompile RAILS_ENV=production",
+ "Clear cache" => "bundle exec rake cache:clear RAILS_ENV=production"
+ }
+ end
+
+ def upgrade
+ update_commands.each do |title, cmd|
+ puts title
+ puts " -> #{cmd}"
+ if system(cmd)
+ puts " -> OK"
+ else
+ puts " -> FAILED"
+ puts "Failed to upgrade. Try to repeat task or proceed with upgrade manually "
+ exit 1
+ end
+ end
+
+ puts "Done"
+ end
+
+ def gitlab_path
+ File.expand_path(File.join(File.dirname(__FILE__), '../..'))
+ end
+
+ # Prompt the user to input something
+ #
+ # message - the message to display before input
+ # choices - array of strings of acceptable answers or nil for any answer
+ #
+ # Returns the user's answer
+ def prompt(message, choices = nil)
+ begin
+ print(message)
+ answer = STDIN.gets.chomp
+ end while !choices.include?(answer)
+ answer
+ end
+ end
+end
diff --git a/lib/gitlab/visibility_level.rb b/lib/gitlab/visibility_level.rb
new file mode 100644
index 00000000000..eada9bcddf5
--- /dev/null
+++ b/lib/gitlab/visibility_level.rb
@@ -0,0 +1,42 @@
+# Gitlab::VisibilityLevel module
+#
+# Define allowed public modes that can be used for
+# GitLab projects to determine project public mode
+#
+module Gitlab
+ module VisibilityLevel
+ PRIVATE = 0
+ INTERNAL = 10
+ PUBLIC = 20
+
+ class << self
+ def values
+ options.values
+ end
+
+ def options
+ {
+ 'Private' => PRIVATE,
+ 'Internal' => INTERNAL,
+ 'Public' => PUBLIC
+ }
+ end
+
+ def allowed_for?(user, level)
+ user.is_admin? || !Gitlab.config.gitlab.restricted_visibility_levels.include?(level)
+ end
+ end
+
+ def private?
+ visibility_level_field == PRIVATE
+ end
+
+ def internal?
+ visibility_level_field == INTERNAL
+ end
+
+ def public?
+ visibility_level_field == PUBLIC
+ end
+ end
+end
diff --git a/lib/support/deploy/deploy.sh b/lib/support/deploy/deploy.sh
index 0d2f8418bcf..b96f73058b6 100755
--- a/lib/support/deploy/deploy.sh
+++ b/lib/support/deploy/deploy.sh
@@ -28,17 +28,18 @@ sudo -u git -H git pull origin master
echo 'Deploy: Bundle and migrate'
# change it to your needs
-sudo -u git -H bundle --without postgres
+sudo -u git -H bundle --without aws development test postgres --deployment
sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production
+sudo -u git -H bundle exec rake assets:clean RAILS_ENV=production
+sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
+sudo -u git -H bundle exec rake cache:clear RAILS_ENV=production
# return stashed changes (if necessary)
# sudo -u git -H git stash pop
-
echo 'Deploy: Starting GitLab server...'
sudo service gitlab start
-sleep 10
sudo -u git -H rm /home/git/gitlab/public/index.html
-echo 'Deploy: Done'
+echo 'Deploy: Done' \ No newline at end of file
diff --git a/lib/support/init.d/gitlab b/lib/support/init.d/gitlab
index fbb7380ac47..f1b94087b6a 100755
--- a/lib/support/init.d/gitlab
+++ b/lib/support/init.d/gitlab
@@ -15,11 +15,20 @@
# Description: GitLab git repository management
### END INIT INFO
+
+###
+# DO NOT EDIT THIS FILE!
+# This file will be overwritten on update.
+# Instead add/change your variables in /etc/default/gitlab
+# An example defaults file can be found in lib/support/default/gitlab
+###
+
+
### Environment variables
RAILS_ENV="production"
-# Script variable names should be lower-case not to conflict with internal
-# /bin/sh variables such as PATH, EDITOR or SHELL.
+# Script variable names should be lower-case not to conflict with
+# internal /bin/sh variables such as PATH, EDITOR or SHELL.
app_user="git"
app_root="/home/$app_user/gitlab"
pid_path="$app_root/tmp/pids"
@@ -27,21 +36,20 @@ socket_path="$app_root/tmp/sockets"
web_server_pid_path="$pid_path/unicorn.pid"
sidekiq_pid_path="$pid_path/sidekiq.pid"
-
-
-### Here ends user configuration ###
-
+# Read configuration variable file if it is present
+test -f /etc/default/gitlab && . /etc/default/gitlab
# Switch to the app_user if it is not he/she who is running the script.
if [ "$USER" != "$app_user" ]; then
sudo -u "$app_user" -H -i $0 "$@"; exit;
fi
-# Switch to the gitlab path, if it fails exit with an error.
+# Switch to the gitlab path, exit on failure.
if ! cd "$app_root" ; then
echo "Failed to cd into $app_root, exiting!"; exit 1
fi
+
### Init Script functions
## Gets the pids from the files
diff --git a/lib/support/init.d/gitlab.default.example b/lib/support/init.d/gitlab.default.example
new file mode 100755
index 00000000000..4230783a9d7
--- /dev/null
+++ b/lib/support/init.d/gitlab.default.example
@@ -0,0 +1,14 @@
+# Copy this lib/support/init.d/gitlab.default.example file to
+# /etc/default/gitlab in order for it to apply to your system.
+
+# RAILS_ENV defines the type of installation that is running.
+# Normal values are "production", "test" and "development".
+RAILS_ENV="production"
+
+# app_user defines the user that GitLab is run as.
+# The default is "git".
+app_user="git"
+
+# app_root defines the folder in which gitlab and it's components are installed.
+# The default is "/home/$app_user/gitlab"
+app_root="/home/$app_user/gitlab"
diff --git a/lib/support/nginx/gitlab b/lib/support/nginx/gitlab
index 62b76984892..9f5155b3916 100644
--- a/lib/support/nginx/gitlab
+++ b/lib/support/nginx/gitlab
@@ -11,6 +11,9 @@ server {
server_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com;
server_tokens off; # don't show the version number, a security best practice
root /home/git/gitlab/public;
+
+ # Set value of client_max_body_size to at least the value of git.max_size in gitlab.yml
+ client_max_body_size 5m;
# individual nginx logs for this gitlab vhost
access_log /var/log/nginx/gitlab_access.log;
diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake
index 009806fcda7..20d5f03d6ef 100644
--- a/lib/tasks/gitlab/check.rake
+++ b/lib/tasks/gitlab/check.rake
@@ -3,6 +3,7 @@ namespace :gitlab do
task check: %w{gitlab:env:check
gitlab:gitlab_shell:check
gitlab:sidekiq:check
+ gitlab:ldap:check
gitlab:app:check}
@@ -611,10 +612,7 @@ namespace :gitlab do
end
def gitlab_shell_version
- gitlab_shell_version_file = "#{gitlab_shell_user_home}/gitlab-shell/VERSION"
- if File.readable?(gitlab_shell_version_file)
- File.read(gitlab_shell_version_file)
- end
+ Gitlab::Shell.new.version
end
def has_gitlab_shell3?
@@ -682,6 +680,44 @@ namespace :gitlab do
end
end
+ namespace :ldap do
+ task :check, [:limit] => :environment do |t, args|
+ args.with_defaults(limit: 100)
+ warn_user_is_not_gitlab
+ start_checking "LDAP"
+
+ if ldap_config.enabled
+ print_users(args.limit)
+ else
+ puts 'LDAP is disabled in config/gitlab.yml'
+ end
+
+ finished_checking "LDAP"
+ end
+
+ def print_users(limit)
+ puts "LDAP users with access to your GitLab server (limit: #{limit}):"
+ ldap.search(attributes: attributes, filter: filter, size: limit, return_result: false) do |entry|
+ puts "DN: #{entry.dn}\t#{ldap_config.uid}: #{entry[ldap_config.uid]}"
+ end
+ end
+
+ def attributes
+ [ldap_config.uid]
+ end
+
+ def filter
+ Net::LDAP::Filter.present?(ldap_config.uid)
+ end
+
+ def ldap
+ @ldap ||= OmniAuth::LDAP::Adaptor.new(ldap_config).connection
+ end
+
+ def ldap_config
+ @ldap_config ||= Gitlab.config.ldap
+ end
+ end
# Helper methods
##########################
@@ -736,7 +772,7 @@ namespace :gitlab do
end
def check_gitlab_shell
- required_version = Gitlab::VersionInfo.new(1, 7, 8)
+ required_version = Gitlab::VersionInfo.new(1, 7, 9)
current_version = Gitlab::VersionInfo.parse(gitlab_shell_version)
print "GitLab Shell version >= #{required_version} ? ... "
diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake
index ac2c4577c77..c46d5855faf 100644
--- a/lib/tasks/gitlab/task_helpers.rake
+++ b/lib/tasks/gitlab/task_helpers.rake
@@ -2,6 +2,16 @@ module Gitlab
class TaskAbortedByUserError < StandardError; end
end
+unless STDOUT.isatty
+ module Colored
+ extend self
+
+ def colorize(string, options={})
+ string
+ end
+ end
+end
+
namespace :gitlab do
# Ask if the user wants to continue