Load public key in initializer.
This commit is contained in:
parent
ad6d623234
commit
448817c4de
|
@ -16,6 +16,7 @@ class ApplicationController < ActionController::Base
|
|||
protect_from_forgery with: :exception
|
||||
|
||||
helper_method :abilities, :can?, :current_application_settings
|
||||
helper_method :github_import_enabled?, :gitlab_import_enabled?, :bitbucket_import_enabled?
|
||||
|
||||
rescue_from Encoding::CompatibilityError do |exception|
|
||||
log_exception(exception)
|
||||
|
@ -313,4 +314,16 @@ class ApplicationController < ActionController::Base
|
|||
set_filter_values(merge_requests)
|
||||
merge_requests
|
||||
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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Import::BitbucketController < Import::BaseController
|
||||
before_filter :verify_bitbucket_import_enabled
|
||||
before_filter :bitbucket_auth, except: :callback
|
||||
|
||||
# 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)
|
||||
end
|
||||
|
||||
def verify_bitbucket_import_enabled
|
||||
not_found! unless bitbucket_import_enabled?
|
||||
end
|
||||
|
||||
def bitbucket_auth
|
||||
if current_user.bitbucket_access_token.blank?
|
||||
go_to_bitbucket_for_permissions
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Import::GithubController < Import::BaseController
|
||||
before_filter :verify_github_import_enabled
|
||||
before_filter :github_auth, except: :callback
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
def verify_github_import_enabled
|
||||
not_found! unless github_import_enabled?
|
||||
end
|
||||
|
||||
def github_auth
|
||||
if current_user.github_access_token.blank?
|
||||
go_to_github_for_permissions
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Import::GitlabController < Import::BaseController
|
||||
before_filter :verify_gitlab_import_enabled
|
||||
before_filter :gitlab_auth, except: :callback
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
def verify_gitlab_import_enabled
|
||||
not_found! unless gitlab_import_enabled?
|
||||
end
|
||||
|
||||
def gitlab_auth
|
||||
if current_user.gitlab_access_token.blank?
|
||||
go_to_gitlab_for_permissions
|
||||
|
|
|
@ -20,4 +20,6 @@ module OauthHelper
|
|||
def additional_providers
|
||||
enabled_oauth_providers.reject{|provider| provider.to_s.starts_with?('ldap')}
|
||||
end
|
||||
|
||||
extend self
|
||||
end
|
||||
|
|
|
@ -265,16 +265,4 @@ module ProjectsHelper
|
|||
"success"
|
||||
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
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
path = File.expand_path("~/.ssh/id_rsa.pub")
|
||||
Gitlab::BitbucketImport.public_key = File.read(path) if File.exist?(path)
|
|
@ -0,0 +1,6 @@
|
|||
module Gitlab
|
||||
module BitbucketImport
|
||||
mattr_accessor :public_key
|
||||
@public_key = nil
|
||||
end
|
||||
end
|
|
@ -9,13 +9,16 @@ module Gitlab
|
|||
end
|
||||
|
||||
def execute
|
||||
return false unless BitbucketImport.public_key.present?
|
||||
|
||||
project_identifier = "#{repo["owner"]}/#{repo["slug"]}"
|
||||
return true if client.deploy_key(project_identifier)
|
||||
|
||||
# TODO: Point to actual public key.
|
||||
client.add_deploy_key(project_identifier, File.read("/Users/douwemaan/.ssh/id_rsa.pub"))
|
||||
|
||||
client.add_deploy_key(project_identifier, BitbucketImport.public_key)
|
||||
|
||||
true
|
||||
rescue
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue