diff options
author | Alejandro RodrÃguez <alejorro70@gmail.com> | 2016-06-24 15:06:46 -0400 |
---|---|---|
committer | Alejandro RodrÃguez <alejorro70@gmail.com> | 2016-06-29 22:30:33 -0400 |
commit | 20b9bb2029972c5f5334d6d684e0d60edb034c5f (patch) | |
tree | a6a9cbc01ec7d9f68cb639aeb80e26d8b6cd865a /lib | |
parent | 86359ec854314574dccea75247f45590262b05c0 (diff) | |
download | gitlab-ce-shards.tar.gz |
Create (if necessary) and link the gitlab-shell secret file on the rake install taskshards
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/backend/shell.rb | 17 | ||||
-rw-r--r-- | lib/tasks/gitlab/shell.rake | 2 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb index e31840ef919..34e0143a82e 100644 --- a/lib/gitlab/backend/shell.rb +++ b/lib/gitlab/backend/shell.rb @@ -1,3 +1,5 @@ +require 'securerandom' + module Gitlab class Shell class Error < StandardError; end @@ -188,6 +190,21 @@ module Gitlab File.exist?(full_path(storage, dir_name)) end + # Create (if necessary) and link the secret token file + def generate_and_link_secret_token + secret_file = Gitlab.config.gitlab_shell.secret_file + unless File.exist? secret_file + # Generate a new token of 16 random hexadecimal characters and store it in secret_file. + token = SecureRandom.hex(16) + File.write(secret_file, token) + end + + link_path = File.join(gitlab_shell_path, '.gitlab_shell_secret') + if File.exist?(gitlab_shell_path) && !File.exist?(link_path) + FileUtils.symlink(secret_file, link_path) + end + end + protected def gitlab_shell_path diff --git a/lib/tasks/gitlab/shell.rake b/lib/tasks/gitlab/shell.rake index 263798e9c22..c85ebdf8619 100644 --- a/lib/tasks/gitlab/shell.rake +++ b/lib/tasks/gitlab/shell.rake @@ -71,6 +71,8 @@ namespace :gitlab do File.open(File.join(home_dir, ".ssh", "environment"), "w+") do |f| f.puts "PATH=#{ENV['PATH']}" end + + Gitlab::Shell.new.generate_and_link_secret_token end desc "GitLab | Setup gitlab-shell" |