Class: ChefDK::Policyfile::ComparisonBase::PolicyGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-dk/policyfile/comparison_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, policy_name, http_client) ⇒ PolicyGroup

Returns a new instance of PolicyGroup.



98
99
100
101
102
# File 'lib/chef-dk/policyfile/comparison_base.rb', line 98

def initialize(group, policy_name, http_client)
  @group = group
  @policy_name = policy_name
  @http_client = http_client
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



94
95
96
# File 'lib/chef-dk/policyfile/comparison_base.rb', line 94

def group
  @group
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



96
97
98
# File 'lib/chef-dk/policyfile/comparison_base.rb', line 96

def http_client
  @http_client
end

#policy_nameObject (readonly)

Returns the value of attribute policy_name.



95
96
97
# File 'lib/chef-dk/policyfile/comparison_base.rb', line 95

def policy_name
  @policy_name
end

Instance Method Details

#lockObject



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/chef-dk/policyfile/comparison_base.rb', line 108

def lock
  http_client.get("policy_groups/#{group}/policies/#{policy_name}")
rescue Net::ProtocolError => e
  if e.respond_to?(:response) && e.response.code.to_s == "404"
    raise PolicyfileDownloadError.new("No Policyfile lock named '#{policy_name}' found in policy_group '#{group}' at #{http_client.url}", e)
  else
    raise PolicyfileDownloadError.new("HTTP error attempting to fetch Policyfile lock from #{http_client.url}", e)
  end
rescue => e
  raise PolicyfileDownloadError.new("Failed to fetch Policyfile lock from #{http_client.url}", e)
end

#nameObject



104
105
106
# File 'lib/chef-dk/policyfile/comparison_base.rb', line 104

def name
  "policy_group:#{group}"
end