-
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 #653 from inspec/CHEF-12251-v2-MAGIC-MODULE-apigee…
…_v1-Organizations__instances__attachment CHEF-12251-v2-MAGIC-MODULE-apigee_v1-Organizations__instances__attachment - Resource Implementation
- Loading branch information
Showing
9 changed files
with
351 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
54 changes: 54 additions & 0 deletions
54
docs/resources/google_apigee_organization_instance_attachment.md
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,54 @@ | ||
+++ | ||
|
||
title = "google_apigee_organization_instance_attachment Resource" | ||
platform = "gcp" | ||
draft = false | ||
gh_repo = "inspec-gcp" | ||
|
||
|
||
[menu.inspec] | ||
|
||
title = "google_apigee_organization_instance_attachment" | ||
identifier = "inspec/resources/gcp/google_apigee_organization_instance_attachment Resource" | ||
parent = "inspec/resources/gcp" | ||
+++ | ||
|
||
Use the `google_apigee_organization_instance_attachment` InSpec audit resource to test the properties of a test a Google OrganizationInstanceAttachment. | ||
|
||
## Installation | ||
{{% inspec_gcp_install %}} | ||
|
||
## Syntax | ||
A `google_apigee_organization_instance_attachment` is used to test a Google OrganizationInstanceAttachment resource | ||
|
||
## Examples | ||
``` | ||
describe google_apigee_organization_instance_attachment(parent:'value_parent', name:'value_name') do | ||
it { should exist } | ||
its('name') { should cmp 'value_name' } | ||
its('environment') { should cmp 'value_environment' } | ||
its('created_at') { should cmp 'value_createdat' } | ||
end | ||
describe google_apigee_organization_instance_attachment(parent:'value_parent',name: "does-not-exit") do | ||
it { should_not exist } | ||
end | ||
``` | ||
|
||
## Parameters | ||
Properties that can be accessed from the `google_apigee_organization_instance_attachment` resource: | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_apigee_organization_instance_attachment` resource: | ||
|
||
|
||
* `name`: Output only. ID of the attachment. | ||
|
||
* `environment`: ID of the attached environment. | ||
|
||
* `created_at`: Output only. Time the attachment was created in 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. |
55 changes: 55 additions & 0 deletions
55
docs/resources/google_apigee_organization_instance_attachments.md
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,55 @@ | ||
+++ | ||
|
||
title = "google_apigee_organization_instance_attachments Resource" | ||
platform = "gcp" | ||
draft = false | ||
gh_repo = "inspec-gcp" | ||
|
||
|
||
[menu.inspec] | ||
|
||
title = "google_apigee_organization_instance_attachments" | ||
identifier = "inspec/resources/gcp/google_apigee_organization_instance_attachments Resource" | ||
parent = "inspec/resources/gcp" | ||
+++ | ||
|
||
Use the `google_apigee_organization_instance_attachments` InSpec audit resource to test the properties of a test a Google OrganizationInstanceAttachment. | ||
|
||
## Installation | ||
{{% inspec_gcp_install %}} | ||
|
||
## Syntax | ||
A `google_apigee_organization_instance_attachments` is used to test a Google OrganizationInstanceAttachment resource | ||
|
||
## Examples | ||
``` | ||
describe google_apigee_organization_instance_attachments(parent: 'value_parent') do | ||
it { should exist } | ||
its('names') { should include 'value_name' } | ||
its('environments') { should include 'value_environment' } | ||
its('created_ats') { should include 'value_createdat' } | ||
end | ||
``` | ||
|
||
## Parameters | ||
Properties that can be accessed from the `google_apigee_organization_instance_attachments` resource: | ||
|
||
See [google_apigee_organization_instance_attachment.md](google_apigee_organization_instance_attachment.md) for more detailed information | ||
* `names`: an array of `google_apigee_organization_instance_attachment` name | ||
* `environments`: an array of `google_apigee_organization_instance_attachment` environment | ||
* `created_ats`: an array of `google_apigee_organization_instance_attachment` created_at | ||
## Properties | ||
Properties that can be accessed from the `google_apigee_organization_instance_attachments` resource: | ||
|
||
See [google_apigee_organization_instance_attachment.md](google_apigee_organization_instance_attachment.md) for more detailed information | ||
* `names`: an array of `google_apigee_organization_instance_attachment` name | ||
* `environments`: an array of `google_apigee_organization_instance_attachment` environment | ||
* `created_ats`: an array of `google_apigee_organization_instance_attachment` 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. |
59 changes: 59 additions & 0 deletions
59
libraries/google_apigee_organization_instance_attachment.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,59 @@ | ||
# 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 ApigeeOrganizationInstanceAttachment < GcpResourceBase | ||
name 'google_apigee_organization_instance_attachment' | ||
desc 'OrganizationInstanceAttachment' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :params | ||
attr_reader :name | ||
attr_reader :environment | ||
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'] | ||
@environment = @fetched['environment'] | ||
@created_at = @fetched['createdAt'] | ||
end | ||
|
||
def exists? | ||
!@fetched.nil? | ||
end | ||
|
||
def to_s | ||
"OrganizationInstanceAttachment #{@params[:name]}" | ||
end | ||
|
||
private | ||
|
||
def product_url(_ = nil) | ||
'https://apigee.googleapis.com/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'{{parent}}/attachments/{{name}}' | ||
end | ||
end |
83 changes: 83 additions & 0 deletions
83
libraries/google_apigee_organization_instance_attachments.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,83 @@ | ||
# 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 ApigeeOrganizationInstanceAttachments < GcpResourceBase | ||
name 'google_apigee_organization_instance_attachments' | ||
desc 'OrganizationInstanceAttachment plural resource' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :table | ||
|
||
filter_table_config = FilterTable.create | ||
|
||
filter_table_config.add(:names, field: :name) | ||
filter_table_config.add(:environments, field: :environment) | ||
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('attachments') | ||
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']] }, | ||
'environment' => ->(obj) { [:environment, obj['environment']] }, | ||
'createdAt' => ->(obj) { [:created_at, obj['createdAt']] }, | ||
} | ||
end | ||
|
||
private | ||
|
||
def product_url(_ = nil) | ||
'https://apigee.googleapis.com/v1/' | ||
end | ||
|
||
def resource_base_url | ||
'{{parent}}/attachments' | ||
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
40 changes: 40 additions & 0 deletions
40
test/integration/verify/controls/google_apigee_organization_instance_attachment.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,40 @@ | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** 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_instance_attachment resource.' | ||
|
||
gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') | ||
|
||
organization_instance_attachment = input('organization_instance_attachment', value: { | ||
"name": "c4452279-f4dd-473c-b50d-de21bec8147b", | ||
"parent": "organizations/ppradhan/instances/us-central1", | ||
"environment": "inspec-test-env", | ||
"created_at": "1728297911815" | ||
}, description: 'organization_instance_attachment description') | ||
control 'google_apigee_organization_instance_attachment-1.0' do | ||
impact 1.0 | ||
title 'google_apigee_organization_instance_attachment resource test' | ||
|
||
describe google_apigee_organization_instance_attachment(name: organization_instance_attachment['name']) do | ||
it { should exist } | ||
its('name') { should cmp organization_instance_attachment['name'] } | ||
its('environment') { should cmp organization_instance_attachment['environment'] } | ||
its('created_at') { should cmp organization_instance_attachment['created_at'] } | ||
|
||
end | ||
|
||
describe google_apigee_organization_instance_attachment(name: "does_not_exit") do | ||
it { should_not exist } | ||
end | ||
end |
35 changes: 35 additions & 0 deletions
35
test/integration/verify/controls/google_apigee_organization_instance_attachments.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,35 @@ | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** 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_instance_attachments resource.' | ||
|
||
gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') | ||
|
||
organization_instance_attachment = input('organization_instance_attachment', value: { | ||
"name": "c4452279-f4dd-473c-b50d-de21bec8147b", | ||
"parent": "organizations/ppradhan/instances/us-central1", | ||
"environment": "inspec-test-env", | ||
"created_at": "1728297911815" | ||
}, description: 'organization_instance_attachment description') | ||
control 'google_apigee_organization_instance_attachments-1.0' do | ||
impact 1.0 | ||
title 'google_apigee_organization_instance_attachments resource test' | ||
|
||
describe google_apigee_organization_instance_attachments(parent: organization_instance_attachment['parent']) do | ||
it { should exist } | ||
its('name') { should include organization_instance_attachment['name'] } | ||
its('environment') { should include organization_instance_attachment['environment'] } | ||
its('created_at') { should include organization_instance_attachment['created_at'] } | ||
end | ||
end |