Class: Serverspec::Type::OctopusDeployAccount

Inherits:
Base
  • Object
show all
Defined in:
lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb

Constant Summary collapse

AZURE =

constants for account types

'AzureSubscription'.freeze
AWS =
'AmazonWebServicesAccount'.freeze
SSH =
'SshKeypair'.freeze
TOKEN =
'Token'.freeze
USERNAME =
'UsernamePassword'.freeze
ACCOUNTTYPES =
[AZURE, AWS, SSH, TOKEN, USERNAME]

Instance Method Summary collapse

Constructor Details

#initialize(serverUrl, apiKey, account_name, space_name = nil) ⇒ OctopusDeployAccount

Returns a new instance of OctopusDeployAccount.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 23

def initialize(serverUrl, apiKey, , space_name = nil)
  @name = "Octopus Deploy Account #{account_name}"
  @runner = Specinfra::Runner
  @serverUrl = serverUrl
  @apiKey = apiKey

  if serverUrl.nil?
    raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
  end
  if apiKey.nil?
    raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
  end
  if .nil?
    raise "'account_name' was not provided. Unable to connect to Octopus server to validate configuration."
  end

  @serverSupportsSpaces = check_supports_spaces(serverUrl)

  if @serverSupportsSpaces
    # set the spaceId correctly


    if space_name.nil?
      @spaceId = 'Spaces-1' # default to Spaces-1

    else
      @spaceId = get_space_id?(space_name)
    end

    @spaceFragment = "#{@spaceId}/"
  end

  @account = (serverUrl, apiKey, )
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 56

def exists?
  (!@account.nil?) && (@account != [])
end

#has_description?(account_description) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 60

def has_description?()
  return false if @account.nil?
  @account["Description"] == 
end

#has_property?(property_name, expected_value) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
117
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 114

def has_property?(property_name, expected_value)
  return false if @account.nil?
  @account[property_name] == expected_value
end

#has_tenanted_deployment_participation?(mode) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
112
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 109

def has_tenanted_deployment_participation?(mode)
  return false if @machine.nil?
  @machine["TenantedDeploymentParticipation"] == mode # copied directly from tentacle

end

#in_environment?(environment_name) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 100

def in_environment?(environment_name)
  return false if @account.nil?
  url = "#{@serverUrl}/api/#{@spaceFragment}environments/all?api-key=#{@apiKey}"
  resp = Net::HTTP.get_response(URI.parse(url))
  environments = JSON.parse(resp.body)
  environment_id = environments.select {|e| e["Name"] == environment_name}.first["Id"]
  !@account["EnvironmentIds"].select {|e| e == environment_id}.empty?
end

#is_account_type?(account_type_name) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 65

def ()
  if !ACCOUNTTYPES.include? 
    raise("'#{account_type_name}' is not a valid account type")
  end
  return false if @account.nil?

  @account["AccountType"] == 
end

#is_aws_account?Boolean

Returns:

  • (Boolean)


80
81
82
83
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 80

def is_aws_account?
  return false if @account.nil?
  @account["AccountType"] == AWS
end

#is_azure_account?Boolean

Returns:

  • (Boolean)


74
75
76
77
78
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 74

def is_azure_account?
  return false if @account.nil?
  @account["AccountType"] == AZURE
  # should also have a subscription number, but Octopus manages validation on this

end

#is_ssh_key_pair?Boolean

Returns:

  • (Boolean)


85
86
87
88
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 85

def is_ssh_key_pair?
  return false if @account.nil?
  @account["AccountType"] == SSH
end

#is_token?Boolean

Returns:

  • (Boolean)


95
96
97
98
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 95

def is_token?
  return false if @account.nil?
  @account["AccountType"] == TOKEN
end

#is_username_password?Boolean

Returns:

  • (Boolean)


90
91
92
93
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 90

def is_username_password?
  return false if @account.nil?
  @account["AccountType"] == USERNAME
end