-
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 #539 from inspec/CHEF-7356-MAGIC-MODULE-apigee-Org…
…anizations__envgroup CHEF-7356-MAGIC-MODULE-apigee-Organizations__envgroup - Resource Implementation
- Loading branch information
Showing
9 changed files
with
333 additions
and
0 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
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_apigee_organization_envgroup resource | ||
platform: gcp | ||
--- | ||
|
||
## Syntax | ||
|
||
A `google_apigee_organization_envgroup` is used to test a Google OrganizationEnvgroup resource | ||
|
||
## Examples | ||
|
||
``` | ||
describe google_apigee_organization_envgroup(name: ' value_name') do | ||
it { should exist } | ||
its('name') { should cmp 'value_name' } | ||
its('hostnames') { should include 'value_hostname' } | ||
its('last_modified_at') { should cmp 'value_lastmodifiedat' } | ||
its('state') { should cmp 'value_state' } | ||
its('created_at') { should cmp 'value_createdat' } | ||
end | ||
describe google_apigee_organization_envgroup(name: "does_not_exit") do | ||
it { should_not exist } | ||
end | ||
``` | ||
|
||
## Properties | ||
|
||
Properties that can be accessed from the `google_apigee_organization_envgroup` resource: | ||
|
||
* `name`: ID of the environment group. | ||
|
||
* `last_modified_at`: The time at which the environment group was last updated as milliseconds since epoch. | ||
|
||
* `hostnames`: Host names for this environment group. | ||
|
||
* `state`: State of the environment group. Values other than ACTIVE means the resource is not ready to use. | ||
|
||
Possible values: | ||
* STATE_UNSPECIFIED | ||
* CREATING | ||
* ACTIVE | ||
* DELETING | ||
* UPDATING | ||
|
||
* `created_at`: The time at which the environment group was created as milliseconds since epoch. | ||
|
||
## GCP Permissions | ||
|
||
Ensure the [Apigee API](https://console.cloud.google.com/apis/library/apigee.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,36 @@ | ||
--- | ||
title: About the google_apigee_organization_envgroups resource | ||
platform: gcp | ||
--- | ||
|
||
## Syntax | ||
|
||
A `google_apigee_organization_envgroups` is used to test a Google OrganizationEnvgroup resource | ||
|
||
## Examples | ||
|
||
``` | ||
describe google_apigee_organization_envgroups(parent: 'value_parent') do | ||
it { should exist } | ||
end | ||
``` | ||
|
||
## Properties | ||
|
||
Properties that can be accessed from the `google_apigee_organization_envgroups` resource: | ||
|
||
See [google_apigee_organization_envgroup.md](google_apigee_organization_envgroup.md) for more detailed information | ||
* `names`: an array of `google_apigee_organization_envgroup` name | ||
* `last_modified_ats`: an array of `google_apigee_organization_envgroup` last_modified_at | ||
* `hostnames`: an array of `google_apigee_organization_envgroup` hostnames | ||
* `states`: an array of `google_apigee_organization_envgroup` state | ||
* `created_ats`: an array of `google_apigee_organization_envgroup` created_at | ||
|
||
## 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 [Apigee API](https://console.cloud.google.com/apis/library/apigee.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,63 @@ | ||
# 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' | ||
|
||
# A provider to manage Apigee resources. | ||
class ApigeeOrganizationEnvgroup < GcpResourceBase | ||
name 'google_apigee_organization_envgroup' | ||
desc 'OrganizationEnvgroup' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :params | ||
attr_reader :name | ||
attr_reader :last_modified_at | ||
attr_reader :hostnames | ||
attr_reader :state | ||
attr_reader :created_at | ||
|
||
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 | ||
@name = @fetched['name'] | ||
@last_modified_at = @fetched['lastModifiedAt'] | ||
@hostnames = @fetched['hostnames'] | ||
@state = @fetched['state'] | ||
@created_at = @fetched['createdAt'] | ||
end | ||
|
||
def exists? | ||
!@fetched.nil? | ||
end | ||
|
||
def to_s | ||
"OrganizationEnvgroup #{@params[:name]}" | ||
end | ||
|
||
private | ||
|
||
def product_url(_ = nil) | ||
'https://apigee.googleapis.com/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'{{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,87 @@ | ||
# 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 ApigeeOrganizationEnvgroups < GcpResourceBase | ||
name 'google_apigee_organization_envgroups' | ||
desc 'OrganizationEnvgroup plural resource' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :table | ||
|
||
filter_table_config = FilterTable.create | ||
|
||
filter_table_config.add(:names, field: :name) | ||
filter_table_config.add(:last_modified_ats, field: :last_modified_at) | ||
filter_table_config.add(:hostnames, field: :hostnames) | ||
filter_table_config.add(:states, field: :state) | ||
filter_table_config.add(:created_ats, field: :created_at) | ||
|
||
filter_table_config.connect(self, :table) | ||
|
||
def initialize(params = {}) | ||
super(params.merge({ use_http_transport: true })) | ||
@params = params | ||
@table = fetch_wrapped_resource('environmentGroups') | ||
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) { [:name, obj['name']] }, | ||
'lastModifiedAt' => ->(obj) { [:last_modified_at, obj['lastModifiedAt']] }, | ||
'hostnames' => ->(obj) { [:hostnames, obj['hostnames']] }, | ||
'state' => ->(obj) { [:state, obj['state']] }, | ||
'createdAt' => ->(obj) { [:created_at, obj['createdAt']] }, | ||
} | ||
end | ||
|
||
private | ||
|
||
def product_url(_ = nil) | ||
'https://apigee.googleapis.com/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'{{parent}}/envgroups' | ||
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
39 changes: 39 additions & 0 deletions
39
test/integration/verify/controls/google_apigee_organization_envgroup.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,39 @@ | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** 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_apigee_organization_envgroup resource.' | ||
|
||
organization_envgroup = input('organization_envgroup', value: { | ||
"name": "test-env-group", | ||
"parent": "organizations/ppradhan/envgroups", | ||
"hostname": "34.95.97.227.nip.io", | ||
"state": "ACTIVE", | ||
"created_at": "1698227493454" | ||
}, description: 'organization_envgroup description') | ||
control 'google_apigee_organization_envgroup-1.0' do | ||
impact 1.0 | ||
title 'google_apigee_organization_envgroup resource test' | ||
|
||
describe google_apigee_organization_envgroup(name: "#{organization_envgroup['parent']}/#{organization_envgroup['name']}") do | ||
it { should exist } | ||
its('name') { should cmp organization_envgroup['name'] } | ||
its('hostnames') { should include organization_envgroup['hostname'] } | ||
its('state') { should cmp organization_envgroup['state'] } | ||
its('created_at') { should cmp organization_envgroup['created_at'] } | ||
end | ||
|
||
describe google_apigee_organization_envgroup(name: "does_not_exit") do | ||
it { should_not exist } | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
test/integration/verify/controls/google_apigee_organization_envgroups.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,39 @@ | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** 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_apigee_organization_envgroups resource.' | ||
|
||
organization_envgroup = input("organization_envgroup", value: { | ||
"name": "test-env-group", | ||
"parent": "organizations/ppradhan", | ||
"hostname": "34.95.97.227.nip.io", | ||
"state": "ACTIVE" | ||
}, description: "organization_envgroup description") | ||
|
||
control 'google_apigee_organization_envgroups-1.0' do | ||
impact 1.0 | ||
title 'google_apigee_organization_envgroups resource test' | ||
|
||
describe google_apigee_organization_envgroups(parent: organization_envgroup["parent"]) do | ||
it { should exist } | ||
its("names") { should include organization_envgroup["name"] } | ||
end | ||
|
||
describe google_apigee_organization_envgroups(parent: organization_envgroup["parent"]).where(name: organization_envgroup["name"]) do | ||
it { should exist } | ||
its("names") { should include organization_envgroup["name"] } | ||
its("hostnames") { should include [organization_envgroup["hostname"]] } | ||
its("states") { should include organization_envgroup["state"] } | ||
end | ||
end |