diff --git a/docs/resources/google_apigee_organization_api.md b/docs/resources/google_apigee_organization_api.md new file mode 100644 index 000000000..d7ad9462b --- /dev/null +++ b/docs/resources/google_apigee_organization_api.md @@ -0,0 +1,57 @@ +--- +title: About the google_apigee_organization_api resource +platform: gcp +--- + +## Syntax +A `google_apigee_organization_api` is used to test a Google OrganizationApi resource + +## Examples +``` +describe google_apigee_organization_api(parent: ' value_parent', name: ' value_name') do + it { should exist } + its('latest_revision_id') { should cmp 'value_latestrevisionid' } + its('api_proxy_type') { should cmp 'value_apiproxytype' } + its('name') { should cmp 'value_name' } + +end + +describe google_apigee_organization_api(parent: ' value_parent', name: "does_not_exit") do + it { should_not exist } +end +``` + +## Properties +Properties that can be accessed from the `google_apigee_organization_api` resource: + + + * `revision`: Output only. List of revisions defined for the API proxy. + + * `latest_revision_id`: Output only. The id of the most recently created revision for this api proxy. + + * `meta_data`: Metadata common to many entities in this API. + + * `last_modified_at`: Time at which the API proxy was most recently modified, in milliseconds since epoch. + + * `created_at`: Time at which the API proxy was created, in milliseconds since epoch. + + * `sub_type`: The type of entity described + + * `api_proxy_type`: Output only. The type of the API proxy. + Possible values: + * API_PROXY_TYPE_UNSPECIFIED + * PROGRAMMABLE + * CONFIGURABLE + + * `read_only`: Output only. Whether this proxy is read-only. A read-only proxy cannot have new revisions created through calls to CreateApiProxyRevision. A proxy is read-only if it was generated by an archive. + + * `labels`: User labels applied to this API Proxy. + + * `additional_properties`: + + * `name`: Output only. Name of the API proxy. + + +## 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_apis.md b/docs/resources/google_apigee_organization_apis.md new file mode 100644 index 000000000..a5cbbe8cf --- /dev/null +++ b/docs/resources/google_apigee_organization_apis.md @@ -0,0 +1,34 @@ +--- +title: About the google_apigee_organization_apis resource +platform: gcp +--- + +## Syntax +A `google_apigee_organization_apis` is used to test a Google OrganizationApi resource + +## Examples +``` + describe google_apigee_organization_apis(parent: ' value_parent') do + it { should exist } + end +``` + +## Properties +Properties that can be accessed from the `google_apigee_organization_apis` resource: + +See [google_apigee_organization_api.md](google_apigee_organization_api.md) for more detailed information + * `revisions`: an array of `google_apigee_organization_api` revision + * `latest_revision_ids`: an array of `google_apigee_organization_api` latest_revision_id + * `meta_data`: an array of `google_apigee_organization_api` meta_data + * `api_proxy_types`: an array of `google_apigee_organization_api` api_proxy_type + * `read_onlies`: an array of `google_apigee_organization_api` read_only + * `labels`: an array of `google_apigee_organization_api` labels + * `names`: an array of `google_apigee_organization_api` name + +## 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/property/organizationapi_labels.rb b/libraries/google/apigee/property/organizationapi_labels.rb new file mode 100644 index 000000000..0cef0a987 --- /dev/null +++ b/libraries/google/apigee/property/organizationapi_labels.rb @@ -0,0 +1,34 @@ +# 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 Apigee + module Property + class OrganizationApiLabels + attr_reader :additional_properties + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @additional_properties = args['additionalProperties'] + end + + def to_s + "#{@parent_identifier} OrganizationApiLabels" + end + end + end + end +end diff --git a/libraries/google/apigee/property/organizationapi_meta_data.rb b/libraries/google/apigee/property/organizationapi_meta_data.rb new file mode 100644 index 000000000..df380f47b --- /dev/null +++ b/libraries/google/apigee/property/organizationapi_meta_data.rb @@ -0,0 +1,40 @@ +# 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 Apigee + module Property + class OrganizationApiMetaData + attr_reader :last_modified_at + + attr_reader :created_at + + attr_reader :sub_type + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @last_modified_at = args['lastModifiedAt'] + @created_at = args['createdAt'] + @sub_type = args['subType'] + end + + def to_s + "#{@parent_identifier} OrganizationApiMetaData" + end + end + end + end +end diff --git a/libraries/google_apigee_organization_api.rb b/libraries/google_apigee_organization_api.rb new file mode 100644 index 000000000..9959d886d --- /dev/null +++ b/libraries/google_apigee_organization_api.rb @@ -0,0 +1,69 @@ +# 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/apigee/property/organizationapi_labels' +require 'google/apigee/property/organizationapi_meta_data' + +# A provider to manage Apigee resources. +class ApigeeOrganizationApi < GcpResourceBase + name 'google_apigee_organization_api' + desc 'OrganizationApi' + supports platform: 'gcp' + + attr_reader :params + attr_reader :revision + attr_reader :latest_revision_id + attr_reader :meta_data + attr_reader :api_proxy_type + attr_reader :read_only + attr_reader :labels + attr_reader :name + + 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 + @revision = @fetched['revision'] + @latest_revision_id = @fetched['latestRevisionId'] + @meta_data = GoogleInSpec::Apigee::Property::OrganizationApiMetaData.new(@fetched['metaData'], to_s) + @api_proxy_type = @fetched['apiProxyType'] + @read_only = @fetched['readOnly'] + @labels = GoogleInSpec::Apigee::Property::OrganizationApiLabels.new(@fetched['labels'], to_s) + @name = @fetched['name'] + end + + def exists? + !@fetched.nil? + end + + def to_s + "OrganizationApi #{@params[:name]}" + end + + private + + def product_url(_ = nil) + 'https://apigee.googleapis.com/v1/' + end + + def resource_base_url + '{{parent}}/apis/{{name}}' + end +end diff --git a/libraries/google_apigee_organization_apis.rb b/libraries/google_apigee_organization_apis.rb new file mode 100644 index 000000000..92199c7fa --- /dev/null +++ b/libraries/google_apigee_organization_apis.rb @@ -0,0 +1,91 @@ +# 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 ApigeeOrganizationApis < GcpResourceBase + name 'google_apigee_organization_apis' + desc 'OrganizationApi plural resource' + supports platform: 'gcp' + + attr_reader :table + + filter_table_config = FilterTable.create + + filter_table_config.add(:revisions, field: :revision) + filter_table_config.add(:latest_revision_ids, field: :latest_revision_id) + filter_table_config.add(:meta_data, field: :meta_data) + filter_table_config.add(:api_proxy_types, field: :api_proxy_type) + filter_table_config.add(:read_onlies, field: :read_only) + filter_table_config.add(:labels, field: :labels) + filter_table_config.add(:names, field: :name) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('proxies') + 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 + { + 'revision' => ->(obj) { [:revision, obj['revision']] }, + 'latestRevisionId' => ->(obj) { [:latest_revision_id, obj['latestRevisionId']] }, + 'metaData' => ->(obj) { [:meta_data, GoogleInSpec::Apigee::Property::OrganizationApiMetaData.new(obj['metaData'], to_s)] }, + 'apiProxyType' => ->(obj) { [:api_proxy_type, obj['apiProxyType']] }, + 'readOnly' => ->(obj) { [:read_only, obj['readOnly']] }, + 'labels' => ->(obj) { [:labels, GoogleInSpec::Apigee::Property::OrganizationApiLabels.new(obj['labels'], to_s)] }, + 'name' => ->(obj) { [:name, obj['name']] }, + } + end + + private + + def product_url(_ = nil) + 'https://apigee.googleapis.com/v1/' + end + + def resource_base_url + '{{parent}}/apis' + end +end diff --git a/test/integration/configuration/mm-attributes.yml b/test/integration/configuration/mm-attributes.yml index 8c37d5494..cd608f800 100644 --- a/test/integration/configuration/mm-attributes.yml +++ b/test/integration/configuration/mm-attributes.yml @@ -621,3 +621,8 @@ vpn_gateway: self_link : "value_selflink" label_fingerprint : "value_labelfingerprint" stack_type : "IPV4_ONLY" + +apigee_organization_apis: + name : "firstproxy", + parent : "organizations/ppradhan", + api_proxy_type : "PROGRAMMABLE" diff --git a/test/integration/verify/controls/google_apigee_organization_api.rb b/test/integration/verify/controls/google_apigee_organization_api.rb new file mode 100644 index 000000000..2b6ab89df --- /dev/null +++ b/test/integration/verify/controls/google_apigee_organization_api.rb @@ -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_api resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + organization_api = input('organization_api', value: { + "name": "firstproxy", + "parent": "organizations/ppradhan", + "latest_revision_id": "value_latestrevisionid", + "api_proxy_type": "PROGRAMMABLE" +}, description: 'organization_api description') +control 'google_apigee_organization_api-1.0' do + impact 1.0 + title 'google_apigee_organization_api resource test' + + describe google_apigee_organization_api(parent: organization_api['parent'],name: organization_api['name']) do + it { should exist } + its('latest_revision_id') { should cmp organization_api['latest_revision_id'] } + its('api_proxy_type') { should cmp organization_api['api_proxy_type'] } + its('name') { should cmp organization_api['name'] } + end + + describe google_apigee_organization_api(parent: organization_api['parent'],name: "does_not_exit") do + it { should_not exist } + end +end diff --git a/test/integration/verify/controls/google_apigee_organization_apis.rb b/test/integration/verify/controls/google_apigee_organization_apis.rb new file mode 100644 index 000000000..7b051f00e --- /dev/null +++ b/test/integration/verify/controls/google_apigee_organization_apis.rb @@ -0,0 +1,32 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_apis resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + organization_api = input('organization_api', value: { + "name": "firstproxy", + "parent": "organizations/ppradhan", + "latest_revision_id": "value_latestrevisionid", + "api_proxy_type": "PROGRAMMABLE" +}, description: 'organization_api description') +control 'google_apigee_organization_apis-1.0' do + impact 1.0 + title 'google_apigee_organization_apis resource test' + + describe google_apigee_organization_apis(parent: organization_api['parent']) do + it { should exist } + end +end