Class: Serverspec::Type::OctopusDeployAccount
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::OctopusDeployAccount
- 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
- #exists? ⇒ Boolean
- #has_description?(account_description) ⇒ Boolean
- #has_property?(property_name, expected_value) ⇒ Boolean
- #has_tenanted_deployment_participation?(mode) ⇒ Boolean
- #in_environment?(environment_name) ⇒ Boolean
-
#initialize(serverUrl, apiKey, account_name, space_name = nil) ⇒ OctopusDeployAccount
constructor
A new instance of OctopusDeployAccount.
- #is_account_type?(account_type_name) ⇒ Boolean
- #is_aws_account? ⇒ Boolean
- #is_azure_account? ⇒ Boolean
- #is_ssh_key_pair? ⇒ Boolean
- #is_token? ⇒ Boolean
- #is_username_password? ⇒ Boolean
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, account_name, 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 account_name.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 = get_account_via_api(serverUrl, apiKey, account_name) end |
Instance Method Details
#exists? ⇒ 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
60 61 62 63 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 60 def has_description?(account_description) return false if @account.nil? @account["Description"] == account_description end |
#has_property?(property_name, expected_value) ⇒ 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
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
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
65 66 67 68 69 70 71 72 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb', line 65 def is_account_type?(account_type_name) if !ACCOUNTTYPES.include? account_type_name raise("'#{account_type_name}' is not a valid account type") end return false if @account.nil? @account["AccountType"] == account_type_name end |
#is_aws_account? ⇒ 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
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
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
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
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 |