From a69d07f57ab1891c994d08d045b06c9c54cfced5 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 6 Aug 2019 12:15:07 -0700 Subject: [PATCH] Pub/Sub Geo Restriction (#175) Signed-off-by: Modular Magician --- docs/resources/google_pubsub_topic.md | 4 +++ docs/resources/google_pubsub_topics.md | 1 + .../property/topic_message_storage_policy.rb | 34 +++++++++++++++++++ libraries/google_pubsub_topic.rb | 3 ++ libraries/google_pubsub_topics.rb | 2 ++ 5 files changed, 44 insertions(+) create mode 100644 libraries/google/pubsub/property/topic_message_storage_policy.rb diff --git a/docs/resources/google_pubsub_topic.md b/docs/resources/google_pubsub_topic.md index b8a97d5a1..99db6326b 100644 --- a/docs/resources/google_pubsub_topic.md +++ b/docs/resources/google_pubsub_topic.md @@ -26,6 +26,10 @@ Properties that can be accessed from the `google_pubsub_topic` resource: * `labels`: A set of key/value label pairs to assign to this Topic. + * `message_storage_policy`: Policy constraining the set of Google Cloud Platform regions where messages published to the topic may be stored. If not present, then no constraints are in effect. + + * `allowed_persistence_regions`: A list of IDs of GCP regions where messages that are published to the topic may be persisted in storage. Messages published by publishers running in non-allowed GCP regions (or running outside of GCP altogether) will be routed for storage in one of the allowed regions. An empty list means that no regions are allowed, and is not a valid configuration. + ## GCP Permissions diff --git a/docs/resources/google_pubsub_topics.md b/docs/resources/google_pubsub_topics.md index ea8bae966..558c80432 100644 --- a/docs/resources/google_pubsub_topics.md +++ b/docs/resources/google_pubsub_topics.md @@ -30,6 +30,7 @@ See [google_pubsub_topic.md](google_pubsub_topic.md) for more detailed informati * `names`: an array of `google_pubsub_topic` name * `kms_key_names`: an array of `google_pubsub_topic` kms_key_name * `labels`: an array of `google_pubsub_topic` labels + * `message_storage_policies`: an array of `google_pubsub_topic` message_storage_policy ## Filter Criteria This resource supports all of the above properties as filter criteria, which can be used diff --git a/libraries/google/pubsub/property/topic_message_storage_policy.rb b/libraries/google/pubsub/property/topic_message_storage_policy.rb new file mode 100644 index 000000000..4a71742e4 --- /dev/null +++ b/libraries/google/pubsub/property/topic_message_storage_policy.rb @@ -0,0 +1,34 @@ +# 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 Pubsub + module Property + class TopicMessageStoragePolicy + attr_reader :allowed_persistence_regions + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @allowed_persistence_regions = args['allowedPersistenceRegions'] + end + + def to_s + "#{@parent_identifier} TopicMessageStoragePolicy" + end + end + end + end +end diff --git a/libraries/google_pubsub_topic.rb b/libraries/google_pubsub_topic.rb index 118b86be1..26e9ed488 100644 --- a/libraries/google_pubsub_topic.rb +++ b/libraries/google_pubsub_topic.rb @@ -14,6 +14,7 @@ # # ---------------------------------------------------------------------------- require 'gcp_backend' +require 'google/pubsub/property/topic_message_storage_policy' # A provider to manage Cloud Pub/Sub resources. class Topic < GcpResourceBase @@ -25,6 +26,7 @@ class Topic < GcpResourceBase attr_reader :name attr_reader :kms_key_name attr_reader :labels + attr_reader :message_storage_policy def initialize(params) super(params.merge({ use_http_transport: true })) @@ -37,6 +39,7 @@ def parse @name = name_from_self_link(@fetched['name']) @kms_key_name = @fetched['kmsKeyName'] @labels = @fetched['labels'] + @message_storage_policy = GoogleInSpec::Pubsub::Property::TopicMessageStoragePolicy.new(@fetched['messageStoragePolicy'], to_s) end # Handles parsing RFC3339 time string diff --git a/libraries/google_pubsub_topics.rb b/libraries/google_pubsub_topics.rb index 068c6e94d..de9c9b45a 100644 --- a/libraries/google_pubsub_topics.rb +++ b/libraries/google_pubsub_topics.rb @@ -26,6 +26,7 @@ class Topics < GcpResourceBase filter_table_config.add(:names, field: :name) filter_table_config.add(:kms_key_names, field: :kms_key_name) filter_table_config.add(:labels, field: :labels) + filter_table_config.add(:message_storage_policies, field: :message_storage_policy) filter_table_config.connect(self, :table) @@ -68,6 +69,7 @@ def transformers 'name' => ->(obj) { return :name, name_from_self_link(obj['name']) }, 'kmsKeyName' => ->(obj) { return :kms_key_name, obj['kmsKeyName'] }, 'labels' => ->(obj) { return :labels, obj['labels'] }, + 'messageStoragePolicy' => ->(obj) { return :message_storage_policy, GoogleInSpec::Pubsub::Property::TopicMessageStoragePolicy.new(obj['messageStoragePolicy'], to_s) }, } end