-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pubsub subscription + topic #99
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ad2eee9
Add pubsub support using Magic Module
jnahelou 558f1f9
Add pubsub scope
jnahelou 30d25c8
Add pubsub tests
jnahelou 0655ec1
Merge branch 'master' into feat/pubsub-magicmodule
jnahelou 58b8b28
Add frozen string literal to pass rubocop
slevenick b92be4f
Commit test
slevenick 354263d
Merge pull request #56 from modular-magician/codegen-pr-1163
slevenick 71614c0
Add InSpec disk resource, refactors of attributes within examples and…
slevenick 2854a02
Merge pull request #57 from modular-magician/codegen-pr-1164
slevenick 6187415
Remove extra braces from inspec ssl policy test
slevenick 28ec2f6
Merge pull request #58 from modular-magician/codegen-pr-1166
slevenick 5b3b46b
Convert name from self link to name
jnahelou 3fd41e6
Updates pubsub tests
jnahelou 81417cd
Merge pull request #62 from jnahelou/feat/pubsub-magicmodule
slevenick 157e937
Rubocop fixes
slevenick 381fac1
Add PubSub support
jnahelou a514215
Merge pull request #59 from modular-magician/codegen-pr-1168
slevenick 4a789fd
Merge remote-tracking branch 'gcp/master' into pubsub-addition
slevenick 16d04ff
Define rubocop target ruby version to 2.4
slevenick c85a01f
Update pubsub to pull gcp project id from correct spot
slevenick 46a9cbe
Actually use memoized variables
slevenick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
--- | ||
AllCops: | ||
TargetRubyVersion: 2.4 | ||
Exclude: | ||
- Gemfile | ||
- Rakefile | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: About the Subscription resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_pubsub_subscription` is used to test a Google Subscription resource | ||
|
||
## Examples | ||
``` | ||
describe google_pubsub_subscription(project: 'chef-gcp-inspec', name: 'inspec-gcp-subscription') do | ||
it { should exist } | ||
end | ||
|
||
describe google_pubsub_subscription(project: 'chef-gcp-inspec', name: 'nonexistent') do | ||
it { should_not exist } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_pubsub_subscription` resource: | ||
|
||
* `name`: Name of the subscription. | ||
|
||
* `topic`: A reference to a Topic resource. | ||
|
||
* `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". | ||
|
||
* `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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: About the Subscription resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_pubsub_subscriptions` is used to test a Google Subscription resource | ||
|
||
## Examples | ||
``` | ||
describe google_pubsub_subscriptions(project: 'chef-gcp-inspec') do | ||
it { should exist } | ||
its('count') { should eq 1 } | ||
end | ||
|
||
google_pubsub_subscriptions(project: 'chef-gcp-inspec').names.each do |subscription_name| | ||
describe google_pubsub_subscription(project: 'chef-gcp-inspec', name: subscription_name) do | ||
it { should exist } | ||
end | ||
end | ||
|
||
``` | ||
|
||
## Properties | ||
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 | ||
* `push_configs`: an array of `google_pubsub_subscription` push_config | ||
* `ack_deadline_seconds`: an array of `google_pubsub_subscription` ack_deadline_seconds | ||
|
||
## Filter Criteria | ||
This resource supports all of the above properties as filter criteria, which can be used | ||
with `where` as a block or a method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
title: About the Topic resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_pubsub_topic` is used to test a Google Topic resource | ||
|
||
## Examples | ||
``` | ||
describe google_pubsub_topic(project: 'chef-gcp-inspec', name: 'inspec-gcp-topic') do | ||
it { should exist } | ||
end | ||
|
||
describe google_pubsub_topic(project: 'chef-gcp-inspec', name: 'nonexistent') do | ||
it { should_not exist } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_pubsub_topic` resource: | ||
|
||
* `name`: Name of the topic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: About the Topic resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_pubsub_topics` is used to test a Google Topic resource | ||
|
||
## Examples | ||
``` | ||
describe google_pubsub_topics(project: 'chef-gcp-inspec') do | ||
it { should exist } | ||
its('names') { should include 'inspec-gcp-topic' } | ||
its('count') { should eq 1 } | ||
end | ||
|
||
google_pubsub_topics(project: 'chef-gcp-inspec').names.each do |topic_name| | ||
describe google_pubsub_topic(project: 'chef-gcp-inspec', name: topic_name) do | ||
its('name') { should eq 'inspec-gcp-topic' } | ||
end | ||
end | ||
|
||
``` | ||
|
||
## Properties | ||
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 | ||
|
||
## Filter Criteria | ||
This resource supports all of the above properties as filter criteria, which can be used | ||
with `where` as a block or a method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
libraries/google/pubsub/property/subscription_push_config.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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 SubscriptionPushconfig | ||
attr_reader :push_endpoint | ||
|
||
def initialize(args = nil) | ||
return if args.nil? | ||
@push_endpoint = args['pushEndpoint'] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 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 'gcp_backend' | ||
require 'google/pubsub/property/subscription_push_config' | ||
|
||
# A provider to manage Google Cloud Pub/Sub resources. | ||
class Subscription < GcpResourceBase | ||
name 'google_pubsub_subscription' | ||
desc 'Subscription' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :name | ||
attr_reader :topic | ||
attr_reader :push_config | ||
attr_reader :ack_deadline_seconds | ||
def base | ||
'https://pubsub.googleapis.com/v1/' | ||
end | ||
|
||
def url | ||
'projects/{{project}}/subscriptions/{{name}}' | ||
end | ||
|
||
def initialize(params) | ||
super(params.merge({ use_http_transport: true })) | ||
@fetched = @connection.fetch(base, url, params) | ||
parse unless @fetched.nil? | ||
end | ||
|
||
def parse | ||
@name = name_from_self_link(@fetched['name']) | ||
@topic = @fetched['topic'] | ||
@push_config = GoogleInSpec::Pubsub::Property::SubscriptionPushconfig.new(@fetched['pushConfig']) | ||
@ack_deadline_seconds = @fetched['ackDeadlineSeconds'] | ||
end | ||
|
||
# Handles parsing RFC3339 time string | ||
def parse_time_string(time_string) | ||
time_string ? Time.parse(time_string) : nil | ||
end | ||
|
||
def exists? | ||
[email protected]? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# 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 'gcp_backend' | ||
class Subscriptions < GcpResourceBase | ||
name 'google_pubsub_subscriptions' | ||
desc 'Subscription plural resource' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :table | ||
|
||
filter_table_config = FilterTable.create | ||
|
||
filter_table_config.add(:names, field: :name) | ||
filter_table_config.add(:topics, field: :topic) | ||
filter_table_config.add(:push_configs, field: :pushConfig) | ||
filter_table_config.add(:ack_deadline_seconds, field: :ackDeadlineSeconds) | ||
|
||
filter_table_config.connect(self, :table) | ||
|
||
def base | ||
'https://pubsub.googleapis.com/v1/' | ||
end | ||
|
||
def url | ||
'projects/{{project}}/subscriptions' | ||
end | ||
|
||
def initialize(params = {}) | ||
super(params.merge({ use_http_transport: true })) | ||
@params = params | ||
@table = fetch_wrapped_resource('subscriptions') | ||
end | ||
|
||
def fetch_wrapped_resource(wrap_path) | ||
# fetch_resource returns an array of responses (to handle pagination) | ||
result = @connection.fetch_all(base, url, @params) | ||
return if result.nil? | ||
|
||
# Conversion of string -> object hash to symbol -> object hash that InSpec needs | ||
converted = [] | ||
result.each do |response| | ||
next if response.nil? || !response.key?(wrap_path) | ||
response[wrap_path].each do |hash| | ||
hash_with_symbols = {} | ||
hash.each_pair { |k, v| hash_with_symbols[k.to_sym] = v } | ||
hash_with_symbols[:name] = name_from_self_link(hash_with_symbols[:name]) | ||
converted.push(hash_with_symbols) | ||
end | ||
end | ||
|
||
converted | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 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 'gcp_backend' | ||
|
||
# A provider to manage Google Cloud Pub/Sub resources. | ||
class Topic < GcpResourceBase | ||
name 'google_pubsub_topic' | ||
desc 'Topic' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :name | ||
def base | ||
'https://pubsub.googleapis.com/v1/' | ||
end | ||
|
||
def url | ||
'projects/{{project}}/topics/{{name}}' | ||
end | ||
|
||
def initialize(params) | ||
super(params.merge({ use_http_transport: true })) | ||
@fetched = @connection.fetch(base, url, params) | ||
parse unless @fetched.nil? | ||
end | ||
|
||
def parse | ||
@name = name_from_self_link(@fetched['name']) | ||
end | ||
|
||
# Handles parsing RFC3339 time string | ||
def parse_time_string(time_string) | ||
time_string ? Time.parse(time_string) : nil | ||
end | ||
|
||
def exists? | ||
[email protected]? | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this to pin the ruby version rubocop was targeting. I was seeing errors in Travis due to default target ruby version that weren't showing up in my local environment and vice versa. I don't have an attachment to 2.4, just want something