Sha256: 4b772da9d7bd260757eb030ad6cee26d9d21d97144f16d5a46779660b758d2e3

Contents?: true

Size: 1.96 KB

Versions: 20

Compression:

Stored size: 1.96 KB

Contents

module Fog
  module Compute
    class Google
      class Mock
        def insert_firewall(_firewall_name, _options = {})
          Fog::Mock.not_implemented
        end
      end

      class Real
        INSERTABLE_FIREWALL_FIELDS = %i{
          allowed
          denied
          description
          destination_ranges
          direction
          name
          network
          priority
          source_ranges
          source_service_accounts
          source_tags
          target_service_accounts
          target_tags
        }.freeze

        ##
        # Create a Firewall resource
        #
        # @param [Hash] opts The firewall object to create
        # @option opts [Array<Hash>] allowed
        # @option opts [Array<Hash>] denied
        # @option opts [String] description
        # @option opts [Array<String>] destination_ranges
        # @option opts [String] direction
        # @option opts [String] name
        # @option opts [String] network
        # @option opts [Fixnum] priority
        # @option opts [Array<String>] source_ranges
        # @option opts [Array<String>] source_service_accounts
        # @option opts [Array<String>] source_tags
        # @option opts [Array<String>] target_service_accounts
        # @option opts [Array<String>] target_tags
        #
        # @see https://cloud.google.com/compute/docs/reference/latest/firewalls/insert
        def insert_firewall(firewall_name, opts = {})
          if opts.key?(:network) && !opts[:network].empty?
            unless opts[:network].start_with?("http://", "https://", "projects/", "global/")
              opts[:network] = "projects/#{@project}/global/networks/#{opts[:network]}"
            end
          end

          opts = opts.select { |k, _| INSERTABLE_FIREWALL_FIELDS.include? k }
                     .merge(:name => firewall_name)

          @compute.insert_firewall(
            @project, ::Google::Apis::ComputeV1::Firewall.new(opts)
          )
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
fog-google-1.9.1 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.9.0 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.8.2 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.8.1 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.8.0 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.7.1 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.7.0 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.6.0 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.5.0 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.4.0 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.3.3 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.3.2 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.3.1 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.3.0 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.2.2 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.2.1 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.2.0 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.1.0 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.0.1 lib/fog/compute/google/requests/insert_firewall.rb
fog-google-1.0.0 lib/fog/compute/google/requests/insert_firewall.rb