Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Add exports to TargetHttpProxy #17

Merged
merged 1 commit into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/puppet/provider/gcompute_target_http_proxy/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
require 'google/compute/property/time'
require 'google/compute/property/urlmap_selflink'
require 'google/hash_utils'
require 'google/object_store'
require 'puppet'

Puppet::Type.type(:gcompute_target_http_proxy).provide(:google) do
Expand All @@ -56,11 +57,13 @@ def self.prefetch(resources)
fetch = fetch_resource(resource, self_link(resource),
'compute#targetHttpProxy')
resource.provider = present(name, fetch) unless fetch.nil?
Google::ObjectStore.instance.add(:gcompute_target_http_proxy, resource)
end
end

def self.present(name, fetch)
result = new({ title: name, ensure: :present }.merge(fetch_to_hash(fetch)))
result.instance_variable_set(:@fetched, fetch)
result
end

Expand Down Expand Up @@ -89,7 +92,7 @@ def create
fetch_auth(@resource),
'application/json',
resource_to_request)
wait_for_operation create_req.send, @resource
@fetched = wait_for_operation create_req.send, @resource
@property_hash[:ensure] = :present
end

Expand All @@ -110,7 +113,7 @@ def flush
fetch_auth(@resource),
'application/json',
resource_to_request)
wait_for_operation update_req.send, @resource
@fetched = wait_for_operation update_req.send, @resource
end

def dirty(field, from, to)
Expand All @@ -121,6 +124,12 @@ def dirty(field, from, to)
}
end

def exports
{
self_link: @fetched['selfLink']
}
end

private

def self.resource_to_hash(resource)
Expand Down
6 changes: 6 additions & 0 deletions lib/puppet/type/gcompute_target_http_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
require 'google/compute/property/string'
require 'google/compute/property/time'
require 'google/compute/property/urlmap_selflink'
require 'google/object_store'
require 'puppet'

Puppet::Type.newtype(:gcompute_target_http_proxy) do
Expand Down Expand Up @@ -88,4 +89,9 @@
newproperty(:url_map, parent: Google::Compute::Property::UrlMapSelfLinkRef) do
desc 'A reference to UrlMap resource'
end

# Returns all properties that a provider can export to other resources
def exports
provider.exports
end
end
46 changes: 46 additions & 0 deletions spec/gcompute_target_http_proxy_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,26 @@
end
end

context '#exports' do
context 'exports all properties' do
let(:resource1) { create_type 1 }
before do
prefetch_url_map
expect_network_get_success 1
described_class.prefetch(title0: resource1)
end

subject { resource1.exports }

let(:expected_results) do
{
self_link: 'selflink(resource(target_http_proxy,0))'
}
end
it { is_expected.to eq(expected_results) }
end
end

private

def expect_network_get_success(id, data = {})
Expand Down Expand Up @@ -1006,6 +1026,32 @@ def debug_network(message)
if ENV['RSPEC_DEBUG'] || ENV['RSPEC_HTTP_VERBOSE']
end

# Creates and prefetch type so exports can be resolved without network access.
def prefetch_url_map
expect_network_get_success_url_map 1

resource = Puppet::Type.type(:gcompute_url_map).new(
project: 'test project#0 data',
name: 'test name#0 data'
)

Puppet::Type.type(:gcompute_url_map).provider(:google)
.prefetch(resource: resource)
end

# Creates and prefetch type so exports can be resolved without network access.
def prefetch_backend_service
expect_network_get_success_backend_service 1

resource = Puppet::Type.type(:gcompute_backend_service).new(
project: 'test project#0 data',
name: 'test name#0 data'
)

Puppet::Type.type(:gcompute_backend_service).provider(:google)
.prefetch(resource: resource)
end

def expand_variables_url_map(template, data, ext_dat = {})
Puppet::Type.type(:gcompute_url_map).provider(:google)
.expand_variables(template, data, ext_dat)
Expand Down