octopus-serverspec-extensions 0.15.4 → 0.15.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 260a7c2b8e6581eacd93f295117fa984b5e496dc51cb23c798d34c02c8411690
         | 
| 4 | 
            +
              data.tar.gz: 348f4dfda4e0cf997e881e85c79fe10146982692d7af54aa5af8b354701fe755
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 68c3951d2313d435d1f106028862489bdf3eef2dd65b1731ba01aa61e24387c750480fbca74713c5be5a25d66d10e2b176442890a7006b29340e68ad8e556314
         | 
| 7 | 
            +
              data.tar.gz: 8997eca9173dce7dfc46e0ec63af78fe043b0d7d652279128c9233ca110b937ea4d2921b37fa5d0bae9e9cd35ec41e42c3a85c05b2b3963b7da4fff4888c2b1e
         | 
| @@ -5,6 +5,7 @@ require 'octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb' | |
| 5 5 | 
             
            require 'octopus_serverspec_extensions/type/octopus_deploy_environment.rb'
         | 
| 6 6 | 
             
            require 'octopus_serverspec_extensions/type/octopus_deploy_project_group.rb'
         | 
| 7 7 | 
             
            require 'octopus_serverspec_extensions/type/octopus_deploy_worker_pool.rb'
         | 
| 8 | 
            +
            require 'octopus_serverspec_extensions/type/octopus_deploy_account.rb'
         | 
| 8 9 | 
             
            require 'octopus_serverspec_extensions/type/windows_dsc.rb'
         | 
| 9 10 | 
             
            require 'octopus_serverspec_extensions/type/windows_firewall.rb'
         | 
| 10 11 | 
             
            require 'octopus_serverspec_extensions/type/windows_scheduled_task.rb'
         | 
| @@ -0,0 +1,165 @@ | |
| 1 | 
            +
            require 'serverspec'
         | 
| 2 | 
            +
            require 'serverspec/type/base'
         | 
| 3 | 
            +
            require 'net/http'
         | 
| 4 | 
            +
            require 'json'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module Serverspec::Type
         | 
| 7 | 
            +
              class OctopusDeployAccount < Base
         | 
| 8 | 
            +
                @account = nil
         | 
| 9 | 
            +
                @serverUrl = nil
         | 
| 10 | 
            +
                @apiKey = nil
         | 
| 11 | 
            +
                @serverSupportsSpaces = nil
         | 
| 12 | 
            +
                @spaceId = nil
         | 
| 13 | 
            +
                @spaceFragment = ""
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                # constants for account types
         | 
| 16 | 
            +
                AZURE = 'AzureSubscription'.freeze
         | 
| 17 | 
            +
                AWS = 'AmazonWebServicesAccount'.freeze
         | 
| 18 | 
            +
                SSH = 'SshKeypair'.freeze
         | 
| 19 | 
            +
                TOKEN = 'Token'.freeze
         | 
| 20 | 
            +
                USERNAME = 'UsernamePassword'.freeze
         | 
| 21 | 
            +
                ACCOUNTTYPES = [AZURE, AWS, SSH, TOKEN, USERNAME]
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def initialize(serverUrl, apiKey, account_name, space_name = nil)
         | 
| 24 | 
            +
                  @name = "Octopus Deploy Account #{account_name}"
         | 
| 25 | 
            +
                  @runner = Specinfra::Runner
         | 
| 26 | 
            +
                  @serverUrl = serverUrl
         | 
| 27 | 
            +
                  @apiKey = apiKey
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  if serverUrl.nil?
         | 
| 30 | 
            +
                    raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                  if apiKey.nil?
         | 
| 33 | 
            +
                    raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
                  if account_name.nil?
         | 
| 36 | 
            +
                    raise "'account_name' was not provided. Unable to connect to Octopus server to validate configuration."
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  @serverSupportsSpaces = check_supports_spaces(serverUrl)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  if @serverSupportsSpaces
         | 
| 42 | 
            +
                    # set the spaceId correctly
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    if space_name.nil?
         | 
| 45 | 
            +
                      @spaceId = 'Spaces-1' # default to Spaces-1
         | 
| 46 | 
            +
                    else
         | 
| 47 | 
            +
                      @spaceId = get_space_id?(space_name)
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    @spaceFragment = "#{@spaceId}/"
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  @account = get_account_via_api(serverUrl, apiKey, account_name)
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                def exists?
         | 
| 57 | 
            +
                  (!@account.nil?) && (@account != [])
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                def has_description?(account_description)
         | 
| 61 | 
            +
                  return false if @account.nil?
         | 
| 62 | 
            +
                  @account["Description"] == account_description
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                def is_account_type?(account_type_name)
         | 
| 66 | 
            +
                  if !ACCOUNTTYPES.include? account_type_name
         | 
| 67 | 
            +
                    raise("'#{account_type_name}' is not a valid account type")
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
                  return false if @account.nil?
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                  @account["AccountType"] == account_type_name
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                def is_azure_account?
         | 
| 75 | 
            +
                  return false if @account.nil?
         | 
| 76 | 
            +
                  @account["AccountType"] == AZURE
         | 
| 77 | 
            +
                  # should also have a subscription number, but Octopus manages validation on this
         | 
| 78 | 
            +
                end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                def is_aws_account?
         | 
| 81 | 
            +
                  return false if @account.nil?
         | 
| 82 | 
            +
                  @account["AccountType"] == AWS
         | 
| 83 | 
            +
                end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                def is_ssh_key_pair?
         | 
| 86 | 
            +
                  return false if @account.nil?
         | 
| 87 | 
            +
                  @account["AccountType"] == SSH
         | 
| 88 | 
            +
                end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                def is_username_password?
         | 
| 91 | 
            +
                  return false if @account.nil?
         | 
| 92 | 
            +
                  @account["AccountType"] == USERNAME
         | 
| 93 | 
            +
                end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                def is_token?
         | 
| 96 | 
            +
                  return false if @account.nil?
         | 
| 97 | 
            +
                  @account["AccountType"] == TOKEN
         | 
| 98 | 
            +
                end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                def in_environment?(environment_name)
         | 
| 101 | 
            +
                  return false if @account.nil?
         | 
| 102 | 
            +
                  url = "#{@serverUrl}/api/#{@spaceFragment}environments/all?api-key=#{@apiKey}"
         | 
| 103 | 
            +
                  resp = Net::HTTP.get_response(URI.parse(url))
         | 
| 104 | 
            +
                  environments = JSON.parse(resp.body)
         | 
| 105 | 
            +
                  environment_id = environments.select {|e| e["Name"] == environment_name}.first["Id"]
         | 
| 106 | 
            +
                  !@account["EnvironmentIds"].select {|e| e == environment_id}.empty?
         | 
| 107 | 
            +
                end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                def has_tenanted_deployment_participation?(mode)
         | 
| 110 | 
            +
                  return false if @machine.nil?
         | 
| 111 | 
            +
                  @machine["TenantedDeploymentParticipation"] == mode # copied directly from tentacle
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                def has_property?(property_name, expected_value)
         | 
| 115 | 
            +
                  return false if @account.nil?
         | 
| 116 | 
            +
                  @account[property_name] == expected_value
         | 
| 117 | 
            +
                end
         | 
| 118 | 
            +
              end
         | 
| 119 | 
            +
             | 
| 120 | 
            +
              def octopus_deploy_account(serverUrl, apiKey, account_name)
         | 
| 121 | 
            +
                OctopusDeployAccount.new(serverUrl, apiKey, account_name)
         | 
| 122 | 
            +
              end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
              private
         | 
| 125 | 
            +
             | 
| 126 | 
            +
              def get_account_via_api(serverUrl, apiKey, account_name)
         | 
| 127 | 
            +
                account = nil
         | 
| 128 | 
            +
                url = "#{serverUrl}/api/#{@spaceFragment}accounts/all?api-key=#{apiKey}"
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                begin
         | 
| 131 | 
            +
                  resp = Net::HTTP.get_response(URI.parse(url))
         | 
| 132 | 
            +
                  body = JSON.parse(resp.body)
         | 
| 133 | 
            +
                  account = body.select {|i| i['Name'] == account_name }.first unless body.nil?
         | 
| 134 | 
            +
                rescue => e
         | 
| 135 | 
            +
                  raise "get_account_via_api: Unable to connect to #{url}: #{e}"
         | 
| 136 | 
            +
                end
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                account
         | 
| 139 | 
            +
              end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
              def check_supports_spaces(serverUrl)
         | 
| 142 | 
            +
                begin
         | 
| 143 | 
            +
                  resp = Net::HTTP.get_response(URI.parse("#{serverUrl}/api/"))
         | 
| 144 | 
            +
                  body = JSON.parse(resp.body)
         | 
| 145 | 
            +
                  version = body['Version']
         | 
| 146 | 
            +
                  return Gem::Version.new(version) > Gem::Version.new('2019.0.0')
         | 
| 147 | 
            +
                rescue => e
         | 
| 148 | 
            +
                  puts "check_supports_spaces: Unable to connect to #{serverUrl}: #{e}"
         | 
| 149 | 
            +
                end
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                false
         | 
| 152 | 
            +
              end
         | 
| 153 | 
            +
             | 
| 154 | 
            +
              def get_space_id?(space_name)
         | 
| 155 | 
            +
                return false if @serverSupportsSpaces.nil?
         | 
| 156 | 
            +
                url = "#{@serverUrl}/api/Spaces/all?api-key=#{@apiKey}"
         | 
| 157 | 
            +
                resp = Net::HTTP.get_response(URI.parse(url))
         | 
| 158 | 
            +
                spaces = JSON.parse(resp.body)
         | 
| 159 | 
            +
                space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
         | 
| 160 | 
            +
                space_id
         | 
| 161 | 
            +
              end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
            end
         | 
| 164 | 
            +
             | 
| 165 | 
            +
            include Serverspec::Type
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: octopus-serverspec-extensions
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.15. | 
| 4 | 
            +
              version: 0.15.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Matt Richardson
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2019-05- | 
| 11 | 
            +
            date: 2019-05-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: serverspec
         | 
| @@ -160,6 +160,7 @@ files: | |
| 160 160 | 
             
            - lib/octopus_serverspec_extensions/type/chocolatey_package.rb
         | 
| 161 161 | 
             
            - lib/octopus_serverspec_extensions/type/java_property_file.rb
         | 
| 162 162 | 
             
            - lib/octopus_serverspec_extensions/type/npm_package.rb
         | 
| 163 | 
            +
            - lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb
         | 
| 163 164 | 
             
            - lib/octopus_serverspec_extensions/type/octopus_deploy_environment.rb
         | 
| 164 165 | 
             
            - lib/octopus_serverspec_extensions/type/octopus_deploy_project_group.rb
         | 
| 165 166 | 
             
            - lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb
         |