Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Add expiration policy to pubsub subscription resource #153

Merged
merged 1 commit into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/resources/google_pubsub_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. A duration in seconds with up to nine fractional digits, terminated by 's'. Example - "3.5s".



## GCP Permissions
Expand Down
1 change: 1 addition & 0 deletions docs/resources/google_pubsub_subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions libraries/google/pubsub/property/subscription_expiration_policy.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions libraries/google_pubsub_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 }))
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libraries/google_pubsub_subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down