From 5f54921cab9008ab1be6bb5becf73d6df4441a91 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Thu, 7 Nov 2019 18:36:21 +0000 Subject: [PATCH] [Ansible] Service Usage Services Signed-off-by: Modular Magician --- docs/resources/google_project_service.md | 16 ++++++- docs/resources/google_project_services.md | 2 + .../serviceusage/property/service_config.rb | 41 +++++++++++++++++ .../property/service_config_apis.rb | 45 +++++++++++++++++++ libraries/google_project_service.rb | 6 +++ libraries/google_project_services.rb | 4 ++ 6 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 libraries/google/serviceusage/property/service_config.rb create mode 100644 libraries/google/serviceusage/property/service_config_apis.rb diff --git a/docs/resources/google_project_service.md b/docs/resources/google_project_service.md index c538da757..99f05564e 100644 --- a/docs/resources/google_project_service.md +++ b/docs/resources/google_project_service.md @@ -20,10 +20,24 @@ Properties that can be accessed from the `google_project_service` resource: * `name`: The resource name of the service - * `parent`: The name of the parent of this service. For example: `projects/123` + * `parent`: The name of the parent of this service. For example 'projects/123' * `state`: Whether or not the service has been enabled for use by the consumer. + * `disable_dependent_services`: Indicates if dependent services should also be disabled. Can only be turned on if service is disabled. + + * `config`: The service configuration of the available service. + + * `name`: The DNS address at which this service is available. + + * `title`: The product title for this service + + * `apis`: The list of API interfaces exported by this service. + + * `name`: Name of the API + + * `version`: The version of the API + ## GCP Permissions diff --git a/docs/resources/google_project_services.md b/docs/resources/google_project_services.md index 986d43859..bffba8a86 100644 --- a/docs/resources/google_project_services.md +++ b/docs/resources/google_project_services.md @@ -24,6 +24,8 @@ See [google_project_service.md](google_project_service.md) for more detailed inf * `names`: an array of `google_project_service` name * `parents`: an array of `google_project_service` parent * `states`: an array of `google_project_service` state + * `disable_dependent_services`: an array of `google_project_service` disable_dependent_services + * `configs`: an array of `google_project_service` config ## Filter Criteria This resource supports all of the above properties as filter criteria, which can be used diff --git a/libraries/google/serviceusage/property/service_config.rb b/libraries/google/serviceusage/property/service_config.rb new file mode 100644 index 000000000..b1646b6ca --- /dev/null +++ b/libraries/google/serviceusage/property/service_config.rb @@ -0,0 +1,41 @@ +# 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 'google/serviceusage/property/service_config_apis' +module GoogleInSpec + module ServiceUsage + module Property + class ServiceConfig + attr_reader :name + + attr_reader :title + + attr_reader :apis + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @name = args['name'] + @title = args['title'] + @apis = GoogleInSpec::ServiceUsage::Property::ServiceConfigApisArray.parse(args['apis'], to_s) + end + + def to_s + "#{@parent_identifier} ServiceConfig" + end + end + end + end +end diff --git a/libraries/google/serviceusage/property/service_config_apis.rb b/libraries/google/serviceusage/property/service_config_apis.rb new file mode 100644 index 000000000..455356649 --- /dev/null +++ b/libraries/google/serviceusage/property/service_config_apis.rb @@ -0,0 +1,45 @@ +# 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. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module ServiceUsage + module Property + class ServiceConfigApis + attr_reader :name + + attr_reader :version + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @name = args['name'] + @version = args['version'] + end + + def to_s + "#{@parent_identifier} ServiceConfigApis" + end + end + + class ServiceConfigApisArray + def self.parse(value, parent_identifier) + return if value.nil? + return ServiceConfigApis.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| ServiceConfigApis.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google_project_service.rb b/libraries/google_project_service.rb index 1ca048463..37fe4506d 100644 --- a/libraries/google_project_service.rb +++ b/libraries/google_project_service.rb @@ -14,6 +14,8 @@ # # ---------------------------------------------------------------------------- require 'gcp_backend' +require 'google/serviceusage/property/service_config' +require 'google/serviceusage/property/service_config_apis' # A provider to manage Service Usage resources. class ServiceUsageService < GcpResourceBase @@ -25,6 +27,8 @@ class ServiceUsageService < GcpResourceBase attr_reader :name attr_reader :parent attr_reader :state + attr_reader :disable_dependent_services + attr_reader :config def initialize(params) super(params.merge({ use_http_transport: true })) @@ -37,6 +41,8 @@ def parse @name = @fetched['name'] @parent = @fetched['parent'] @state = @fetched['state'] + @disable_dependent_services = @fetched['disableDependentServices'] + @config = GoogleInSpec::ServiceUsage::Property::ServiceConfig.new(@fetched['config'], to_s) end # Handles parsing RFC3339 time string diff --git a/libraries/google_project_services.rb b/libraries/google_project_services.rb index be604ed14..4d5071078 100644 --- a/libraries/google_project_services.rb +++ b/libraries/google_project_services.rb @@ -26,6 +26,8 @@ class ServiceUsageServices < GcpResourceBase filter_table_config.add(:names, field: :name) filter_table_config.add(:parents, field: :parent) filter_table_config.add(:states, field: :state) + filter_table_config.add(:disable_dependent_services, field: :disable_dependent_services) + filter_table_config.add(:configs, field: :config) filter_table_config.connect(self, :table) @@ -68,6 +70,8 @@ def transformers 'name' => ->(obj) { return :name, obj['name'] }, 'parent' => ->(obj) { return :parent, obj['parent'] }, 'state' => ->(obj) { return :state, obj['state'] }, + 'disableDependentServices' => ->(obj) { return :disable_dependent_services, obj['disableDependentServices'] }, + 'config' => ->(obj) { return :config, GoogleInSpec::ServiceUsage::Property::ServiceConfig.new(obj['config'], to_s) }, } end