Skip to content

Commit

Permalink
Add labels to Pubsub Subscription/Topics (#109)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and rileykarson committed Feb 19, 2019
1 parent 2688372 commit 28ec6a7
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/resources/google_pubsub_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ Properties that can be accessed from the `google_pubsub_subscription` resource:

* `topic`: A reference to a Topic resource.

* `labels`: A set of key/value label pairs to assign to this Subscription.

* `push_config`: If push delivery is used with this subscription, this field is used to configure it. An empty pushConfig signifies that the subscriber will pull and ack messages using API methods.

* `pushEndpoint`: A URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might use "https://example.com/push".

* `attributes`: Endpoint configuration attributes. Every endpoint has a set of API supported attributes that can be used to control different aspects of the message delivery. The currently supported attribute is x-goog-version, which you can use to change the format of the pushed message. This attribute indicates the version of the data expected by the endpoint. This controls the shape of the pushed message (i.e., its fields and metadata). The endpoint version is based on the version of the Pub/Sub API. If not present during the subscriptions.create call, it will default to the version of the API used to make such call. If not present during a subscriptions.modifyPushConfig call, its value will not be changed. subscriptions.get calls will always return a valid version, even if the subscription was created without this attribute. The possible values for this attribute are: - v1beta1: uses the push format defined in the v1beta1 Pub/Sub API. - v1 or v1beta2: uses the push format defined in the v1 Pub/Sub API.

* `ack_deadline_seconds`: This value is the maximum time after a subscriber receives a message before the subscriber should acknowledge the message. After message delivery but before the ack deadline expires and before the message is acknowledged, it is an outstanding message and will not be delivered again during that time (on a best-effort basis). For pull subscriptions, this value is used as the initial value for the ack deadline. To override this value for a given message, call subscriptions.modifyAckDeadline with the corresponding ackId if using pull. The minimum custom deadline you can specify is 10 seconds. The maximum custom deadline you can specify is 600 seconds (10 minutes). If this parameter is 0, a default value of 10 seconds is used. For push delivery, this value is also used to set the request timeout for the call to the push endpoint. If the subscriber never acknowledges the message, the Pub/Sub system will eventually redeliver the message.
1 change: 1 addition & 0 deletions docs/resources/google_pubsub_subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Properties that can be accessed from the `google_pubsub_subscriptions` resource:
See [google_pubsub_subscription.md](google_pubsub_subscription.md) for more detailed information
* `names`: an array of `google_pubsub_subscription` name
* `topics`: an array of `google_pubsub_subscription` topic
* `labels`: an array of `google_pubsub_subscription` labels
* `push_configs`: an array of `google_pubsub_subscription` push_config
* `ack_deadline_seconds`: an array of `google_pubsub_subscription` ack_deadline_seconds

Expand Down
2 changes: 2 additions & 0 deletions docs/resources/google_pubsub_topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ end
Properties that can be accessed from the `google_pubsub_topic` resource:

* `name`: Name of the topic.

* `labels`: A set of key/value label pairs to assign to this Topic.
1 change: 1 addition & 0 deletions docs/resources/google_pubsub_topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Properties that can be accessed from the `google_pubsub_topics` resource:

See [google_pubsub_topic.md](google_pubsub_topic.md) for more detailed information
* `names`: an array of `google_pubsub_topic` name
* `labels`: an array of `google_pubsub_topic` labels

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
Expand Down
3 changes: 3 additions & 0 deletions libraries/google/pubsub/property/subscription_push_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ module Property
class SubscriptionPushConfig
attr_reader :push_endpoint

attr_reader :attributes

def initialize(args = nil)
return if args.nil?
@push_endpoint = args['pushEndpoint']
@attributes = args['attributes']
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions libraries/google_pubsub_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Subscription < GcpResourceBase

attr_reader :name
attr_reader :topic
attr_reader :labels
attr_reader :push_config
attr_reader :ack_deadline_seconds
def base
Expand All @@ -43,6 +44,7 @@ def initialize(params)
def parse
@name = name_from_self_link(@fetched['name'])
@topic = @fetched['topic']
@labels = @fetched['labels']
@push_config = GoogleInSpec::Pubsub::Property::SubscriptionPushConfig.new(@fetched['pushConfig'])
@ack_deadline_seconds = @fetched['ackDeadlineSeconds']
end
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 @@ -25,6 +25,7 @@ class Subscriptions < GcpResourceBase

filter_table_config.add(:names, field: :name)
filter_table_config.add(:topics, field: :topic)
filter_table_config.add(:labels, field: :labels)
filter_table_config.add(:push_configs, field: :push_config)
filter_table_config.add(:ack_deadline_seconds, field: :ack_deadline_seconds)

Expand Down Expand Up @@ -76,6 +77,7 @@ def transformers
{
'name' => ->(obj) { return :name, name_from_self_link(obj['name']) },
'topic' => ->(obj) { return :topic, obj['topic'] },
'labels' => ->(obj) { return :labels, obj['labels'] },
'pushConfig' => ->(obj) { return :push_config, GoogleInSpec::Pubsub::Property::SubscriptionPushConfig.new(obj['pushConfig']) },
'ackDeadlineSeconds' => ->(obj) { return :ack_deadline_seconds, obj['ackDeadlineSeconds'] },
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/google_pubsub_topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Topic < GcpResourceBase
supports platform: 'gcp'

attr_reader :name
attr_reader :labels
def base
'https://pubsub.googleapis.com/v1/'
end
Expand All @@ -38,6 +39,7 @@ def initialize(params)

def parse
@name = name_from_self_link(@fetched['name'])
@labels = @fetched['labels']
end

# Handles parsing RFC3339 time string
Expand Down
2 changes: 2 additions & 0 deletions libraries/google_pubsub_topics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Topics < GcpResourceBase
filter_table_config = FilterTable.create

filter_table_config.add(:names, field: :name)
filter_table_config.add(:labels, field: :labels)

filter_table_config.connect(self, :table)

Expand Down Expand Up @@ -72,6 +73,7 @@ def transform(key, value)
def transformers
{
'name' => ->(obj) { return :name, name_from_self_link(obj['name']) },
'labels' => ->(obj) { return :labels, obj['labels'] },
}
end

Expand Down

0 comments on commit 28ec6a7

Please sign in to comment.