Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Added property to database instances and helper methods to instance r…
Browse files Browse the repository at this point in the history
…esource.

Signed-off-by: Stuart Paterson <spaterson@chef.io>
  • Loading branch information
Stuart Paterson committed Sep 7, 2018
1 parent 88d43aa commit fb9086c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/resources/google_sql_database_instances.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ The following examples show how to use this InSpec audit resource.

## Filter Criteria

This resource supports the following filter criteria: `instance_name`; `instance_region`; `instance_zone` and `instance_state`. Any of these may be used with `where`, as a block or as a method.
This resource supports the following filter criteria: `instance_name`; `instance_version`; `instance_region`; `instance_zone` and `instance_state`. Any of these may be used with `where`, as a block or as a method.

## Properties

* `instance_names` - an array of google_sql_database_instance name strings
* `instance_versions` - an array of google_sql_database_instance version strings
* `instance_regions`- an array of google_compute_region name strings
* `instance_zones`- an array of google_sql_database_instance name strings
* `instance_states`- an array of google_sql_database_instance state strings
Expand Down
17 changes: 17 additions & 0 deletions libraries/google_sql_database_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ def exists?
!@database.nil?
end

def has_ip_configuration_require_ssl?
return false if !defined?(@database.settings.ip_configuration.require_ssl)
return false if @database.settings.ip_configuration.require_ssl.nil?
return true if @database.settings.ip_configuration.require_ssl.to_s.casecmp('true').zero?
false
end

def authorized_networks
return [] if !defined?(@database.settings.ip_configuration.authorized_networks)
@database.settings.ip_configuration.authorized_networks
end

def primary_ip_address
return false if !defined?(@database.ip_addresses[0].ip_address)
@database.ip_addresses[0].ip_address
end

def to_s
"Database #{@display_name}"
end
Expand Down
2 changes: 2 additions & 0 deletions libraries/google_sql_database_instances.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def initialize(opts = {})
# FilterTable setup
filter_table_config = FilterTable.create
filter_table_config.add(:instance_names, field: :instance_name)
filter_table_config.add(:instance_versions, field: :instance_version)
filter_table_config.add(:instance_regions, field: :instance_region)
filter_table_config.add(:instance_zones, field: :instance_zone)
filter_table_config.add(:instance_states, field: :instance_state)
Expand All @@ -35,6 +36,7 @@ def fetch_data
return [] if !@databases || !@databases.items
@databases.items.map do |instance|
instance_rows+=[{ instance_name: instance.name,
instance_version: instance.database_version,
instance_region: instance.region,
instance_zone: instance.gce_zone,
instance_state: instance.state }]
Expand Down

0 comments on commit fb9086c

Please sign in to comment.