From 58489393b4eeb1c645e543ef3f556deae587035a Mon Sep 17 00:00:00 2001 From: Ty Larrabee Date: Tue, 30 Apr 2019 23:53:32 +0000 Subject: [PATCH] Add expiration policy to pubsub subscription resource Signed-off-by: Modular Magician --- docs/resources/google_pubsub_subscription.md | 4 +++ docs/resources/google_pubsub_subscriptions.md | 1 + .../subscription_expiration_policy.rb | 34 +++++++++++++++++++ libraries/google_pubsub_subscription.rb | 3 ++ libraries/google_pubsub_subscriptions.rb | 2 ++ 5 files changed, 44 insertions(+) create mode 100644 libraries/google/pubsub/property/subscription_expiration_policy.rb diff --git a/docs/resources/google_pubsub_subscription.md b/docs/resources/google_pubsub_subscription.md index f5713d361..bc06073e7 100644 --- a/docs/resources/google_pubsub_subscription.md +++ b/docs/resources/google_pubsub_subscription.md @@ -38,6 +38,10 @@ Properties that can be accessed from the `google_pubsub_subscription` resource: * `retain_acked_messages`: Indicates whether to retain acknowledged messages. If `true`, then messages are not expunged from the subscription's backlog, even if they are acknowledged, until they fall out of the messageRetentionDuration window. + * `expiration_policy`: A policy that specifies the conditions for this subscription's expiration. A subscription is considered active as long as any connected subscriber is successfully consuming messages from the subscription or is issuing operations on the subscription. If expirationPolicy is not set, a default policy with ttl of 31 days will be used. The minimum allowed value for expirationPolicy.ttl is 1 day. + + * `ttl`: Specifies the "time-to-live" duration for an associated resource. The resource expires if it is not active for a period of ttl. The definition of "activity" depends on the type of the associated resource. The minimum and maximum allowed values for ttl depend on the type of the associated resource, as well. If ttl is not set, the associated resource never expires. + ## GCP Permissions diff --git a/docs/resources/google_pubsub_subscriptions.md b/docs/resources/google_pubsub_subscriptions.md index 75092b065..d95d60dd4 100644 --- a/docs/resources/google_pubsub_subscriptions.md +++ b/docs/resources/google_pubsub_subscriptions.md @@ -30,6 +30,7 @@ See [google_pubsub_subscription.md](google_pubsub_subscription.md) for more deta * `ack_deadline_seconds`: an array of `google_pubsub_subscription` ack_deadline_seconds * `message_retention_durations`: an array of `google_pubsub_subscription` message_retention_duration * `retain_acked_messages`: an array of `google_pubsub_subscription` retain_acked_messages + * `expiration_policies`: an array of `google_pubsub_subscription` expiration_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/subscription_expiration_policy.rb b/libraries/google/pubsub/property/subscription_expiration_policy.rb new file mode 100644 index 000000000..914944bf6 --- /dev/null +++ b/libraries/google/pubsub/property/subscription_expiration_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 SubscriptionExpirationPolicy + attr_reader :ttl + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @ttl = args['ttl'] + end + + def to_s + "#{@parent_identifier} SubscriptionExpirationPolicy" + end + end + end + end +end diff --git a/libraries/google_pubsub_subscription.rb b/libraries/google_pubsub_subscription.rb index a2d5a6a12..6975ba247 100644 --- a/libraries/google_pubsub_subscription.rb +++ b/libraries/google_pubsub_subscription.rb @@ -14,6 +14,7 @@ # # ---------------------------------------------------------------------------- require 'gcp_backend' +require 'google/pubsub/property/subscription_expiration_policy' require 'google/pubsub/property/subscription_push_config' # A provider to manage Cloud Pub/Sub resources. @@ -30,6 +31,7 @@ class Subscription < GcpResourceBase attr_reader :ack_deadline_seconds attr_reader :message_retention_duration attr_reader :retain_acked_messages + attr_reader :expiration_policy def initialize(params) super(params.merge({ use_http_transport: true })) @@ -46,6 +48,7 @@ def parse @ack_deadline_seconds = @fetched['ackDeadlineSeconds'] @message_retention_duration = @fetched['messageRetentionDuration'] @retain_acked_messages = @fetched['retainAckedMessages'] + @expiration_policy = GoogleInSpec::Pubsub::Property::SubscriptionExpirationPolicy.new(@fetched['expirationPolicy'], to_s) end # Handles parsing RFC3339 time string diff --git a/libraries/google_pubsub_subscriptions.rb b/libraries/google_pubsub_subscriptions.rb index 66ce93252..a07e976dd 100644 --- a/libraries/google_pubsub_subscriptions.rb +++ b/libraries/google_pubsub_subscriptions.rb @@ -30,6 +30,7 @@ class Subscriptions < GcpResourceBase filter_table_config.add(:ack_deadline_seconds, field: :ack_deadline_seconds) filter_table_config.add(:message_retention_durations, field: :message_retention_duration) filter_table_config.add(:retain_acked_messages, field: :retain_acked_messages) + filter_table_config.add(:expiration_policies, field: :expiration_policy) filter_table_config.connect(self, :table) @@ -76,6 +77,7 @@ def transformers 'ackDeadlineSeconds' => ->(obj) { return :ack_deadline_seconds, obj['ackDeadlineSeconds'] }, 'messageRetentionDuration' => ->(obj) { return :message_retention_duration, obj['messageRetentionDuration'] }, 'retainAckedMessages' => ->(obj) { return :retain_acked_messages, obj['retainAckedMessages'] }, + 'expirationPolicy' => ->(obj) { return :expiration_policy, GoogleInSpec::Pubsub::Property::SubscriptionExpirationPolicy.new(obj['expirationPolicy'], to_s) }, } end