8000 Add ability to login an extension user with a certificate by sbacheld · Pull Request #24 · rlane/rbvmomi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add ability to login an extension user with a certificate #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions lib/rbvmomi/vim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,50 @@ def self.connect opts
end
end

# Connect to a vSphere SDK endpoint using extension and a certificate
#
# @param [Hash] opts The options hash.
# @option opts [String] :host (sdkTunnel) Host to connect to.
# @option opts [Numeric] :port (8089) Port to connect to.
# @option opts [String] :proxyHost Host to connect to.
# @option opts [Numeric] :proxyPort (80) Port to connect to.
# @option opts [Boolean] :ssl (true) Whether to use SSL.
# @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors.
# @option opts [String] :extension_key Extension key.
# @option opts [String] :path (/sdkTunnel) SDK endpoint path.
# @option opts [String] :cert Path to the certificate
# @option opts [String] :key Path to the private key
# @option opts [String] :path (/sdkTunnel) SDK endpoint path.
# @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
def self.connect_extension_by_certificate opts
fail unless opts.is_a? Hash
fail "proxy host option required" unless opts[:proxyHost]
fail "extension key required" unless opts[:extension_key]
fail "certificate required" unless opts[:cert]
fail "private key required" unless opts[:key]

opts[:host] ||= 'sdkTunnel'
opts[:port] ||= 8089
opts[:proxyPort] ||= 80
opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
opts[:insecure] ||= false
opts[:path] ||= '/sdkTunnel'
opts[:cert] = File.read(opts[:cert])
opts[:key] = File.read(opts[:key])
opts[:ns] ||= 'urn:vim25'
rev_given = opts[:rev] != nil
opts[:rev] = '4.0' unless rev_given
opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug

new(opts).tap do |vim|
vim.serviceContent.sessionManager.LoginExtensionByCertificate :extensionKey => opts[:extension_key]
unless rev_given
rev = vim.serviceContent.about.apiVersion
vim.rev = [rev, '5.0'].min
end
end
end

def close
VIM::SessionManager(self, 'SessionManager').Logout rescue RbVmomi::Fault
self.cookie = nil
Expand Down
0