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

Commit

Permalink
Add InSpec support for source repositories
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
slevenick authored and modular-magician committed Feb 19, 2019
1 parent 2688372 commit fb2b900
Show file tree
Hide file tree
Showing 62 changed files with 876 additions and 460 deletions.
31 changes: 31 additions & 0 deletions docs/resources/google_sourcerepo_repositories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: About the google_sourcerepo_repositories resource
platform: gcp
---

## Syntax
A `google_sourcerepo_repositories` is used to test a Google Repository resource

## Examples
```
repo_name = 'inspec-gcp-repository'
describe.one do
google_sourcerepo_repositories(project: 'chef-gcp-inspec').names.each do |name|
describe name do
it { should match /\/repos\/#{repo_name}$/ }
end
end
end
```

## Properties
Properties that can be accessed from the `google_sourcerepo_repositories` resource:

See [google_sourcerepo_repository.md](google_sourcerepo_repository.md) for more detailed information
* `names`: an array of `google_sourcerepo_repository` name
* `urls`: an array of `google_sourcerepo_repository` url
* `sizes`: an array of `google_sourcerepo_repository` size

## 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.
27 changes: 27 additions & 0 deletions docs/resources/google_sourcerepo_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: About the google_sourcerepo_repository resource
platform: gcp
---

## Syntax
A `google_sourcerepo_repository` is used to test a Google Repository resource

## Examples
```
describe google_sourcerepo_repository(project: 'chef-gcp-inspec', name: 'inspec-gcp-repository') do
it { should exist }
end
describe google_sourcerepo_repository(project: 'chef-gcp-inspec', name: 'nonexistent') do
it { should_not exist }
end
```

## Properties
Properties that can be accessed from the `google_sourcerepo_repository` resource:

* `name`: Resource name of the repository, of the form projects/{{project}}/repos/{{repo}}. The repo name may contain slashes. eg, projects/myproject/repos/name/with/slash

* `url`: URL to clone the repository from Google Cloud Source Repositories.

* `size`: The disk usage of the repo, in bytes.
19 changes: 11 additions & 8 deletions libraries/google_bigquery_dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,10 @@ class Dataset < GcpResourceBase
attr_reader :labels
attr_reader :last_modified_time
attr_reader :location
def base
'https://www.googleapis.com/bigquery/v2/'
end

def url
'projects/{{project}}/datasets/{{name}}'
end

def initialize(params)
super(params.merge({ use_http_transport: true }))
@fetched = @connection.fetch(base, url, params)
@fetched = @connection.fetch(product_url, resource_base_url, params)
parse unless @fetched.nil?
end

Expand All @@ -70,4 +63,14 @@ def parse_time_string(time_string)
def exists?
!@fetched.nil?
end

private

def product_url
'https://www.googleapis.com/bigquery/v2/'
end

def resource_base_url
'projects/{{project}}/datasets/{{name}}'
end
end
20 changes: 11 additions & 9 deletions libraries/google_bigquery_datasets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ class Datasets < GcpResourceBase

filter_table_config.connect(self, :table)

def base
'https://www.googleapis.com/bigquery/v2/'
end

def url
'projects/{{project}}/datasets'
end

def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
Expand All @@ -47,7 +39,7 @@ def initialize(params = {})

def fetch_wrapped_resource(wrap_path)
# fetch_resource returns an array of responses (to handle pagination)
result = @connection.fetch_all(base, url, @params)
result = @connection.fetch_all(product_url, resource_base_url, @params)
return if result.nil?

# Conversion of string -> object hash to symbol -> object hash that InSpec needs
Expand Down Expand Up @@ -87,4 +79,14 @@ def transformers
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end

private

def product_url
'https://www.googleapis.com/bigquery/v2/'
end

def resource_base_url
'projects/{{project}}/datasets'
end
end
19 changes: 11 additions & 8 deletions libraries/google_bigquery_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,10 @@ class Table < GcpResourceBase
attr_reader :expiration_time
attr_reader :external_data_configuration
attr_reader :dataset
def base
'https://www.googleapis.com/bigquery/v2/'
end

def url
'projects/{{project}}/datasets/{{dataset}}/tables/{{name}}'
end

def initialize(params)
super(params.merge({ use_http_transport: true }))
@fetched = @connection.fetch(base, url, params)
@fetched = @connection.fetch(product_url, resource_base_url, params)
parse unless @fetched.nil?
end

Expand Down Expand Up @@ -103,4 +96,14 @@ def parse_time_string(time_string)
def exists?
!@fetched.nil?
end

private

def product_url
'https://www.googleapis.com/bigquery/v2/'
end

def resource_base_url
'projects/{{project}}/datasets/{{dataset}}/tables/{{name}}'
end
end
20 changes: 11 additions & 9 deletions libraries/google_bigquery_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ class Tables < GcpResourceBase

filter_table_config.connect(self, :table)

def base
'https://www.googleapis.com/bigquery/v2/'
end

def url
'projects/{{project}}/datasets/{{dataset}}/tables'
end

def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
Expand All @@ -61,7 +53,7 @@ def initialize(params = {})

def fetch_wrapped_resource(wrap_path)
# fetch_resource returns an array of responses (to handle pagination)
result = @connection.fetch_all(base, url, @params)
result = @connection.fetch_all(product_url, resource_base_url, @params)
return if result.nil?

# Conversion of string -> object hash to symbol -> object hash that InSpec needs
Expand Down Expand Up @@ -115,4 +107,14 @@ def transformers
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end

private

def product_url
'https://www.googleapis.com/bigquery/v2/'
end

def resource_base_url
'projects/{{project}}/datasets/{{dataset}}/tables'
end
end
19 changes: 11 additions & 8 deletions libraries/google_cloudbuild_trigger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,10 @@ class Trigger < GcpResourceBase
attr_reader :included_files
attr_reader :trigger_template
attr_reader :build
def base
'https://cloudbuild.googleapis.com/v1/'
end

def url
'projects/{{project}}/triggers/{{id}}'
end

def initialize(params)
super(params.merge({ use_http_transport: true }))
@fetched = @connection.fetch(base, url, params)
@fetched = @connection.fetch(product_url, resource_base_url, params)
parse unless @fetched.nil?
end

Expand All @@ -69,4 +62,14 @@ def parse_time_string(time_string)
def exists?
!@fetched.nil?
end

private

def product_url
'https://cloudbuild.googleapis.com/v1/'
end

def resource_base_url
'projects/{{project}}/triggers/{{id}}'
end
end
20 changes: 11 additions & 9 deletions libraries/google_cloudbuild_triggers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ class Triggers < GcpResourceBase

filter_table_config.connect(self, :table)

def base
'https://cloudbuild.googleapis.com/v1/'
end

def url
'projects/{{project}}/triggers'
end

def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
Expand All @@ -52,7 +44,7 @@ def initialize(params = {})

def fetch_wrapped_resource(wrap_path)
# fetch_resource returns an array of responses (to handle pagination)
result = @connection.fetch_all(base, url, @params)
result = @connection.fetch_all(product_url, resource_base_url, @params)
return if result.nil?

# Conversion of string -> object hash to symbol -> object hash that InSpec needs
Expand Down Expand Up @@ -97,4 +89,14 @@ def transformers
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end

private

def product_url
'https://cloudbuild.googleapis.com/v1/'
end

def resource_base_url
'projects/{{project}}/triggers'
end
end
19 changes: 11 additions & 8 deletions libraries/google_compute_autoscaler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,10 @@ class Autoscaler < GcpResourceBase
attr_reader :autoscaling_policy
attr_reader :target
attr_reader :zone
def base
'https://www.googleapis.com/compute/v1/'
end

def url
'projects/{{project}}/zones/{{zone}}/autoscalers/{{name}}'
end

def initialize(params)
super(params.merge({ use_http_transport: true }))
@fetched = @connection.fetch(base, url, params)
@fetched = @connection.fetch(product_url, resource_base_url, params)
parse unless @fetched.nil?
end

Expand All @@ -64,4 +57,14 @@ def parse_time_string(time_string)
def exists?
!@fetched.nil?
end

private

def product_url
'https://www.googleapis.com/compute/v1/'
end

def resource_base_url
'projects/{{project}}/zones/{{zone}}/autoscalers/{{name}}'
end
end
20 changes: 11 additions & 9 deletions libraries/google_compute_autoscalers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ class Autoscalers < GcpResourceBase

filter_table_config.connect(self, :table)

def base
'https://www.googleapis.com/compute/v1/'
end

def url
'projects/{{project}}/zones/{{zone}}/autoscalers'
end

def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
Expand All @@ -49,7 +41,7 @@ def initialize(params = {})

def fetch_wrapped_resource(wrap_path)
# fetch_resource returns an array of responses (to handle pagination)
result = @connection.fetch_all(base, url, @params)
result = @connection.fetch_all(product_url, resource_base_url, @params)
return if result.nil?

# Conversion of string -> object hash to symbol -> object hash that InSpec needs
Expand Down Expand Up @@ -91,4 +83,14 @@ def transformers
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end

private

def product_url
'https://www.googleapis.com/compute/v1/'
end

def resource_base_url
'projects/{{project}}/zones/{{zone}}/autoscalers'
end
end
19 changes: 11 additions & 8 deletions libraries/google_compute_backend_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ class BackendService < GcpResourceBase
attr_reader :region
attr_reader :session_affinity
attr_reader :timeout_sec
def base
'https://www.googleapis.com/compute/v1/'
end

def url
'projects/{{project}}/global/backendServices/{{name}}'
end

def initialize(params)
super(params.merge({ use_http_transport: true }))
@fetched = @connection.fetch(base, url, params)
@fetched = @connection.fetch(product_url, resource_base_url, params)
parse unless @fetched.nil?
end

Expand Down Expand Up @@ -85,4 +78,14 @@ def parse_time_string(time_string)
def exists?
!@fetched.nil?
end

private

def product_url
'https://www.googleapis.com/compute/v1/'
end

def resource_base_url
'projects/{{project}}/global/backendServices/{{name}}'
end
end
Loading

0 comments on commit fb2b900

Please sign in to comment.