module Serverspec::Type

Public Instance Methods

chocolatey_package(name) click to toggle source
# File lib/octopus_serverspec_extensions/type/chocolatey_package.rb, line 29
def chocolatey_package(name)
  ChocolateyPackage.new(name)
end
java_property_file(name) click to toggle source
# File lib/octopus_serverspec_extensions/type/java_property_file.rb, line 24
def java_property_file(name)
  JavaPropertyFile.new(name)
end
npm_package(name) click to toggle source
# File lib/octopus_serverspec_extensions/type/npm_package.rb, line 32
def npm_package(name)
  NpmPackage.new(name)
end
octopus_account(*url_and_api_key, account_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb, line 144
def octopus_account(*url_and_api_key, account_name)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)

  OctopusDeployAccount.new(serverUrl, apiKey, account_name)
end
octopus_deploy_account(*url_and_api_key, account_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb, line 138
def octopus_deploy_account(*url_and_api_key, account_name)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)

  OctopusDeployAccount.new(serverUrl, apiKey, account_name)
end
octopus_deploy_environment(*url_and_api_key, environment_name) click to toggle source

module-level constructors/entrypoints

# File lib/octopus_serverspec_extensions/type/octopus_deploy_environment.rb, line 81
def octopus_deploy_environment(*url_and_api_key, environment_name)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)

  OctopusDeployEnvironment.new(serverUrl, apiKey, environment_name)
end
octopus_deploy_project_group(*url_and_api_key, project_group_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_project_group.rb, line 76
def octopus_deploy_project_group(*url_and_api_key, project_group_name)
  url, apikey = get_octopus_creds(url_and_api_key)
  octopus_deploy_projectgroup(url, apikey, project_group_name)
end
octopus_deploy_projectgroup(*url_and_api_key, project_group_name) click to toggle source

module-level constructors/entrypoints

# File lib/octopus_serverspec_extensions/type/octopus_deploy_project_group.rb, line 71
def octopus_deploy_projectgroup(*url_and_api_key, project_group_name) # deprecated - no underscore in name
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)
  OctopusDeployProjectGroup.new(serverUrl, apiKey, project_group_name)
end
octopus_deploy_smtp_config(*url_and_api_key) click to toggle source

module-level constructors/entrypoints

# File lib/octopus_serverspec_extensions/type/octopus_deploy_smtp_config.rb, line 80
def octopus_deploy_smtp_config(*url_and_api_key)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)
  OctopusDeploySmtpConfig.new(serverUrl, apiKey)
end
octopus_deploy_space(*url_and_api_key, space_name) click to toggle source

module-level constructors/entrypoints

# File lib/octopus_serverspec_extensions/type/octopus_deploy_space.rb, line 59
def octopus_deploy_space(*url_and_api_key, space_name)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)
  OctopusDeploySpace.new(serverUrl, apiKey, space_name)
end
octopus_deploy_team(*url_and_api_key, team_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_team.rb, line 51
def octopus_deploy_team(*url_and_api_key, team_name)
  serverUrl,apiKey = get_octopus_creds(url_and_api_key)
  OctopusDeployTeam.new(serverUrl, apiKey, team_name)
end
octopus_deploy_tentacle(serverUrl, apiKey, instance) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb, line 149
def octopus_deploy_tentacle(serverUrl, apiKey, instance)
  OctopusDeployTentacle.new(serverUrl, apiKey, instance)
end
octopus_deploy_upgrade_config(*url_and_api_key) click to toggle source

module-level constructors/entrypoints

# File lib/octopus_serverspec_extensions/type/octopus_deploy_upgrade_config.rb, line 65
def octopus_deploy_upgrade_config(*url_and_api_key)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)
  OctopusDeployUpgradeConfig.new(serverUrl, apiKey)
end
octopus_deploy_user(*url_and_api_key, user_name) click to toggle source

module-level constructors/entrypoints

# File lib/octopus_serverspec_extensions/type/octopus_deploy_user.rb, line 81
def octopus_deploy_user(*url_and_api_key, user_name)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)
  OctopusDeployUser.new(serverUrl, apiKey, user_name)
end
octopus_deploy_worker(serverUrl, apiKey, instance) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 114
def octopus_deploy_worker(serverUrl, apiKey, instance)
  OctopusDeployWorker.new(serverUrl, apiKey, instance)
end
octopus_deploy_worker_pool(*url_and_api_key, worker_pool_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker_pool.rb, line 52
def octopus_deploy_worker_pool(*url_and_api_key, worker_pool_name)
  serverUrl, apiKey = get_octopus_url(url_and_api_key)

  OctopusDeployWorkerPool.new(serverUrl, apiKey, worker_pool_name)
end
octopus_environment(*url_and_api_key, environment_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_environment.rb, line 87
def octopus_environment(*url_and_api_key, environment_name)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)

  OctopusDeployEnvironment.new(serverUrl, apiKey, environment_name)
end
octopus_project_group(*url_and_api_key, project_group_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_project_group.rb, line 81
def octopus_project_group(*url_and_api_key, project_group_name)
  url, apikey = get_octopus_creds(url_and_api_key)
  octopus_deploy_projectgroup(url, apikey, project_group_name)
end
octopus_projectgroup(*url_and_api_key, project_group_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_project_group.rb, line 86
def octopus_projectgroup(*url_and_api_key, project_group_name) # deprecated - no underscore in name
  url, apikey = get_octopus_creds(url_and_api_key)
  octopus_deploy_projectgroup(url, apikey, project_group_name)
end
octopus_smtp_config(*url_and_api_key) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_smtp_config.rb, line 85
def octopus_smtp_config(*url_and_api_key)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)
  octopus_deploy_smtp_config(serverUrl, apiKey)
end
octopus_space(*url_and_api_key, space_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_space.rb, line 64
def octopus_space(*url_and_api_key, space_name)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)
  OctopusDeploySpace.new(serverUrl, apiKey, space_name)
end
octopus_team(*url_and_api_key, team_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_team.rb, line 56
def octopus_team(*url_and_api_key, team_name)
  serverUrl,apiKey = get_octopus_creds(url_and_api_key)
  OctopusDeployTeam.new(serverUrl, apiKey, team_name)
end
octopus_upgrade_config(*url_and_api_key) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_upgrade_config.rb, line 70
def octopus_upgrade_config(*url_and_api_key)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)
  octopus_deploy_upgrade_config(serverUrl, apiKey)
end
octopus_user(*url_and_api_key, user_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_user.rb, line 86
def octopus_user(*url_and_api_key, user_name)
  serverUrl, apiKey = get_octopus_creds(url_and_api_key)
  octopus_deploy_user(serverUrl, apiKey, user_name)
end
octopus_worker_pool(*url_and_api_key, worker_pool_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker_pool.rb, line 58
def octopus_worker_pool(*url_and_api_key, worker_pool_name)
  serverUrl, apiKey = get_octopus_url(url_and_api_key)

  OctopusDeployWorkerPool.new(serverUrl, apiKey, worker_pool_name)
end
windows_dsc() click to toggle source
# File lib/octopus_serverspec_extensions/type/windows_dsc.rb, line 32
def windows_dsc
  WindowsDSC.new
end
windows_firewall() click to toggle source
# File lib/octopus_serverspec_extensions/type/windows_firewall.rb, line 27
def windows_firewall
  WindowsFirewall.new
end
windows_scheduled_task(name) click to toggle source
# File lib/octopus_serverspec_extensions/type/windows_scheduled_task.rb, line 28
def windows_scheduled_task(name)
  WindowsScheduledTask.new(name)
end

Private Instance Methods

check_supports_spaces(serverUrl) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb, line 155
def check_supports_spaces(serverUrl)
  begin
    resp = Net::HTTP.get_response(URI.parse("#{serverUrl}/api/"))
    body = JSON.parse(resp.body)
    version = body['Version']
    return Gem::Version.new(version) > Gem::Version.new('2019.0.0')
  rescue => e
    puts "Unable to connect to #{serverUrl}: #{e}"
  end

  return false
end
get_account_via_api(serverUrl, apiKey, account_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb, line 152
def get_account_via_api(serverUrl, apiKey, account_name)
  account = nil

  unless @spaceId.nil?
    # set the spaceId correctly
    @spaceFragment = "#{@spaceId}/"
  end

  url = "#{serverUrl}/api/#{@spaceFragment}accounts/all?api-key=#{apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    account = body.select {|i| i['Name'] == account_name }.first unless body.nil?
  rescue => e
    raise "get_account_via_api: Unable to connect to #{url}: #{e}"
  end

  account
end
get_environment_via_api(serverUrl, apiKey, environment_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_environment.rb, line 95
def get_environment_via_api(serverUrl, apiKey, environment_name)
  environment = nil

  unless @spaceId.nil?
    # set the spaceId correctly
    @spaceFragment = "#{@spaceId}/"
  end

  url = "#{serverUrl}/api/#{@spaceFragment}environments?name=#{environment_name}&api-key=#{apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    environment = body['Items'].first unless body.nil?
  rescue => e
    raise "Unable to connect to #{url}: #{e}"
  end

  environment
end
get_machine_via_api(serverUrl, apiKey, thumbprint) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb, line 192
def get_machine_via_api(serverUrl, apiKey, thumbprint)
  machine = nil
  url = "#{serverUrl}/api/#{@spaceFragment}machines/all?api-key=#{apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    machine = body.select {|e| e["Thumbprint"] == thumbprint}.first unless body.nil?
  rescue => e
    puts "Unable to connect to #{url}: #{e}"
  end

  machine
end
get_project_group_via_api(serverUrl, apiKey, project_group_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_project_group.rb, line 93
def get_project_group_via_api(serverUrl, apiKey, project_group_name)
  pg = nil

 raise "'project_group_name' not supplied" if(project_group_name.nil? || project_group_name == '')

  unless @spaceId.nil?
    @spaceFragment = "#{@spaceId}/"
  end

  url = "#{serverUrl}/api/#{@spaceFragment}projectgroups/all?api-key=#{apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    pg = body.select {|i| i['Name'] == project_group_name }.first unless body.nil?
  rescue => e
    raise "get_project_group_via_api: Unable to connect to #{url}: #{e}"
  end

  pg
end
get_smtp_config_via_api(serverUrl, apiKey) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_smtp_config.rb, line 92
def get_smtp_config_via_api(serverUrl, apiKey)
  smtp = nil

  url = "#{serverUrl}/api/smtpconfiguration?api-key=#{apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    smtp = body unless body.nil?
  rescue => e
    raise "get_smtp_config_via_api: Unable to connect to #{url}: #{e}"
  end

  smtp
end
get_space_id?(space_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_project_group.rb, line 115
def get_space_id?(space_name)
  url = "#{@serverUrl}/api/Spaces/all?api-key=#{@apiKey}"
  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    spaces = JSON.parse(resp.body)
    space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
  rescue
    raise "get_space_id: unable to connect to #{url}: #{e}"
  end
  space_id
end
get_space_via_api() click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_space.rb, line 71
def get_space_via_api
  space = nil

  @serverSupportsSpaces = check_supports_spaces(@serverUrl)

  unless @serverSupportsSpaces
    raise "Server does not support Spaces"
  end

  url = "#{@serverUrl}/api/Spaces/all?api-key=#{@apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    space = body.select {|i| i['Name'] == @spaceName }.first unless body.nil?
  rescue => e
    raise "get_account_via_api: Unable to connect to #{url}: #{e}"
  end

  space
  end
get_team_via_api(serverUrl, apiKey, team_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_team.rb, line 63
def get_team_via_api(serverUrl, apiKey, team_name)
  team = nil

  url = "#{serverUrl}/api#{@spaceFragment}/teams/all?api-key=#{apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    teams = body unless body.nil?
    team = teams.select {|i| i['Name'] == team_name }.first unless teams.nil?
  rescue => e
    raise "get_team_via_api: Unable to connect to #{url}: #{e}"
  end

  team
end
get_upgrade_config_endpoint(serverUrl) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_upgrade_config.rb, line 77
def get_upgrade_config_endpoint(serverUrl)
  endpoint = nil

  url = "#{serverUrl}/api/"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    json = body unless body.nil?
    endpoint = json['Links']['UpgradeConfiguration']
  rescue => e
    raise "get_upgrade_config_endpoint: Unable to connect to #{url}: #{e}"
  end

  endpoint
end
get_upgrade_config_via_api(serverUrl, apiKey) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_upgrade_config.rb, line 94
def get_upgrade_config_via_api(serverUrl, apiKey)
  smtp = nil

  stem = get_upgrade_config_endpoint(serverUrl)
  url = "#{serverUrl}#{stem}?api-key=#{apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    smtp = body unless body.nil?
  rescue => e
    raise "get_upgrade_config_via_api: Unable to connect to #{url}: #{e}"
  end

  smtp
end
get_user_via_api(serverUrl, apiKey, user_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_user.rb, line 93
def get_user_via_api(serverUrl, apiKey, user_name)
  user = nil

  url = "#{serverUrl}/api/users/all?api-key=#{apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    users = body unless body.nil?
    user = users.select {|i| i['Username'] == user_name }.first unless users.nil?
  rescue => e
    raise "get_user_via_api: Unable to connect to #{url}: #{e}"
  end

  user
end
get_worker_pool_via_api(serverUrl, apiKey, worker_pool_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker_pool.rb, line 66
def get_worker_pool_via_api(serverUrl, apiKey, worker_pool_name)
  worker_pool = nil

  if @serverSupportsSpaces
    # set the spaceId correctly
    @spaceFragment = "#{@spaceId}/"
  end

  url = "#{serverUrl}/api/#{@spaceFragment}workerpools/all?api-key=#{apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    worker_pool = body.select {|i| i['Name'] == worker_pool_name } unless body.nil?
  rescue => e
    raise "Unable to connect to #{url}: #{e}"
  end

  worker_pool
end
get_worker_via_api(serverUrl, apiKey, thumbprint) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 157
def get_worker_via_api(serverUrl, apiKey, thumbprint)
  worker = nil
  url = "#{serverUrl}/api/#{@spaceFragment}workers/all?api-key=#{apiKey}"

  begin
    resp = Net::HTTP.get_response(URI.parse(url))
    body = JSON.parse(resp.body)
    worker = body.select {|e| e["Thumbprint"] == thumbprint}.first unless body.nil?
  rescue => e
    puts "Unable to connect to #{url}: #{e}"
  end

  worker
end
machine_healthcheck_outstanding(machine) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb, line 188
def machine_healthcheck_outstanding(machine)
  machine["StatusSummary"] == "This machine was recently added. Please perform a health check."
end
poll_until_machine_has_completed_healthcheck(serverUrl, apiKey, thumbprint) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb, line 168
def poll_until_machine_has_completed_healthcheck(serverUrl, apiKey, thumbprint)
  machine = nil
  url = "#{serverUrl}/api/#{@spaceFragment}machines/all?api-key=#{apiKey}"

  now = Time.now
  counter = 1
  loop do
    machine = get_machine_via_api(serverUrl, apiKey, thumbprint)

    break if machine.nil?
    break if counter > 10
    break if !machine_healthcheck_outstanding(machine)
    puts "Machine health check for #{machine["Name"]} has not yet completed. Waiting 5 seconds to try again."
    counter += 1
    sleep 5
  end

  machine
end
poll_until_worker_has_completed_healthcheck(serverUrl, apiKey, thumbprint) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 133
def poll_until_worker_has_completed_healthcheck(serverUrl, apiKey, thumbprint)
  worker = nil
  url = "#{serverUrl}/api/#{@spaceFragment}workers/all?api-key=#{apiKey}"

  now = Time.now
  counter = 1
  loop do
    worker = get_worker_via_api(serverUrl, apiKey, thumbprint)

    break if worker.nil?
    break if counter > 10
    break if !worker_healthcheck_outstanding(worker)
    puts "Machine health check for #{worker["Name"]} has not yet completed. Waiting 5 seconds to try again."
    counter += 1
    sleep 5
  end

  worker
end
worker_healthcheck_outstanding(worker) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 153
def worker_healthcheck_outstanding(worker)
  worker["StatusSummary"] == "This machine was recently added. Please perform a health check."
end