From 9c6917a46c63cf7c03103d7206956ab0d2cd7d2d Mon Sep 17 00:00:00 2001 From: Samir Anand Date: Wed, 13 Dec 2023 10:19:20 +0530 Subject: [PATCH 1/4] Automatically generated by magic modules for service: apigee and resource: Organizations__apis__revision. This commit includes the following changes: - Singular Resource - Plural Resource - Documentation updates - Terraform configuration - Integration tests Signed-off-by: Samir Anand --- ...google_apigee_organization_api_revision.md | 36 ++++++++ ...oogle_apigee_organization_api_revisions.md | 30 +++++++ ...google_apigee_organization_api_revision.rb | 59 +++++++++++++ ...oogle_apigee_organization_api_revisions.rb | 83 +++++++++++++++++++ ...google_apigee_organization_api_revision.rb | 38 +++++++++ ...oogle_apigee_organization_api_revisions.rb | 31 +++++++ 6 files changed, 277 insertions(+) create mode 100644 docs/resources/google_apigee_organization_api_revision.md create mode 100644 docs/resources/google_apigee_organization_api_revisions.md create mode 100644 libraries/google_apigee_organization_api_revision.rb create mode 100644 libraries/google_apigee_organization_api_revisions.rb create mode 100644 test/integration/verify/controls/google_apigee_organization_api_revision.rb create mode 100644 test/integration/verify/controls/google_apigee_organization_api_revisions.rb diff --git a/docs/resources/google_apigee_organization_api_revision.md b/docs/resources/google_apigee_organization_api_revision.md new file mode 100644 index 000000000..1091e2803 --- /dev/null +++ b/docs/resources/google_apigee_organization_api_revision.md @@ -0,0 +1,36 @@ +--- +title: About the google_apigee_organization_api_revision resource +platform: gcp +--- + +## Syntax +A `google_apigee_organization_api_revision` is used to test a Google OrganizationApiRevision resource + +## Examples +``` +describe google_apigee_organization_api_revision(name: ' value_name') do + it { should exist } + its('content_type') { should cmp 'value_contenttype' } + its('data') { should cmp 'value_data' } + +end + +describe google_apigee_organization_api_revision(name: "does_not_exit") do + it { should_not exist } +end +``` + +## Properties +Properties that can be accessed from the `google_apigee_organization_api_revision` resource: + + + * `extensions`: Application specific response metadata. Must be set in the first response for streaming APIs. + + * `content_type`: The HTTP Content-Type header value specifying the content type of the body. + + * `data`: The HTTP request/response body as raw binary. + + +## GCP Permissions + +Ensure the [Apigee API](https://console.cloud.google.com/apis/library/apigee.googleapis.com/) is enabled for the current project. diff --git a/docs/resources/google_apigee_organization_api_revisions.md b/docs/resources/google_apigee_organization_api_revisions.md new file mode 100644 index 000000000..c625c8f51 --- /dev/null +++ b/docs/resources/google_apigee_organization_api_revisions.md @@ -0,0 +1,30 @@ +--- +title: About the google_apigee_organization_api_revisions resource +platform: gcp +--- + +## Syntax +A `google_apigee_organization_api_revisions` is used to test a Google OrganizationApiRevision resource + +## Examples +``` + describe google_apigee_organization_api_revisions() do + it { should exist } + end +``` + +## Properties +Properties that can be accessed from the `google_apigee_organization_api_revisions` resource: + +See [google_apigee_organization_api_revision.md](google_apigee_organization_api_revision.md) for more detailed information + * `extensions`: an array of `google_apigee_organization_api_revision` extensions + * `content_types`: an array of `google_apigee_organization_api_revision` content_type + * `data`: an array of `google_apigee_organization_api_revision` data + +## 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. diff --git a/libraries/google_apigee_organization_api_revision.rb b/libraries/google_apigee_organization_api_revision.rb new file mode 100644 index 000000000..c7156263d --- /dev/null +++ b/libraries/google_apigee_organization_api_revision.rb @@ -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 ApigeeOrganizationApiRevision < GcpResourceBase + name 'google_apigee_organization_api_revision' + desc 'OrganizationApiRevision' + supports platform: 'gcp' + + attr_reader :params + attr_reader :extensions + attr_reader :content_type + attr_reader :data + + 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 + @extensions = @fetched['extensions'] + @content_type = @fetched['contentType'] + @data = @fetched['data'] + end + + def exists? + !@fetched.nil? + end + + def to_s + "OrganizationApiRevision #{@params[:name]}" + end + + private + + def product_url(_ = nil) + 'https://apigee.googleapis.com/v1/' + end + + def resource_base_url + '{{name}}' + end +end diff --git a/libraries/google_apigee_organization_api_revisions.rb b/libraries/google_apigee_organization_api_revisions.rb new file mode 100644 index 000000000..6a100b245 --- /dev/null +++ b/libraries/google_apigee_organization_api_revisions.rb @@ -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 ApigeeOrganizationApiRevisions < GcpResourceBase + name 'google_apigee_organization_api_revisions' + desc 'OrganizationApiRevision plural resource' + supports platform: 'gcp' + + attr_reader :table + + filter_table_config = FilterTable.create + + filter_table_config.add(:extensions, field: :extensions) + filter_table_config.add(:content_types, field: :content_type) + filter_table_config.add(:data, field: :data) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('organizationApiRevisions') + 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 + { + 'extensions' => ->(obj) { [:extensions, obj['extensions']] }, + 'contentType' => ->(obj) { [:content_type, obj['contentType']] }, + 'data' => ->(obj) { [:data, obj['data']] }, + } + end + + private + + def product_url(_ = nil) + 'https://apigee.googleapis.com/v1/' + end + + def resource_base_url + '' + end +end diff --git a/test/integration/verify/controls/google_apigee_organization_api_revision.rb b/test/integration/verify/controls/google_apigee_organization_api_revision.rb new file mode 100644 index 000000000..9f0be0fda --- /dev/null +++ b/test/integration/verify/controls/google_apigee_organization_api_revision.rb @@ -0,0 +1,38 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_api_revision resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + organization_api_revision = input('organization_api_revision', value: { + "name": "value_name", + "content_type": "value_contenttype", + "data": "value_data" +}, description: 'organization_api_revision description') +control 'google_apigee_organization_api_revision-1.0' do + impact 1.0 + title 'google_apigee_organization_api_revision resource test' + + describe google_apigee_organization_api_revision(name: organization_api_revision['name']) do + it { should exist } + its('content_type') { should cmp organization_api_revision['content_type'] } + its('data') { should cmp organization_api_revision['data'] } + + end + + describe google_apigee_organization_api_revision(name: "does_not_exit") do + it { should_not exist } + end +end diff --git a/test/integration/verify/controls/google_apigee_organization_api_revisions.rb b/test/integration/verify/controls/google_apigee_organization_api_revisions.rb new file mode 100644 index 000000000..767bac7e8 --- /dev/null +++ b/test/integration/verify/controls/google_apigee_organization_api_revisions.rb @@ -0,0 +1,31 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_api_revisions resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + organization_api_revision = input('organization_api_revision', value: { + "name": "value_name", + "content_type": "value_contenttype", + "data": "value_data" +}, description: 'organization_api_revision description') +control 'google_apigee_organization_api_revisions-1.0' do + impact 1.0 + title 'google_apigee_organization_api_revisions resource test' + + describe google_apigee_organization_api_revisions() do + it { should exist } + end +end From 65a7b9d1a359ca16b7f5099fa63d5853220a3fb3 Mon Sep 17 00:00:00 2001 From: Samir <85890442+sa-progress@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:23:22 +0530 Subject: [PATCH 2/4] Manual response parsing and test case update. Signed-off-by: Samir <85890442+sa-progress@users.noreply.github.com> --- libraries/gcp_backend.rb | 3 +++ ...google_apigee_organization_api_revision.rb | 26 ++++++++++++++----- ...oogle_apigee_organization_api_revisions.rb | 24 ++++------------- libraries/google_compute_regions.rb | 1 - 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/libraries/gcp_backend.rb b/libraries/gcp_backend.rb index ca60cd4cb..0ecccf518 100644 --- a/libraries/gcp_backend.rb +++ b/libraries/gcp_backend.rb @@ -238,6 +238,9 @@ def next_page(uri, request_type, token = nil) request_type, ) result = JSON.parse(get_request.send.body) + if result.is_a?(Array) + return result + end next_page_token = result['nextPageToken'] return [result] if next_page_token.nil? diff --git a/libraries/google_apigee_organization_api_revision.rb b/libraries/google_apigee_organization_api_revision.rb index c7156263d..8ea7d5db6 100644 --- a/libraries/google_apigee_organization_api_revision.rb +++ b/libraries/google_apigee_organization_api_revision.rb @@ -22,9 +22,16 @@ class ApigeeOrganizationApiRevision < GcpResourceBase supports platform: 'gcp' attr_reader :params - attr_reader :extensions - attr_reader :content_type - attr_reader :data + attr_reader :description + attr_reader :created_at + attr_reader :configuration_version + attr_reader :policies + attr_reader :entity_meta_data_as_properties + attr_reader :type + attr_reader :proxies + attr_reader :revision + attr_reader :name + attr_reader :last_modified_at def initialize(params) super(params.merge({ use_http_transport: true })) @@ -34,9 +41,16 @@ def initialize(params) end def parse - @extensions = @fetched['extensions'] - @content_type = @fetched['contentType'] - @data = @fetched['data'] + @policies = @fetched['policies'] + @configuration_version = @fetched['configurationVersion'] + @created_at = @fetched['createdAt'] + @description = @fetched['description'] + @entity_meta_data_as_properties = @fetched['entityMetaDataAsProperties'] + @last_modified_at = @fetched['lastModifiedAt'] + @name = @fetched['name'] + @revision = @fetched['revision'] + @proxies = @fetched['proxies'] + @type = @fetched['type'] end def exists? diff --git a/libraries/google_apigee_organization_api_revisions.rb b/libraries/google_apigee_organization_api_revisions.rb index 6a100b245..61bbade29 100644 --- a/libraries/google_apigee_organization_api_revisions.rb +++ b/libraries/google_apigee_organization_api_revisions.rb @@ -37,26 +37,12 @@ def initialize(params = {}) 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 + @connection.fetch_all(product_url, resource_base_url, @params, 'Get') end + def revisions + @table + end def transform(key, value) return transformers[key].call(value) if transformers.key?(key) @@ -78,6 +64,6 @@ def product_url(_ = nil) end def resource_base_url - '' + '{{parent}}/revisions' end end diff --git a/libraries/google_compute_regions.rb b/libraries/google_compute_regions.rb index 5878bc619..049580496 100644 --- a/libraries/google_compute_regions.rb +++ b/libraries/google_compute_regions.rb @@ -58,7 +58,6 @@ def fetch_wrapped_resource(wrap_path) converted.push(hash_with_symbols) end end - converted end From ee194f9ed9f5983bee1bce55a84f77b39d129f3a Mon Sep 17 00:00:00 2001 From: Samir <85890442+sa-progress@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:30:39 +0530 Subject: [PATCH 3/4] Manual response parsing and test case update. Signed-off-by: Samir <85890442+sa-progress@users.noreply.github.com> --- .../configuration/mm-attributes.yml | 6 ++++++ ...google_apigee_organization_api_revision.rb | 19 ++++++++++--------- ...oogle_apigee_organization_api_revisions.rb | 19 +++++++++++-------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/test/integration/configuration/mm-attributes.yml b/test/integration/configuration/mm-attributes.yml index 8c37d5494..cd23a40a4 100644 --- a/test/integration/configuration/mm-attributes.yml +++ b/test/integration/configuration/mm-attributes.yml @@ -621,3 +621,9 @@ vpn_gateway: self_link : "value_selflink" label_fingerprint : "value_labelfingerprint" stack_type : "IPV4_ONLY" + +organization_api_revision: + name: "organizations/ppradhan/apis/helloworld/revisions/1" + parent: "organizations/ppradhan/apis/helloworld" + content_type: "Application" + revision: 1 diff --git a/test/integration/verify/controls/google_apigee_organization_api_revision.rb b/test/integration/verify/controls/google_apigee_organization_api_revision.rb index 9f0be0fda..2d199c01e 100644 --- a/test/integration/verify/controls/google_apigee_organization_api_revision.rb +++ b/test/integration/verify/controls/google_apigee_organization_api_revision.rb @@ -16,23 +16,24 @@ gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') - organization_api_revision = input('organization_api_revision', value: { - "name": "value_name", - "content_type": "value_contenttype", - "data": "value_data" +organization_api_revision = input('organization_api_revision', value: { + "name": "organizations/{organization}/apis/{api}/revisions/{revision}", + "content_type": "Application", + "data": "value_data", + "revision": 1, }, description: 'organization_api_revision description') control 'google_apigee_organization_api_revision-1.0' do impact 1.0 title 'google_apigee_organization_api_revision resource test' describe google_apigee_organization_api_revision(name: organization_api_revision['name']) do - it { should exist } - its('content_type') { should cmp organization_api_revision['content_type'] } - its('data') { should cmp organization_api_revision['data'] } - + it { should exist } + its('type') { should cmp organization_api_revision['content_type'] } + its('revision') { should cmp organization_api_revision['revision'] } end describe google_apigee_organization_api_revision(name: "does_not_exit") do - it { should_not exist } + it { should_not exist } end end + diff --git a/test/integration/verify/controls/google_apigee_organization_api_revisions.rb b/test/integration/verify/controls/google_apigee_organization_api_revisions.rb index 767bac7e8..101d48952 100644 --- a/test/integration/verify/controls/google_apigee_organization_api_revisions.rb +++ b/test/integration/verify/controls/google_apigee_organization_api_revisions.rb @@ -12,20 +12,23 @@ # # ---------------------------------------------------------------------------- -title 'Test GCP google_apigee_organization_api_revisions resource.' - +# title 'Test GCP google_apigee_organization_api_revisions resource.' +# gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') - organization_api_revision = input('organization_api_revision', value: { - "name": "value_name", - "content_type": "value_contenttype", - "data": "value_data" +organization_api_revision = input('organization_api_revision', value: { + "parent": "organizations/ppradhan/apis/helloworld", + "content_type": "Application", + "data": "value_data", + "revision": 1, }, description: 'organization_api_revision description') + control 'google_apigee_organization_api_revisions-1.0' do impact 1.0 title 'google_apigee_organization_api_revisions resource test' - describe google_apigee_organization_api_revisions() do + describe google_apigee_organization_api_revisions(parent: organization_api_revision['parent']) do it { should exist } - end + its('revisions') { should include "1" } + end end From df3c962f2fc0b58197589974283100ce0df39e66 Mon Sep 17 00:00:00 2001 From: Samir <85890442+sa-progress@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:07:10 +0530 Subject: [PATCH 4/4] Test cases added. Signed-off-by: Samir <85890442+sa-progress@users.noreply.github.com> --- test/integration/configuration/mm-attributes.yml | 1 + .../google_apigee_organization_api_revisions.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/test/integration/configuration/mm-attributes.yml b/test/integration/configuration/mm-attributes.yml index cd23a40a4..97dcf7853 100644 --- a/test/integration/configuration/mm-attributes.yml +++ b/test/integration/configuration/mm-attributes.yml @@ -627,3 +627,4 @@ organization_api_revision: parent: "organizations/ppradhan/apis/helloworld" content_type: "Application" revision: 1 + api: "helloworld" diff --git a/test/integration/verify/controls/google_apigee_organization_api_revisions.rb b/test/integration/verify/controls/google_apigee_organization_api_revisions.rb index 101d48952..1159b28af 100644 --- a/test/integration/verify/controls/google_apigee_organization_api_revisions.rb +++ b/test/integration/verify/controls/google_apigee_organization_api_revisions.rb @@ -18,9 +18,11 @@ organization_api_revision = input('organization_api_revision', value: { "parent": "organizations/ppradhan/apis/helloworld", + "name": "organizations/{organization}/apis/{api}/revisions/{revision}", "content_type": "Application", "data": "value_data", "revision": 1, + "api": "helloworld" }, description: 'organization_api_revision description') control 'google_apigee_organization_api_revisions-1.0' do @@ -31,4 +33,12 @@ it { should exist } its('revisions') { should include "1" } end + + google_apigee_organization_api_revisions(parent: organization_api_revision['parent']).revisions.each do |rev| + describe google_apigee_organization_api_revision(name: "organizations/#{gcp_project_id}/apis/#{api}/revisions/#{rev}") do + it { should exist } + its('type') { should cmp organization_api_revision['content_type'] } + its('revision') { should cmp organization_api_revision['revision'] } + end + end end