This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
forked from inspec/inspec-gcp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
735f38f
commit 16f45e7
Showing
15 changed files
with
617 additions
and
1 deletion.
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,31 @@ | ||
--- | ||
title: About the google_spanner_database resource | ||
platform: gcp | ||
--- | ||
|
||
## Syntax | ||
A `google_spanner_database` is used to test a Google Database resource | ||
|
||
## Examples | ||
``` | ||
describe google_spanner_database(project: 'chef-gcp-inspec', name: 'spdatabase') do | ||
it { should exist } | ||
its('name') { should eq 'spdatabase' } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_spanner_database` resource: | ||
|
||
|
||
* `name`: A unique identifier for the database, which cannot be changed after the instance is created. Values are of the form [a-z][-a-z0-9]*[a-z0-9]. | ||
|
||
* `extra_statements`: An optional list of DDL statements to run inside the newly created database. Statements can create tables, indexes, etc. These statements execute atomically with the creation of the database: if there is an error in any statement, the database is not created. | ||
|
||
* `instance`: The instance to create the database on. | ||
|
||
|
||
## GCP Permissions | ||
|
||
Ensure the [Cloud Spanner API](https://console.cloud.google.com/apis/library/spanner.googleapis.com/) is enabled for the current project. |
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 google_spanner_databases resource | ||
platform: gcp | ||
--- | ||
|
||
## Syntax | ||
A `google_spanner_databases` is used to test a Google Database resource | ||
|
||
## Examples | ||
``` | ||
describe google_spanner_databases(project: 'chef-gcp-inspec', name: 'spdatabase') do | ||
it { should exist } | ||
its('name') { should eq 'spdatabase' } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_spanner_databases` resource: | ||
|
||
See [google_spanner_database.md](google_spanner_database.md) for more detailed information | ||
* `names`: an array of `google_spanner_database` name | ||
* `extra_statements`: an array of `google_spanner_database` extra_statements | ||
* `instances`: an array of `google_spanner_database` instance | ||
|
||
## 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. | ||
|
||
## GCP Permissions | ||
|
||
Ensure the [Cloud Spanner API](https://console.cloud.google.com/apis/library/spanner.googleapis.com/) is enabled for the current project. |
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,40 @@ | ||
--- | ||
title: About the google_spanner_instance resource | ||
platform: gcp | ||
--- | ||
|
||
## Syntax | ||
A `google_spanner_instance` is used to test a Google Instance resource | ||
|
||
## Examples | ||
``` | ||
describe google_spanner_instance(project: 'chef-gcp-inspec', name: 'spinstance', config: 'regional-us-east1') do | ||
it { should exist } | ||
its('config') { should eq 'projects/'chef-gcp-inspec'/instanceConfigs/regional-us-east1' } | ||
its('name') { should eq 'spinstance' } | ||
its('display_name') { should eq 'inspectest' } | ||
its('node_count') { should eq '2' } | ||
its('labels') { should eq '' } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_spanner_instance` resource: | ||
|
||
|
||
* `name`: A unique identifier for the instance, which cannot be changed after the instance is created. The name must be between 6 and 30 characters in length. | ||
|
||
* `config`: The name of the instance's configuration (similar but not quite the same as a region) which defines defines the geographic placement and replication of your databases in this instance. It determines where your data is stored. Values are typically of the form `regional-europe-west1` , `us-central` etc. In order to obtain a valid list please consult the [Configuration section of the docs](https://cloud.google.com/spanner/docs/instances). | ||
|
||
* `display_name`: The descriptive name for this instance as it appears in UIs. Must be unique per project and between 4 and 30 characters in length. | ||
|
||
* `node_count`: The number of nodes allocated to this instance. | ||
|
||
* `labels`: An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }. | ||
|
||
|
||
## GCP Permissions | ||
|
||
Ensure the [Cloud Spanner API](https://console.cloud.google.com/apis/library/spanner.googleapis.com/) is enabled for the current project. |
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,34 @@ | ||
--- | ||
title: About the google_spanner_instances resource | ||
platform: gcp | ||
--- | ||
|
||
## Syntax | ||
A `google_spanner_instances` is used to test a Google Instance resource | ||
|
||
## Examples | ||
``` | ||
describe google_spanner_instances(project: 'chef-gcp-inspec', config: 'regional-us-east1') do | ||
its('config') { should eq 'regional-us-east1' } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_spanner_instances` resource: | ||
|
||
See [google_spanner_instance.md](google_spanner_instance.md) for more detailed information | ||
* `names`: an array of `google_spanner_instance` name | ||
* `configs`: an array of `google_spanner_instance` config | ||
* `display_names`: an array of `google_spanner_instance` display_name | ||
* `node_counts`: an array of `google_spanner_instance` node_count | ||
* `labels`: an array of `google_spanner_instance` labels | ||
|
||
## 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. | ||
|
||
## GCP Permissions | ||
|
||
Ensure the [Cloud Spanner API](https://console.cloud.google.com/apis/library/spanner.googleapis.com/) is enabled for the current project. |
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,64 @@ | ||
# 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 Cloud Spanner resources. | ||
class SpannerDatabase < GcpResourceBase | ||
name 'google_spanner_database' | ||
desc 'Database' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :params | ||
attr_reader :name | ||
attr_reader :extra_statements | ||
attr_reader :instance | ||
|
||
def initialize(params) | ||
super(params.merge({ use_http_transport: true })) | ||
@params = params | ||
@fetched = @connection.fetch(product_url, resource_base_url, params, 'Get') | ||
parse unless @fetched.nil? | ||
end | ||
|
||
def parse | ||
@name = @fetched['name'] | ||
@extra_statements = @fetched['extraStatements'] | ||
@instance = @fetched['instance'] | ||
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 | ||
|
||
def to_s | ||
"Database #{@params[:name]}" | ||
end | ||
|
||
private | ||
|
||
def product_url | ||
'https://spanner.googleapis.com/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'projects/{{project}}/instances/{{instance}}/databases/{{name}}' | ||
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,88 @@ | ||
# 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 SpannerDatabases < GcpResourceBase | ||
name 'google_spanner_databases' | ||
desc 'Database plural resource' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :table | ||
|
||
filter_table_config = FilterTable.create | ||
|
||
filter_table_config.add(:names, field: :name) | ||
filter_table_config.add(:extra_statements, field: :extra_statements) | ||
filter_table_config.add(:instances, field: :instance) | ||
|
||
filter_table_config.connect(self, :table) | ||
|
||
def initialize(params = {}) | ||
super(params.merge({ use_http_transport: true })) | ||
@params = params | ||
@table = fetch_wrapped_resource('databases') | ||
end | ||
|
||
def fetch_wrapped_resource(wrap_path) | ||
# fetch_resource returns an array of responses (to handle pagination) | ||
result = @connection.fetch_all(product_url, resource_base_url, @params, 'Get') | ||
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_key do |key| | ||
name, value = transform(key, hash) | ||
hash_with_symbols[name] = value | ||
end | ||
converted.push(hash_with_symbols) | ||
end | ||
end | ||
|
||
converted | ||
end | ||
|
||
def transform(key, value) | ||
return transformers[key].call(value) if transformers.key?(key) | ||
|
||
[key.to_sym, value] | ||
end | ||
|
||
def transformers | ||
{ | ||
'name' => ->(obj) { return :name, obj['name'] }, | ||
'extraStatements' => ->(obj) { return :extra_statements, obj['extraStatements'] }, | ||
'instance' => ->(obj) { return :instance, obj['instance'] }, | ||
} | ||
end | ||
|
||
# Handles parsing RFC3339 time string | ||
def parse_time_string(time_string) | ||
time_string ? Time.parse(time_string) : nil | ||
end | ||
|
||
private | ||
|
||
def product_url | ||
'https://spanner.googleapis.com/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'projects/{{project}}/instances/{{instance}}/databases' | ||
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,68 @@ | ||
# 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 Cloud Spanner resources. | ||
class SpannerInstance < GcpResourceBase | ||
name 'google_spanner_instance' | ||
desc 'Instance' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :params | ||
attr_reader :name | ||
attr_reader :config | ||
attr_reader :display_name | ||
attr_reader :node_count | ||
attr_reader :labels | ||
|
||
def initialize(params) | ||
super(params.merge({ use_http_transport: true })) | ||
@params = params | ||
@fetched = @connection.fetch(product_url, resource_base_url, params, 'Get') | ||
parse unless @fetched.nil? | ||
end | ||
|
||
def parse | ||
@name = @fetched['name'] | ||
@config = @fetched['config'] | ||
@display_name = @fetched['displayName'] | ||
@node_count = @fetched['nodeCount'] | ||
@labels = @fetched['labels'] | ||
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 | ||
|
||
def to_s | ||
"Instance #{@params[:name]}" | ||
end | ||
|
||
private | ||
|
||
def product_url | ||
'https://spanner.googleapis.com/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'projects/{{project}}/instances/{{name}}' | ||
end | ||
end |
Oops, something went wrong.