Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bigquery subnetworks and networks to generate #206

Merged
merged 1 commit into from
Nov 21, 2019
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
69 changes: 69 additions & 0 deletions generate/gen-controls/bigquery_dataset.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

require 'yaml'
require 'logger'

title 'Test GCP google_bigquery_dataset resource.'
# rubocop:disable Metrics/BlockLength
control 'google_bigquery_dataset-1.0' do
impact 1.0
title 'google_bigquery_dataset resource test'

logger = Logger.new(STDOUT)
logger.level = Logger::WARN
logger.warn('Generating tests for google_bigquery_dataset')
filters = []
ignored_fields = []
output_folder = ENV['OUTPUT_PATH']

if output_folder.nil?
output_folder = File.join(File.dirname(__FILE__), '../../generated_tests')
logger.warn("Undefined output folder path at variable OUTPUT_PATH. Defaulting to #{File.expand_path(output_folder)}")
end

Dir.mkdir(output_folder) unless File.exist?(output_folder)
template_path = File.join(File.dirname(__FILE__), '../../generated_test_template.erb')
config_folder = ENV['CNF_PATH']
logger.warn('Undefined configuration folder path at variable CNF_PATH. Ignoring configuration files')
unless config_folder.nil?
file_name = File.join(config_folder, 'google_bigquery_dataset.yaml')
if File.file?(file_name)
config = YAML.load_file(file_name)
config_filters = config['filters']
config_filters.each do
# This is not currently implemented
logger.warn('Filters are not currently supported, ignoring')
end
config_ignored = config['ignore_fields']
ignored_fields += config_ignored
end
end
project_name = ENV['GCP_PROJECT_NAME']
raise 'Undefined project name, please set the GCP_PROJECT_NAME variable' if project_name.nil?
plural_identifiers = [{ project: project_name }]

all_identifiers = []
i = 0
plural_identifiers.each do |plural_identifier|
plural = google_bigquery_datasets(plural_identifier)
identifiers = plural.identifiers

identifiers.each do |identifier|
all_identifiers.push(identifier)
resource = google_bigquery_dataset(identifier)

unless filters.all? { |filter| filter.call(resource) }
next
end
resource.dump(output_folder, template_path, i, ignored_fields)

output = "Writing #{File.expand_path(output_folder)}/Dataset_#{i}.rb"
describe output do
# Prints pretty message when writing controls to files
its('length') { should be >= 0 }
end
i += 1
end
end
end
# rubocop:enable Metrics/BlockLength
78 changes: 78 additions & 0 deletions generate/gen-controls/bigquery_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true

require 'yaml'
require 'logger'

title 'Test GCP google_bigquery_table resource.'
# rubocop:disable Metrics/BlockLength
control 'google_bigquery_table-1.0' do
impact 1.0
title 'google_bigquery_table resource test'

logger = Logger.new(STDOUT)
logger.level = Logger::WARN
logger.warn('Generating tests for google_bigquery_table')
filters = []
ignored_fields = []
output_folder = ENV['OUTPUT_PATH']

if output_folder.nil?
output_folder = File.join(File.dirname(__FILE__), '../../generated_tests')
logger.warn("Undefined output folder path at variable OUTPUT_PATH. Defaulting to #{File.expand_path(output_folder)}")
end

Dir.mkdir(output_folder) unless File.exist?(output_folder)
template_path = File.join(File.dirname(__FILE__), '../../generated_test_template.erb')
config_folder = ENV['CNF_PATH']
logger.warn('Undefined configuration folder path at variable CNF_PATH. Ignoring configuration files')
unless config_folder.nil?
file_name = File.join(config_folder, 'google_bigquery_table.yaml')
if File.file?(file_name)
config = YAML.load_file(file_name)
config_filters = config['filters']
config_filters.each do
# This is not currently implemented
logger.warn('Filters are not currently supported, ignoring')
end
config_ignored = config['ignore_fields']
ignored_fields += config_ignored
end
end
project_name = ENV['GCP_PROJECT_NAME']
raise 'Undefined project name, please set the GCP_PROJECT_NAME variable' if project_name.nil?
plural_identifiers = [{ project: project_name }]

next_identifiers = []
dataset_ids = google_bigquery_datasets(project: project_name).ids
dataset_ids.each do |dataset_id|
plural_identifiers.each do |plural_identifier|
next_identifiers.push(plural_identifier.merge({ dataset: dataset_id.split(':').last }))
end
end
plural_identifiers = next_identifiers

all_identifiers = []
i = 0
plural_identifiers.each do |plural_identifier|
plural = google_bigquery_tables(plural_identifier)
identifiers = plural.identifiers

identifiers.each do |identifier|
all_identifiers.push(identifier)
resource = google_bigquery_table(identifier)

unless filters.all? { |filter| filter.call(resource) }
next
end
resource.dump(output_folder, template_path, i, ignored_fields)

output = "Writing #{File.expand_path(output_folder)}/Table_#{i}.rb"
describe output do
# Prints pretty message when writing controls to files
its('length') { should be >= 0 }
end
i += 1
end
end
end
# rubocop:enable Metrics/BlockLength
69 changes: 69 additions & 0 deletions generate/gen-controls/compute_network.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

require 'yaml'
require 'logger'

title 'Test GCP google_compute_network resource.'
# rubocop:disable Metrics/BlockLength
control 'google_compute_network-1.0' do
impact 1.0
title 'google_compute_network resource test'

logger = Logger.new(STDOUT)
logger.level = Logger::WARN
logger.warn('Generating tests for google_compute_network')
filters = []
ignored_fields = []
output_folder = ENV['OUTPUT_PATH']

if output_folder.nil?
output_folder = File.join(File.dirname(__FILE__), '../../generated_tests')
logger.warn("Undefined output folder path at variable OUTPUT_PATH. Defaulting to #{File.expand_path(output_folder)}")
end

Dir.mkdir(output_folder) unless File.exist?(output_folder)
template_path = File.join(File.dirname(__FILE__), '../../generated_test_template.erb')
config_folder = ENV['CNF_PATH']
logger.warn('Undefined configuration folder path at variable CNF_PATH. Ignoring configuration files')
unless config_folder.nil?
file_name = File.join(config_folder, 'google_compute_network.yaml')
if File.file?(file_name)
config = YAML.load_file(file_name)
config_filters = config['filters']
config_filters.each do
# This is not currently implemented
logger.warn('Filters are not currently supported, ignoring')
end
config_ignored = config['ignore_fields']
ignored_fields += config_ignored
end
end
project_name = ENV['GCP_PROJECT_NAME']
raise 'Undefined project name, please set the GCP_PROJECT_NAME variable' if project_name.nil?
plural_identifiers = [{ project: project_name }]

all_identifiers = []
i = 0
plural_identifiers.each do |plural_identifier|
plural = google_compute_networks(plural_identifier)
identifiers = plural.identifiers

identifiers.each do |identifier|
all_identifiers.push(identifier)
resource = google_compute_network(identifier)

unless filters.all? { |filter| filter.call(resource) }
next
end
resource.dump(output_folder, template_path, i, ignored_fields)

output = "Writing #{File.expand_path(output_folder)}/Network_#{i}.rb"
describe output do
# Prints pretty message when writing controls to files
its('length') { should be >= 0 }
end
i += 1
end
end
end
# rubocop:enable Metrics/BlockLength
78 changes: 78 additions & 0 deletions generate/gen-controls/compute_subnetwork.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true

require 'yaml'
require 'logger'

title 'Test GCP google_compute_subnetwork resource.'
# rubocop:disable Metrics/BlockLength
control 'google_compute_subnetwork-1.0' do
impact 1.0
title 'google_compute_subnetwork resource test'

logger = Logger.new(STDOUT)
logger.level = Logger::WARN
logger.warn('Generating tests for google_compute_subnetwork')
filters = []
ignored_fields = []
output_folder = ENV['OUTPUT_PATH']

if output_folder.nil?
output_folder = File.join(File.dirname(__FILE__), '../../generated_tests')
logger.warn("Undefined output folder path at variable OUTPUT_PATH. Defaulting to #{File.expand_path(output_folder)}")
end

Dir.mkdir(output_folder) unless File.exist?(output_folder)
template_path = File.join(File.dirname(__FILE__), '../../generated_test_template.erb')
config_folder = ENV['CNF_PATH']
logger.warn('Undefined configuration folder path at variable CNF_PATH. Ignoring configuration files')
unless config_folder.nil?
file_name = File.join(config_folder, 'google_compute_subnetwork.yaml')
if File.file?(file_name)
config = YAML.load_file(file_name)
config_filters = config['filters']
config_filters.each do
# This is not currently implemented
logger.warn('Filters are not currently supported, ignoring')
end
config_ignored = config['ignore_fields']
ignored_fields += config_ignored
end
end
project_name = ENV['GCP_PROJECT_NAME']
raise 'Undefined project name, please set the GCP_PROJECT_NAME variable' if project_name.nil?
plural_identifiers = [{ project: project_name }]

next_identifiers = []
region_names = google_compute_regions(project: project_name).region_names
region_names.each do |region_name|
plural_identifiers.each do |plural_identifier|
next_identifiers.push(plural_identifier.merge({ region: region_name }))
end
end
plural_identifiers = next_identifiers

all_identifiers = []
i = 0
plural_identifiers.each do |plural_identifier|
plural = google_compute_subnetworks(plural_identifier)
identifiers = plural.identifiers

identifiers.each do |identifier|
all_identifiers.push(identifier)
resource = google_compute_subnetwork(identifier)

unless filters.all? { |filter| filter.call(resource) }
next
end
resource.dump(output_folder, template_path, i, ignored_fields)

output = "Writing #{File.expand_path(output_folder)}/Subnetwork_#{i}.rb"
describe output do
# Prints pretty message when writing controls to files
its('length') { should be >= 0 }
end
i += 1
end
end
end
# rubocop:enable Metrics/BlockLength
6 changes: 5 additions & 1 deletion generate/libraries/google_bigquery_datasets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ def identifiers
combo = item.merge(@params)
item_identifiers = {}
params.each do |param|
item_identifiers[param.to_sym] = combo[param.to_sym]
if param == 'name'
item_identifiers[param.to_sym] = item[:dataset_reference].dataset_id
else
item_identifiers[param.to_sym] = combo[param.to_sym]
end
end
result.push(item_identifiers)
end
Expand Down
6 changes: 5 additions & 1 deletion generate/libraries/google_bigquery_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def identifiers
combo = item.merge(@params)
item_identifiers = {}
params.each do |param|
item_identifiers[param.to_sym] = combo[param.to_sym]
if param == 'name'
item_identifiers[param.to_sym] = item[:table_reference].table_id
else
item_identifiers[param.to_sym] = combo[param.to_sym]
end
end
result.push(item_identifiers)
end
Expand Down
Loading