-
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 #357 from inspec/f/AcceleratorTypes
RESOURCE-73 F/accelerator types
- Loading branch information
Showing
9 changed files
with
362 additions
and
7 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,50 @@ | ||
--- | ||
title: About the google_compute_accelerator_type resource | ||
platform: gcp | ||
--- | ||
|
||
## Syntax | ||
A `google_compute_accelerator_type` is used to test a Google AcceleratorType resource | ||
|
||
## Examples | ||
``` | ||
describe google_compute_accelerator_type(project: 'chef-gcp-inspec', zone: 'us-east1-b', name: 'accelerator_id') do | ||
it { should exist } | ||
it { should be_up } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_compute_accelerator_type` resource: | ||
|
||
|
||
* `creation_timestamp`: Creation timestamp in RFC3339 text format. | ||
|
||
* `deprecated`: The deprecation status associated with this accelerator type. | ||
|
||
* `state`: An optional RFC3339 timestamp on or after which the state of this resource is intended to change to DELETED. This is only informational and the status will not change unless the client explicitly changes it. | ||
|
||
* `deprecated`: An optional RFC3339 timestamp on or after which the state of this resource is intended to change to DEPRECATED. This is only informational and the status will not change unless the client explicitly changes it. | ||
|
||
* `obsolete`: An optional RFC3339 timestamp on or after which the state of this resource is intended to change to OBSOLETE. This is only informational and the status will not change unless the client explicitly changes it. | ||
|
||
* `replacement`: The URL of the suggested replacement for a deprecated resource. The suggested replacement resource must be the same kind of resource as the deprecated resource. | ||
|
||
* `state`: The deprecation state of this resource. This can be DEPRECATED, OBSOLETE, or DELETED. Operations which create a new resource using a DEPRECATED resource will return successfully, but with a warning indicating the deprecated resource and recommending its replacement. Operations which use OBSOLETE or DELETED resources will be rejected and result in an error. | ||
Possible values: | ||
* DEPRECATED | ||
* OBSOLETE | ||
* DELETED | ||
|
||
* `description`: An optional textual description of the resource. | ||
|
||
* `id`: The unique identifier for the resource. | ||
|
||
* `name`: Name of the resource. | ||
|
||
* `zone`: The name of the zone where the accelerator type resides. | ||
|
||
|
||
## GCP Permissions | ||
|
||
Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.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_compute_accelerator_types resource | ||
platform: gcp | ||
--- | ||
|
||
## Syntax | ||
A `google_compute_accelerator_types` is used to test a Google AcceleratorType resource | ||
|
||
## Examples | ||
``` | ||
describe google_compute_accelerator_types(project: 'chef-gcp-inspec', zone: 'us-east1-b') do | ||
it { should exist } | ||
it { should be_up } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_compute_accelerator_types` resource: | ||
|
||
See [google_compute_accelerator_type.md](google_compute_accelerator_type.md) for more detailed information | ||
* `creation_timestamps`: an array of `google_compute_accelerator_type` creation_timestamp | ||
* `deprecateds`: an array of `google_compute_accelerator_type` deprecated | ||
* `descriptions`: an array of `google_compute_accelerator_type` description | ||
* `ids`: an array of `google_compute_accelerator_type` id | ||
* `names`: an array of `google_compute_accelerator_type` name | ||
* `zones`: an array of `google_compute_accelerator_type` 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. | ||
|
||
## GCP Permissions | ||
|
||
Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project. |
49 changes: 49 additions & 0 deletions
49
libraries/google/compute/property/acceleratortype_deprecated.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,49 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# 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. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
module GoogleInSpec | ||
module Compute | ||
module Property | ||
class AcceleratorTypeDeprecated | ||
attr_reader :state | ||
|
||
attr_reader :deprecated | ||
|
||
attr_reader :obsolete | ||
|
||
attr_reader :replacement | ||
|
||
def initialize(args = nil, parent_identifier = nil) | ||
return if args.nil? | ||
@parent_identifier = parent_identifier | ||
@state = parse_time_string(args['state']) | ||
@deprecated = parse_time_string(args['deprecated']) | ||
@obsolete = parse_time_string(args['obsolete']) | ||
@replacement = args['replacement'] | ||
@state = args['state'] | ||
end | ||
|
||
def to_s | ||
"#{@parent_identifier} AcceleratorTypeDeprecated" | ||
end | ||
|
||
# Handles parsing RFC3339 time string | ||
def parse_time_string(time_string) | ||
time_string ? Time.parse(time_string) : nil | ||
end | ||
end | ||
end | ||
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,71 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# 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' | ||
require 'google/compute/property/acceleratortype_deprecated' | ||
|
||
# A provider to manage Compute Engine resources. | ||
class ComputeAcceleratorType < GcpResourceBase | ||
name 'google_compute_accelerator_type' | ||
desc 'AcceleratorType' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :params | ||
attr_reader :creation_timestamp | ||
attr_reader :deprecated | ||
attr_reader :description | ||
attr_reader :id | ||
attr_reader :name | ||
attr_reader :zone | ||
|
||
def initialize(params) | ||
super(params.merge({ use_http_transport: true })) | ||
@params = params | ||
@fetched = @connection.fetch(product_url(params[:beta]), resource_base_url, params, 'Get') | ||
parse unless @fetched.nil? | ||
end | ||
|
||
def parse | ||
@creation_timestamp = parse_time_string(@fetched['creationTimestamp']) | ||
@deprecated = GoogleInSpec::Compute::Property::AcceleratorTypeDeprecated.new(@fetched['deprecated'], to_s) | ||
@description = @fetched['description'] | ||
@id = @fetched['id'] | ||
@name = @fetched['name'] | ||
@zone = @fetched['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 | ||
|
||
def to_s | ||
"AcceleratorType #{@params[:name]}" | ||
end | ||
|
||
private | ||
|
||
def product_url(_ = nil) | ||
'https://compute.googleapis.com/compute/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'projects/{{project}}/zones/{{zone}}/acceleratorTypes/{{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,94 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# 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 ComputeAcceleratorTypes < GcpResourceBase | ||
name 'google_compute_accelerator_types' | ||
desc 'AcceleratorType plural resource' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :table | ||
|
||
filter_table_config = FilterTable.create | ||
|
||
filter_table_config.add(:creation_timestamps, field: :creation_timestamp) | ||
filter_table_config.add(:deprecateds, field: :deprecated) | ||
filter_table_config.add(:descriptions, field: :description) | ||
filter_table_config.add(:ids, field: :id) | ||
filter_table_config.add(:names, field: :name) | ||
filter_table_config.add(:zones, field: :zone) | ||
|
||
filter_table_config.connect(self, :table) | ||
|
||
def initialize(params = {}) | ||
super(params.merge({ use_http_transport: true })) | ||
@params = params | ||
@table = fetch_wrapped_resource('items') | ||
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 | ||
{ | ||
'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) }, | ||
'deprecated' => ->(obj) { return :deprecated, GoogleInSpec::Compute::Property::AcceleratorTypeDeprecated.new(obj['deprecated'], to_s) }, | ||
'description' => ->(obj) { return :description, obj['description'] }, | ||
'id' => ->(obj) { return :id, obj['id'] }, | ||
'name' => ->(obj) { return :name, obj['name'] }, | ||
'zone' => ->(obj) { return :zone, obj['zone'] }, | ||
} | ||
end | ||
|
||
# Handles parsing RFC3339 time string | ||
def parse_time_string(time_string) | ||
time_string ? Time.parse(time_string) : nil | ||
end | ||
|
||
private | ||
|
||
def product_url(_ = nil) | ||
'https://compute.googleapis.com/compute/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'projects/{{project}}/zones/{{zone}}/acceleratorTypes' | ||
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
27 changes: 27 additions & 0 deletions
27
test/integration/verify/controls/google_compute_accelerator_type.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,27 @@ | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# 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_compute_accelerator_type resource.' | ||
|
||
gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') | ||
accelerator_type = attribute('accelerator_type', default: null, description: 'The accelerator type') | ||
control 'google_compute_accelerator_type-1.0' do | ||
impact 1.0 | ||
title 'google_compute_accelerator_type resource test' | ||
|
||
describe google_compute_accelerator_type(project: gcp_project_id, zone: 'us-east1-b', name: accelerator_type['name']) do | ||
it { should exist } | ||
it { should be_up } | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
test/integration/verify/controls/google_compute_accelerator_types.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,27 @@ | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# 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_compute_accelerator_types resource.' | ||
|
||
gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') | ||
accelerator_type = attribute('accelerator_type', default: null, description: 'The accelerator type') | ||
control 'google_compute_accelerator_types-1.0' do | ||
impact 1.0 | ||
title 'google_compute_accelerator_types resource test' | ||
|
||
describe google_compute_accelerator_types(project: gcp_project_id, zone: 'us-east1-b') do | ||
it { should exist } | ||
it { should be_up } | ||
end | ||
end |