Introduce Key namespace so we could put more keys

This commit is contained in:
Lin Jen-Shin 2018-03-09 15:54:20 +08:00
parent 8230b774b5
commit 9a538b9eeb
6 changed files with 30 additions and 25 deletions

View File

@ -11,9 +11,12 @@ module QA
autoload :Scenario, 'qa/runtime/scenario'
autoload :Browser, 'qa/runtime/browser'
autoload :Env, 'qa/runtime/env'
autoload :RSAKey, 'qa/runtime/rsa_key'
autoload :Address, 'qa/runtime/address'
autoload :API, 'qa/runtime/api'
module Key
autoload :RSA, 'qa/runtime/key/rsa'
end
end
##

23
qa/qa/runtime/key/rsa.rb Normal file
View File

@ -0,0 +1,23 @@
require 'net/ssh'
require 'forwardable'
module QA
module Runtime
module Key
class RSA
extend Forwardable
attr_reader :key
def_delegators :@key, :fingerprint, :to_pem
def initialize(bits = 4096)
@key = OpenSSL::PKey::RSA.new(bits)
end
def public_key
@public_key ||= "#{key.ssh_type} #{[key.to_blob].pack('m0')}"
end
end
end
end
end

View File

@ -1,21 +0,0 @@
require 'net/ssh'
require 'forwardable'
module QA
module Runtime
class RSAKey
extend Forwardable
attr_reader :key
def_delegators :@key, :fingerprint, :to_pem
def initialize(bits = 4096)
@key = OpenSSL::PKey::RSA.new(bits)
end
def public_key
@public_key ||= "#{key.ssh_type} #{[key.to_blob].pack('m0')}"
end
end
end
end

View File

@ -4,7 +4,7 @@ module QA
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials }
key = Runtime::RSAKey.new
key = Runtime::Key::RSA.new
deploy_key_title = 'deploy key title'
deploy_key_value = key.public_key

View File

@ -3,7 +3,7 @@ require 'digest/sha1'
module QA
feature 'cloning code using a deploy key', :core, :docker do
let(:runner_name) { "qa-runner-#{Time.now.to_i}" }
let(:key) { Runtime::RSAKey.new }
let(:key) { Runtime::Key::RSA.new }
given(:project) do
Factory::Resource::Project.fabricate! do |resource|

View File

@ -1,4 +1,4 @@
describe QA::Runtime::RSAKey do
describe QA::Runtime::Key::RSA do
describe '#public_key' do
subject { described_class.new.public_key }