diff options
author | Justin DiPierro <dipierroj@gmail.com> | 2016-09-29 12:46:54 -0400 |
---|---|---|
committer | Justin DiPierro <dipierroj@gmail.com> | 2016-10-06 11:22:37 -0400 |
commit | fe46e4eb35dd6728a8a5ebcee9cc05a4613effbf (patch) | |
tree | 241a0fad11b7719f193f3deb6b8818c37159ec8c /lib/gitlab/backend/shell.rb | |
parent | 9a13f885a9dc7b072d41160a6d3db965c9114b4b (diff) | |
download | gitlab-ce-fe46e4eb35dd6728a8a5ebcee9cc05a4613effbf.tar.gz |
Load Github::Shell's secret token from file on initialization instead of every request.
Diffstat (limited to 'lib/gitlab/backend/shell.rb')
-rw-r--r-- | lib/gitlab/backend/shell.rb | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb index 79eac66b364..d0060fbaca1 100644 --- a/lib/gitlab/backend/shell.rb +++ b/lib/gitlab/backend/shell.rb @@ -17,6 +17,18 @@ module Gitlab end class << self + def secret_token + @secret_token ||= begin + File.read(Gitlab.config.gitlab_shell.secret_file).chomp + end + end + + def ensure_secret_token! + return if File.exist?(File.join(Gitlab.config.gitlab_shell.path, '.gitlab_shell_secret')) + + generate_and_link_secret_token + end + def version_required @version_required ||= File.read(Rails.root. join('GITLAB_SHELL_VERSION')).strip @@ -25,6 +37,25 @@ module Gitlab def strip_key(key) key.split(/ /)[0, 2].join(' ') end + + private + + # Create (if necessary) and link the secret token file + def generate_and_link_secret_token + secret_file = Gitlab.config.gitlab_shell.secret_file + shell_path = Gitlab.config.gitlab_shell.path + + unless File.size?(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(shell_path, '.gitlab_shell_secret') + if File.exist?(shell_path) && !File.exist?(link_path) + FileUtils.symlink(secret_file, link_path) + end + end end # Init new repository @@ -201,21 +232,6 @@ 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.size?(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 |