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.
GCP Inspec for Standard Application Version
Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
52b376f
commit cb860bf
Showing
9 changed files
with
337 additions
and
2 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,34 @@ | ||
--- | ||
title: About the google_appengine_standard_app_version resource | ||
platform: gcp | ||
--- | ||
|
||
## Syntax | ||
A `google_appengine_standard_app_version` is used to test a Google StandardAppVersion resource | ||
|
||
## Examples | ||
``` | ||
describe google_appengine_standard_app_version(project: 'chef-gcp-inspec', location: 'europe-west2', version_id: 'v2', service: 'default') do | ||
it { should exist } | ||
its('version_id') { should eq 'v2' } | ||
its('runtime') { should eq 'nodejs10' } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_appengine_standard_app_version` resource: | ||
|
||
* `name`: Full path to the Version resource in the API. Example, "v1". | ||
|
||
* `version_id`: Relative name of the version within the service. For example, `v1`. Version names can contain only lowercase letters, numbers, or hyphens. Reserved names,"default", "latest", and any name with the prefix "ah-". | ||
|
||
* `runtime`: Desired runtime. Example python27. | ||
|
||
* `threadsafe`: Whether multiple requests can be dispatched to this version at once. | ||
|
||
|
||
|
||
## GCP Permissions | ||
|
||
Ensure the [App Engine Admin API](https://console.cloud.google.com/apis/library/appengine.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_appengine_standard_app_versions resource | ||
platform: gcp | ||
--- | ||
|
||
## Syntax | ||
A `google_appengine_standard_app_versions` is used to test a Google StandardAppVersion resource | ||
|
||
## Examples | ||
``` | ||
describe google_appengine_standard_app_versions(project: 'chef-gcp-inspec', location: 'europe-west2',service: 'default') do | ||
its('runtimes') { should include 'nodejs10' } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_appengine_standard_app_versions` resource: | ||
|
||
See [google_appengine_standard_app_version.md](google_appengine_standard_app_version.md) for more detailed information | ||
* `names`: an array of `google_appengine_standard_app_version` name | ||
* `version_ids`: an array of `google_appengine_standard_app_version` version_id | ||
* `runtimes`: an array of `google_appengine_standard_app_version` runtime | ||
* `threadsaves`: an array of `google_appengine_standard_app_version` threadsafe | ||
|
||
## 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 [App Engine Admin API](https://console.cloud.google.com/apis/library/appengine.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,66 @@ | ||
# 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 App Engine resources. | ||
class StandardAppVersion < GcpResourceBase | ||
name 'google_appengine_standard_app_version' | ||
desc 'StandardAppVersion' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :params | ||
attr_reader :name | ||
attr_reader :version_id | ||
attr_reader :runtime | ||
attr_reader :threadsafe | ||
|
||
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'] | ||
@version_id = @fetched['id'] | ||
@runtime = @fetched['runtime'] | ||
@threadsafe = @fetched['threadsafe'] | ||
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 | ||
"StandardAppVersion #{@params[:version_id]}" | ||
end | ||
|
||
private | ||
|
||
def product_url | ||
'https://appengine.googleapis.com/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'apps/{{project}}/services/{{service}}/versions/{{version_id}}' | ||
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,90 @@ | ||
# 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 StandardAppVersions < GcpResourceBase | ||
name 'google_appengine_standard_app_versions' | ||
desc 'StandardAppVersion plural resource' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :table | ||
|
||
filter_table_config = FilterTable.create | ||
|
||
filter_table_config.add(:names, field: :name) | ||
filter_table_config.add(:version_ids, field: :version_id) | ||
filter_table_config.add(:runtimes, field: :runtime) | ||
filter_table_config.add(:threadsaves, field: :threadsafe) | ||
|
||
filter_table_config.connect(self, :table) | ||
|
||
def initialize(params = {}) | ||
super(params.merge({ use_http_transport: true })) | ||
@params = params | ||
@table = fetch_wrapped_resource('versions') | ||
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'] }, | ||
'id' => ->(obj) { return :version_id, obj['id'] }, | ||
'runtime' => ->(obj) { return :runtime, obj['runtime'] }, | ||
'threadsafe' => ->(obj) { return :threadsafe, obj['threadsafe'] }, | ||
} | ||
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://appengine.googleapis.com/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'apps/{{project}}/services/{{service}}/versions' | ||
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
Binary file not shown.
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
36 changes: 36 additions & 0 deletions
36
test/integration/verify/controls/google_appengine_standard_app_version.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,36 @@ | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** 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. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
|
||
title 'Test GCP google_appengine_standard_app_version resource.' | ||
|
||
gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') | ||
gcp_location = attribute(:gcp_location, default: 'gcp_location', description: 'The GCP project location.') | ||
standardappversion = attribute('standardappversion', default: { | ||
"version_id": "v2", | ||
"service": "default", | ||
"runtime": "nodejs10", | ||
"entrypoint": "node ./app.js", | ||
"port": "8080" | ||
}, description: 'Cloud App Engine definition') | ||
control 'google_appengine_standard_app_version-1.0' do | ||
impact 1.0 | ||
title 'google_appengine_standard_app_version resource test' | ||
|
||
|
||
describe google_appengine_standard_app_version(project: gcp_project_id, location: gcp_location, version_id: standardappversion['version_id'], service: standardappversion['service']) do | ||
it { should exist } | ||
its('version_id') { should eq standardappversion['version_id'] } | ||
its('runtime') { should eq standardappversion['runtime'] } | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
test/integration/verify/controls/google_appengine_standard_app_versions.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,34 @@ | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** 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. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
|
||
title 'Test GCP google_appengine_standard_app_versions resource.' | ||
|
||
gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') | ||
gcp_location = attribute(:gcp_location, default: 'gcp_location', description: 'The GCP project location.') | ||
standardappversion = attribute('standardappversion', default: { | ||
"version_id": "v2", | ||
"service": "default", | ||
"runtime": "nodejs10", | ||
"entrypoint": "node ./app.js", | ||
"port": "8080" | ||
}, description: 'Cloud App Engine definition') | ||
control 'google_appengine_standard_app_versions-1.0' do | ||
impact 1.0 | ||
title 'google_appengine_standard_app_versions resource test' | ||
|
||
|
||
describe google_appengine_standard_app_versions(project: gcp_project_id, location: gcp_location,service: standardappversion['service']) do | ||
its('runtimes') { should include standardappversion['runtime'] } | ||
end | ||
end |