Sha256: 821edb153663c9642aeca6599ed07b1b64293519e257c55c394653d7e10ea811

Contents?: true

Size: 1.38 KB

Versions: 7

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: false

require 'uri'

# The main URI Module
module URI
  # Creates the vSphereURL, extended by the Generic Class
  class VsphereUrl < Generic
    # Default port for connecting to the vSphere cluster Webserver
    DEFAULT_PORT = 443
    # Default path for connecting to the vSphere cluster URL
    DEFAULT_PATH = '/sdk'.freeze

    # Creates the URL from options that are decided
    #
    def self.from_config(options)
      parts = []
      parts << 'vsphere://'
      parts << options[:host]
      parts << ':'
      parts << (options[:port] || DEFAULT_PORT)
      parts << (options[:path] || DEFAULT_PATH)
      parts << '?use_ssl='
      parts << (options[:use_ssl] == false ? false : true)
      parts << '&insecure='
      parts << (options[:insecure] || false)
      URI parts.join
    end

    # Converts URL to SSL if needed
    #
    def use_ssl
      if query
        ssl_query = query.split('&').each.select do |q|
          q.start_with?('use_ssl=')
        end.first
        ssl_query == 'use_ssl=true'
      else
        true
      end
    end

    # Converts URL to insecure if needed
    #
    def insecure
      if query
        insecure_query = query.split('&').each.select do |q|
          q.start_with?('insecure=')
        end.first
        insecure_query == 'insecure=true'
      else
        false
      end
    end
  end
  @@schemes['VSPHERE'] = VsphereUrl
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
chef-provisioning-vsphere-2.2.2 lib/chef/provisioning/vsphere_driver/vsphere_url.rb
chef-provisioning-vsphere-2.2.1 lib/chef/provisioning/vsphere_driver/vsphere_url.rb
chef-provisioning-vsphere-2.2.0 lib/chef/provisioning/vsphere_driver/vsphere_url.rb
chef-provisioning-vsphere-2.1.0 lib/chef/provisioning/vsphere_driver/vsphere_url.rb
chef-provisioning-vsphere-2.0.10 lib/chef/provisioning/vsphere_driver/vsphere_url.rb
chef-provisioning-vsphere-2.0.9 lib/chef/provisioning/vsphere_driver/vsphere_url.rb
chef-provisioning-vsphere-2.0.8 lib/chef/provisioning/vsphere_driver/vsphere_url.rb