Skip to content
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

CHEF-7204-MAGIC-MODULE-compute_v1-RegionNotificationEndpoint - Resource Implementation #625

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
65 changes: 65 additions & 0 deletions docs/resources/google_compute_region_notification_endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: About the google_compute_region_notification_endpoint resource
platform: gcp
---

## Syntax
A `google_compute_region_notification_endpoint` is used to test a Google RegionNotificationEndpoint resource

## Examples
```
describe google_compute_region_notification_endpoint(notificationEndpoint: ' ', project: 'chef-gcp-inspec', region: ' value_region') do
it { should exist }
its('kind') { should cmp 'value_kind' }
its('id') { should cmp 'value_id' }
its('creation_timestamp') { should cmp 'value_creationtimestamp' }
its('name') { should cmp 'value_name' }
its('description') { should cmp 'value_description' }
its('self_link') { should cmp 'value_selflink' }
its('region') { should cmp 'value_region' }

end

describe google_compute_region_notification_endpoint(notificationEndpoint: ' ', project: 'chef-gcp-inspec', region: ' value_region') do
it { should_not exist }
end
```

## Properties
Properties that can be accessed from the `google_compute_region_notification_endpoint` resource:


* `kind`: [Output Only] Type of the resource. Always compute#notificationEndpoint for notification endpoints.

* `id`: [Output Only] A unique identifier for this resource type. The server generates this identifier.

* `creation_timestamp`: [Output Only] Creation timestamp in RFC3339 text format.

* `name`: Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

* `description`: An optional description of this resource. Provide this property when you create the resource.

* `self_link`: [Output Only] Server-defined URL for the resource.

* `region`: [Output Only] URL of the region where the notification endpoint resides. This field applies only to the regional resource. You must specify this field as part of the HTTP request URL. It is not settable as a field in the request body.

* `grpc_settings`: Represents a gRPC setting that describes one gRPC notification endpoint and the retry duration attempting to send notification to this endpoint.

* `endpoint`: Endpoint to which gRPC notifications are sent. This must be a valid gRPCLB DNS name.

* `retry_duration_sec`: How much time (in seconds) is spent attempting notification retries until a successful response is received. Default is 30s. Limit is 20m (1200s). Must be a positive number.

* `payload_name`: Optional. If specified, this field is used to populate the "name" field in gRPC requests.

* `authority`: Optional. If specified, this field is used to set the authority header by the sender of notifications. See https://tools.ietf.org/html/rfc7540#section-8.1.2.3

* `resend_interval`: A Duration represents a fixed-length span of time represented as a count of seconds and fractions of seconds at nanosecond resolution. It is independent of any calendar and concepts like "day" or "month". Range is approximately 10,000 years.

* `seconds`: Span of time at a resolution of a second. Must be from 0 to 315,576,000,000 inclusive. Note: these bounds are computed from: 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years

* `nanos`: Span of time that's a fraction of a second at nanosecond resolution. Durations less than one second are represented with a 0 `seconds` field and a positive `nanos` field. Must be from 0 to 999,999,999 inclusive.


## GCP Permissions

Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project.
35 changes: 35 additions & 0 deletions docs/resources/google_compute_region_notification_endpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: About the google_compute_region_notification_endpoints resource
platform: gcp
---

## Syntax
A `google_compute_region_notification_endpoints` is used to test a Google RegionNotificationEndpoint resource

## Examples
```
describe google_compute_region_notification_endpoints(project: 'chef-gcp-inspec', region: ' value_region') do
it { should exist }
end
```

## Properties
Properties that can be accessed from the `google_compute_region_notification_endpoints` resource:

See [google_compute_region_notification_endpoint.md](google_compute_region_notification_endpoint.md) for more detailed information
* `kinds`: an array of `google_compute_region_notification_endpoint` kind
* `ids`: an array of `google_compute_region_notification_endpoint` id
* `creation_timestamps`: an array of `google_compute_region_notification_endpoint` creation_timestamp
* `names`: an array of `google_compute_region_notification_endpoint` name
* `descriptions`: an array of `google_compute_region_notification_endpoint` description
* `self_links`: an array of `google_compute_region_notification_endpoint` self_link
* `regions`: an array of `google_compute_region_notification_endpoint` region
* `grpc_settings`: an array of `google_compute_region_notification_endpoint` grpc_settings

## 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.

## GCP Permissions

Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# 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 'google/compute/property/regionnotificationendpoint_grpc_settings_resend_interval'
module GoogleInSpec
module Compute
module Property
class RegionNotificationEndpointGrpcSettings
attr_reader :endpoint

attr_reader :retry_duration_sec

attr_reader :payload_name

attr_reader :authority

attr_reader :resend_interval

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@endpoint = args['endpoint']
@retry_duration_sec = args['retryDurationSec']
@payload_name = args['payloadName']
@authority = args['authority']
@resend_interval = GoogleInSpec::Compute::Property::RegionNotificationEndpointGrpcSettingsResendInterval.new(args['resendInterval'], to_s)
end

def to_s
"#{@parent_identifier} RegionNotificationEndpointGrpcSettings"
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# 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 Compute
module Property
class RegionNotificationEndpointGrpcSettingsResendInterval
attr_reader :seconds

attr_reader :nanos

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@seconds = args['seconds']
@nanos = args['nanos']
end

def to_s
"#{@parent_identifier} RegionNotificationEndpointGrpcSettingsResendInterval"
end
end
end
end
end
71 changes: 71 additions & 0 deletions libraries/google_compute_region_notification_endpoint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# 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/compute/property/regionnotificationendpoint_grpc_settings'
require 'google/compute/property/regionnotificationendpoint_grpc_settings_resend_interval'

# A provider to manage Compute Engine resources.
class ComputeRegionNotificationEndpoint < GcpResourceBase
name 'google_compute_region_notification_endpoint'
desc 'RegionNotificationEndpoint'
supports platform: 'gcp'

attr_reader :params
attr_reader :kind
attr_reader :id
attr_reader :creation_timestamp
attr_reader :name
attr_reader :description
attr_reader :self_link
attr_reader :region
attr_reader :grpc_settings

def initialize(params)
super(params.merge({ use_http_transport: true }))
@params = params
@fetched = @connection.fetch(product_url(params[:beta]), resource_base_url, params, 'Get')
parse unless @fetched.nil?
end

def parse
@kind = @fetched['kind']
@id = @fetched['id']
@creation_timestamp = @fetched['creationTimestamp']
@name = @fetched['name']
@description = @fetched['description']
@self_link = @fetched['selfLink']
@region = @fetched['region']
@grpc_settings = GoogleInSpec::Compute::Property::RegionNotificationEndpointGrpcSettings.new(@fetched['grpcSettings'], to_s)
end

def exists?
[email protected]?
end

def to_s
"RegionNotificationEndpoint #{@params[:notificationEndpoint]}"
end

private

def product_url(_ = nil)
'https://compute.googleapis.com/compute/v1/'
end

def resource_base_url
'projects/{{project}}/regions/{{region}}/notificationEndpoints/{{notification_endpoint}}'
end
end
93 changes: 93 additions & 0 deletions libraries/google_compute_region_notification_endpoints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# 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 ComputeRegionNotificationEndpoints < GcpResourceBase
name 'google_compute_region_notification_endpoints'
desc 'RegionNotificationEndpoint plural resource'
supports platform: 'gcp'

attr_reader :table

filter_table_config = FilterTable.create

filter_table_config.add(:kinds, field: :kind)
filter_table_config.add(:ids, field: :id)
filter_table_config.add(:creation_timestamps, field: :creation_timestamp)
filter_table_config.add(:names, field: :name)
filter_table_config.add(:descriptions, field: :description)
filter_table_config.add(:self_links, field: :self_link)
filter_table_config.add(:regions, field: :region)
filter_table_config.add(:grpc_settings, field: :grpc_settings)

filter_table_config.connect(self, :table)

def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
@table = fetch_wrapped_resource('regionNotificationEndpoints')
end

def fetch_wrapped_resource(wrap_path)
# fetch_resource returns an array of responses (to handle pagination)
result = @connection.fetch_all(product_url, resource_base_url, @params, 'Get')
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_key do |key|
name, value = transform(key, hash)
hash_with_symbols[name] = value
end
converted.push(hash_with_symbols)
end
end

converted
end

def transform(key, value)
return transformers[key].call(value) if transformers.key?(key)

[key.to_sym, value]
end

def transformers
{
'kind' => ->(obj) { [:kind, obj['kind']] },
'id' => ->(obj) { [:id, obj['id']] },
'creationTimestamp' => ->(obj) { [:creation_timestamp, obj['creationTimestamp']] },
'name' => ->(obj) { [:name, obj['name']] },
'description' => ->(obj) { [:description, obj['description']] },
'selfLink' => ->(obj) { [:self_link, obj['selfLink']] },
'region' => ->(obj) { [:region, obj['region']] },
'grpcSettings' => ->(obj) { [:grpc_settings, GoogleInSpec::Compute::Property::RegionNotificationEndpointGrpcSettings.new(obj['grpcSettings'], to_s)] },
}
end

private

def product_url(_ = nil)
'https://compute.googleapis.com/compute/v1/'
end

def resource_base_url
'projects/{{project}}/regions/{{region}}/notificationEndpoints'
end
end
Loading