Load public key in initializer.
This commit is contained in:
parent
ad6d623234
commit
448817c4de
9 changed files with 44 additions and 15 deletions
|
@ -16,6 +16,7 @@ class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
helper_method :abilities, :can?, :current_application_settings
|
helper_method :abilities, :can?, :current_application_settings
|
||||||
|
helper_method :github_import_enabled?, :gitlab_import_enabled?, :bitbucket_import_enabled?
|
||||||
|
|
||||||
rescue_from Encoding::CompatibilityError do |exception|
|
rescue_from Encoding::CompatibilityError do |exception|
|
||||||
log_exception(exception)
|
log_exception(exception)
|
||||||
|
@ -313,4 +314,16 @@ class ApplicationController < ActionController::Base
|
||||||
set_filter_values(merge_requests)
|
set_filter_values(merge_requests)
|
||||||
merge_requests
|
merge_requests
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def github_import_enabled?
|
||||||
|
OauthHelper.enabled_oauth_providers.include?(:github)
|
||||||
|
end
|
||||||
|
|
||||||
|
def gitlab_import_enabled?
|
||||||
|
OauthHelper.enabled_oauth_providers.include?(:gitlab)
|
||||||
|
end
|
||||||
|
|
||||||
|
def bitbucket_import_enabled?
|
||||||
|
OauthHelper.enabled_oauth_providers.include?(:bitbucket) && Gitlab::BitbucketImport.public_key.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class Import::BitbucketController < Import::BaseController
|
class Import::BitbucketController < Import::BaseController
|
||||||
|
before_filter :verify_bitbucket_import_enabled
|
||||||
before_filter :bitbucket_auth, except: :callback
|
before_filter :bitbucket_auth, except: :callback
|
||||||
|
|
||||||
# rescue_from OAuth::Error, with: :bitbucket_unauthorized
|
# rescue_from OAuth::Error, with: :bitbucket_unauthorized
|
||||||
|
@ -55,6 +56,10 @@ class Import::BitbucketController < Import::BaseController
|
||||||
@client ||= Gitlab::BitbucketImport::Client.new(current_user.bitbucket_access_token, current_user.bitbucket_access_token_secret)
|
@client ||= Gitlab::BitbucketImport::Client.new(current_user.bitbucket_access_token, current_user.bitbucket_access_token_secret)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def verify_bitbucket_import_enabled
|
||||||
|
not_found! unless bitbucket_import_enabled?
|
||||||
|
end
|
||||||
|
|
||||||
def bitbucket_auth
|
def bitbucket_auth
|
||||||
if current_user.bitbucket_access_token.blank?
|
if current_user.bitbucket_access_token.blank?
|
||||||
go_to_bitbucket_for_permissions
|
go_to_bitbucket_for_permissions
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class Import::GithubController < Import::BaseController
|
class Import::GithubController < Import::BaseController
|
||||||
|
before_filter :verify_github_import_enabled
|
||||||
before_filter :github_auth, except: :callback
|
before_filter :github_auth, except: :callback
|
||||||
|
|
||||||
rescue_from Octokit::Unauthorized, with: :github_unauthorized
|
rescue_from Octokit::Unauthorized, with: :github_unauthorized
|
||||||
|
@ -44,6 +45,10 @@ class Import::GithubController < Import::BaseController
|
||||||
@client ||= Gitlab::GithubImport::Client.new(current_user.github_access_token)
|
@client ||= Gitlab::GithubImport::Client.new(current_user.github_access_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def verify_github_import_enabled
|
||||||
|
not_found! unless github_import_enabled?
|
||||||
|
end
|
||||||
|
|
||||||
def github_auth
|
def github_auth
|
||||||
if current_user.github_access_token.blank?
|
if current_user.github_access_token.blank?
|
||||||
go_to_github_for_permissions
|
go_to_github_for_permissions
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class Import::GitlabController < Import::BaseController
|
class Import::GitlabController < Import::BaseController
|
||||||
|
before_filter :verify_gitlab_import_enabled
|
||||||
before_filter :gitlab_auth, except: :callback
|
before_filter :gitlab_auth, except: :callback
|
||||||
|
|
||||||
rescue_from OAuth2::Error, with: :gitlab_unauthorized
|
rescue_from OAuth2::Error, with: :gitlab_unauthorized
|
||||||
|
@ -41,6 +42,10 @@ class Import::GitlabController < Import::BaseController
|
||||||
@client ||= Gitlab::GitlabImport::Client.new(current_user.gitlab_access_token)
|
@client ||= Gitlab::GitlabImport::Client.new(current_user.gitlab_access_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def verify_gitlab_import_enabled
|
||||||
|
not_found! unless gitlab_import_enabled?
|
||||||
|
end
|
||||||
|
|
||||||
def gitlab_auth
|
def gitlab_auth
|
||||||
if current_user.gitlab_access_token.blank?
|
if current_user.gitlab_access_token.blank?
|
||||||
go_to_gitlab_for_permissions
|
go_to_gitlab_for_permissions
|
||||||
|
|
|
@ -20,4 +20,6 @@ module OauthHelper
|
||||||
def additional_providers
|
def additional_providers
|
||||||
enabled_oauth_providers.reject{|provider| provider.to_s.starts_with?('ldap')}
|
enabled_oauth_providers.reject{|provider| provider.to_s.starts_with?('ldap')}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
extend self
|
||||||
end
|
end
|
||||||
|
|
|
@ -265,16 +265,4 @@ module ProjectsHelper
|
||||||
"success"
|
"success"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_import_enabled?
|
|
||||||
enabled_oauth_providers.include?(:github)
|
|
||||||
end
|
|
||||||
|
|
||||||
def gitlab_import_enabled?
|
|
||||||
enabled_oauth_providers.include?(:gitlab)
|
|
||||||
end
|
|
||||||
|
|
||||||
def bitbucket_import_enabled?
|
|
||||||
enabled_oauth_providers.include?(:bitbucket)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
2
config/initializers/public_key.rb
Normal file
2
config/initializers/public_key.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
path = File.expand_path("~/.ssh/id_rsa.pub")
|
||||||
|
Gitlab::BitbucketImport.public_key = File.read(path) if File.exist?(path)
|
6
lib/gitlab/bitbucket_import.rb
Normal file
6
lib/gitlab/bitbucket_import.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module Gitlab
|
||||||
|
module BitbucketImport
|
||||||
|
mattr_accessor :public_key
|
||||||
|
@public_key = nil
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,13 +9,16 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
|
return false unless BitbucketImport.public_key.present?
|
||||||
|
|
||||||
project_identifier = "#{repo["owner"]}/#{repo["slug"]}"
|
project_identifier = "#{repo["owner"]}/#{repo["slug"]}"
|
||||||
return true if client.deploy_key(project_identifier)
|
return true if client.deploy_key(project_identifier)
|
||||||
|
|
||||||
# TODO: Point to actual public key.
|
client.add_deploy_key(project_identifier, BitbucketImport.public_key)
|
||||||
client.add_deploy_key(project_identifier, File.read("/Users/douwemaan/.ssh/id_rsa.pub"))
|
|
||||||
|
|
||||||
true
|
true
|
||||||
|
rescue
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue