-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from modular-magician/codegen-pr-1239
Inspec resource record sets
- Loading branch information
Showing
8 changed files
with
340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: About the ResourceRecordSet resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_dns_resource_record_set` is used to test a Google ResourceRecordSet resource | ||
|
||
## Examples | ||
``` | ||
describe google_dns_resource_record_set(project: 'chef-gcp-inspec', name: 'backend.my.domain.com.', type: 'A', managed_zone: 'inspec-gcp-managed-zone') do | ||
it { should exist } | ||
its('type') { should eq 'A' } | ||
its('ttl') { should eq '300' } | ||
its('target') { should include '8.8.8.8' } | ||
its('target') { should include '8.8.4.4' } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_dns_resource_record_set` resource: | ||
|
||
* `name`: For example, www.example.com. | ||
|
||
* `type`: One of valid DNS resource types. | ||
|
||
* `ttl`: Number of seconds that this ResourceRecordSet can be cached by resolvers. | ||
|
||
* `target`: As defined in RFC 1035 (section 5) and RFC 1034 (section 3.6.1) | ||
|
||
* `managed_zone`: Identifies the managed zone addressed by this request. Can be the managed zone name or id. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: About the ResourceRecordSet resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_dns_resource_record_sets` is used to test a Google ResourceRecordSet resource | ||
|
||
## Examples | ||
``` | ||
describe google_dns_resource_record_sets(project: 'chef-gcp-inspec', name: 'backend.my.domain.com.', managed_zone: 'inspec-gcp-managed-zone') do | ||
its('count') { should eq 3 } | ||
its('types') { should include 'A' } | ||
its('ttls') { should include '300' } | ||
its('targets.flatten') { should include '8.8.8.8' } | ||
its('targets.flatten') { should include '8.8.4.4' } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_dns_resource_record_sets` resource: | ||
|
||
See [google_dns_resource_record_set.md](google_dns_resource_record_set.md) for more detailed information | ||
* `names`: an array of `google_dns_resource_record_set` name | ||
* `types`: an array of `google_dns_resource_record_set` type | ||
* `ttls`: an array of `google_dns_resource_record_set` ttl | ||
* `targets`: an array of `google_dns_resource_record_set` target | ||
* `managed_zones`: an array of `google_dns_resource_record_set` managed_zone | ||
|
||
## Filter Criteria | ||
This resource supports all of the above properties as filter criteria, which can be used | ||
with `where` as a block or a method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in README.md and | ||
# CONTRIBUTING.md located at the root of this package. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
require 'gcp_backend' | ||
|
||
# A provider to manage Google Cloud DNS resources. | ||
class ResourceRecordSet < GcpResourceBase | ||
name 'google_dns_resource_record_set' | ||
desc 'ResourceRecordSet' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :name | ||
attr_reader :type | ||
attr_reader :ttl | ||
attr_reader :target | ||
attr_reader :managed_zone | ||
def base | ||
'https://www.googleapis.com/dns/v1/' | ||
end | ||
|
||
def url | ||
'projects/{{project}}/managedZones/{{managed_zone}}/rrsets?name={{name}}&type={{type}}' | ||
end | ||
|
||
def initialize(params) | ||
super(params.merge({ use_http_transport: true })) | ||
fetched = @connection.fetch(base, url, params) | ||
@fetched = unwrap(fetched, params) | ||
parse unless @fetched.nil? | ||
end | ||
|
||
def identity | ||
%w{name type} | ||
end | ||
|
||
def collection_item | ||
'rrsets' | ||
end | ||
|
||
def unwrap(fetched, params) | ||
fetched[collection_item].find { |result| identity.all? { |id| result[id.to_sym] == params[id] } } | ||
end | ||
|
||
def parse | ||
@name = @fetched['name'] | ||
@type = @fetched['type'] | ||
@ttl = @fetched['ttl'] | ||
@target = @fetched['rrdatas'] | ||
@managed_zone = @fetched['managed_zone'] | ||
end | ||
|
||
# Handles parsing RFC3339 time string | ||
def parse_time_string(time_string) | ||
time_string ? Time.parse(time_string) : nil | ||
end | ||
|
||
def exists? | ||
!@fetched.nil? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in README.md and | ||
# CONTRIBUTING.md located at the root of this package. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
require 'gcp_backend' | ||
class ResourceRecordSets < GcpResourceBase | ||
name 'google_dns_resource_record_sets' | ||
desc 'ResourceRecordSet plural resource' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :table | ||
|
||
filter_table_config = FilterTable.create | ||
|
||
filter_table_config.add(:names, field: :name) | ||
filter_table_config.add(:types, field: :type) | ||
filter_table_config.add(:ttls, field: :ttl) | ||
filter_table_config.add(:targets, field: :target) | ||
filter_table_config.add(:managed_zones, field: :managed_zone) | ||
|
||
filter_table_config.connect(self, :table) | ||
|
||
def base | ||
'https://www.googleapis.com/dns/v1/' | ||
end | ||
|
||
def url | ||
'projects/{{project}}/managedZones/{{managed_zone}}/rrsets' | ||
end | ||
|
||
def api_names | ||
{ | ||
'rrdatas' => 'target', | ||
} | ||
end | ||
|
||
def initialize(params = {}) | ||
super(params.merge({ use_http_transport: true })) | ||
@params = params | ||
@table = fetch_wrapped_resource('rrsets') | ||
end | ||
|
||
def fetch_wrapped_resource(wrap_path) | ||
# fetch_resource returns an array of responses (to handle pagination) | ||
result = @connection.fetch_all(base, url, @params) | ||
return if result.nil? | ||
|
||
# Conversion of string -> object hash to symbol -> object hash that InSpec needs | ||
converted = [] | ||
result.each do |response| | ||
next if response.nil? || !response.key?(wrap_path) | ||
response[wrap_path].each do |hash| | ||
hash_with_symbols = {} | ||
hash.each_pair { |k, v| api_names.key?(k) ? hash_with_symbols[api_names[k].to_sym] = v : hash_with_symbols[k.to_sym] = v } | ||
converted.push(hash_with_symbols) | ||
end | ||
end | ||
|
||
converted | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
test/integration/verify/controls/google_dns_resource_record_set.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in README.md and | ||
# CONTRIBUTING.md located at the root of this package. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
|
||
title 'Test GCP google_dns_resource_record_set resource.' | ||
|
||
gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') | ||
record_set = attribute('record_set', default: { | ||
"name": "backend.my.domain.com.", | ||
"type": "A", | ||
"ttl": 300, | ||
"rrdatas1": "8.8.8.8", | ||
"rrdatas2": "8.8.4.4" | ||
}) | ||
managed_zone = attribute('managed_zone', default: { | ||
"name": "inspec-gcp-managed-zone", | ||
"dns_name": "my.domain.com.", | ||
"description": "A test DNS zone", | ||
"label_key": "key", | ||
"label_value": "value" | ||
}) | ||
control 'google_dns_resource_record_set-1.0' do | ||
impact 1.0 | ||
title 'google_dns_resource_record_set resource test' | ||
|
||
describe google_dns_resource_record_set(project: gcp_project_id, name: record_set['name'], type: record_set['type'], managed_zone: managed_zone['name']) do | ||
it { should exist } | ||
its('type') { should eq record_set['type'] } | ||
its('ttl') { should eq record_set['ttl'] } | ||
its('target') { should include record_set['rrdatas1'] } | ||
its('target') { should include record_set['rrdatas2'] } | ||
end | ||
end |
43 changes: 43 additions & 0 deletions
43
test/integration/verify/controls/google_dns_resource_record_sets.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in README.md and | ||
# CONTRIBUTING.md located at the root of this package. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
|
||
title 'Test GCP google_dns_resource_record_sets resource.' | ||
|
||
gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') | ||
record_set = attribute('record_set', default: { | ||
"name": "backend.my.domain.com.", | ||
"type": "A", | ||
"ttl": 300, | ||
"rrdatas1": "8.8.8.8", | ||
"rrdatas2": "8.8.4.4" | ||
}) | ||
managed_zone = attribute('managed_zone', default: { | ||
"name": "inspec-gcp-managed-zone", | ||
"dns_name": "my.domain.com.", | ||
"description": "A test DNS zone", | ||
"label_key": "key", | ||
"label_value": "value" | ||
}) | ||
control 'google_dns_resource_record_sets-1.0' do | ||
impact 1.0 | ||
title 'google_dns_resource_record_sets resource test' | ||
|
||
describe google_dns_resource_record_sets(project: gcp_project_id, name: record_set['name'], managed_zone: managed_zone['name']) do | ||
its('count') { should eq 3 } | ||
its('types') { should include record_set['type'] } | ||
its('ttls') { should include record_set['ttl'] } | ||
its('targets.flatten') { should include record_set['rrdatas1'] } | ||
its('targets.flatten') { should include record_set['rrdatas2'] } | ||
end | ||
end |