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

RESOURCE-68 compute-global-public-delegated-prefixes #413

Merged
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
resource added for sql operations
Signed-off-by: sa-progress <samir.anand@progress.com>
  • Loading branch information
sa-progress committed Apr 20, 2022
commit 70dc317da9513f629941631013948611026be60c
46 changes: 46 additions & 0 deletions docs/resources/google_compute_public_delegated_prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: About the google_compute_public_delegated_prefix resource
platform: gcp
---

## Syntax
A `google_compute_public_delegated_prefix` is used to test a Google PublicDelegatedPrefix resource

## Examples
```
describe google_compute_public_delegated_prefix(project: 'chef-gcp-inspec', region: 'us-east1-b', name: 'test') do
it { should exist }
end
```

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


* `creation_timestamp`: Creation timestamp in RFC3339 text format.This field is deprecated.

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

* `id`: The unique identifier for the resource.

* `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.

* `ip_cidr_range`: The IPv4 address range, in CIDR format, represented by this public delegated prefix.

* `parent_prefix`: The value of requestId if you provided it in the request. Not present otherwise.

* `is_live_migration`: If true, the prefix will be live migrated.

* `fingerprint`: Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking. This field will be ignored when inserting a new PublicDelegatedPrefix. An up-to-date fingerprint must be provided in order to update the PublicDelegatedPrefix, otherwise the request will fail with error 412 conditionNotMet. To see the latest fingerprint, make a get() request to retrieve a PublicDelegatedPrefix. A base64-encoded string.

* `status`: The status of the public delegated prefix, which can be one of following values: * INITIALIZING The public delegated prefix is being initialized and addresses cannot be created yet. * READY_TO_ANNOUNCE The public delegated prefix is a live migration prefix and is active. * ANNOUNCED The public delegated prefix is active. * DELETING The public delegated prefix is being deprovsioned.
Possible values:
* INITIALIZING
* READY_TO_ANNOUNCE
* ANNOUNCED
* DELETING


## GCP Permissions

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

## Syntax
A `google_compute_public_delegated_prefixes` is used to test a Google PublicDelegatedPrefix resource

## Examples
```
describe google_compute_public_delegated_prefixes(project: 'chef-gcp-inspec', region: 'us-east1-b') do
it { should exist }
end
```

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

See [google_compute_public_delegated_prefix.md](google_compute_public_delegated_prefix.md) for more detailed information
* `creation_timestamps`: an array of `google_compute_public_delegated_prefix` creation_timestamp
* `descriptions`: an array of `google_compute_public_delegated_prefix` description
* `ids`: an array of `google_compute_public_delegated_prefix` id
* `names`: an array of `google_compute_public_delegated_prefix` name
* `ip_cidr_ranges`: an array of `google_compute_public_delegated_prefix` ip_cidr_range
* `parent_prefixes`: an array of `google_compute_public_delegated_prefix` parent_prefix
* `is_live_migrations`: an array of `google_compute_public_delegated_prefix` is_live_migration
* `fingerprints`: an array of `google_compute_public_delegated_prefix` fingerprint
* `statuses`: an array of `google_compute_public_delegated_prefix` status

## 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.
76 changes: 76 additions & 0 deletions libraries/google_compute_public_delegated_prefix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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'

# A provider to manage Compute Engine resources.
class ComputePublicDelegatedPrefix < GcpResourceBase
name 'google_compute_public_delegated_prefix'
desc 'PublicDelegatedPrefix'
supports platform: 'gcp'

attr_reader :params
attr_reader :creation_timestamp
attr_reader :description
attr_reader :id
attr_reader :name
attr_reader :ip_cidr_range
attr_reader :parent_prefix
attr_reader :is_live_migration
attr_reader :fingerprint
attr_reader :status

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
@creation_timestamp = parse_time_string(@fetched['creationTimestamp'])
@description = @fetched['description']
@id = @fetched['id']
@name = @fetched['name']
@ip_cidr_range = @fetched['ipCidrRange']
@parent_prefix = @fetched['parentPrefix']
@is_live_migration = @fetched['isLiveMigration']
@fingerprint = @fetched['fingerprint']
@status = @fetched['status']
end

# Handles parsing RFC3339 time string
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end

def exists?
!@fetched.nil?
end

def to_s
"PublicDelegatedPrefix #{@params[:name]}"
end

private

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

def resource_base_url
'projects/{{project}}/regions/{{region}}/publicDelegatedPrefixes/{{name}}'
end
end
100 changes: 100 additions & 0 deletions libraries/google_compute_public_delegated_prefixes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 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 ComputePublicDelegatedPrefixs < GcpResourceBase
name 'google_compute_public_delegated_prefixes'
desc 'PublicDelegatedPrefix plural resource'
supports platform: 'gcp'

attr_reader :table

filter_table_config = FilterTable.create

filter_table_config.add(:creation_timestamps, field: :creation_timestamp)
filter_table_config.add(:descriptions, field: :description)
filter_table_config.add(:ids, field: :id)
filter_table_config.add(:names, field: :name)
filter_table_config.add(:ip_cidr_ranges, field: :ip_cidr_range)
filter_table_config.add(:parent_prefixes, field: :parent_prefix)
filter_table_config.add(:is_live_migrations, field: :is_live_migration)
filter_table_config.add(:fingerprints, field: :fingerprint)
filter_table_config.add(:statuses, field: :status)

filter_table_config.connect(self, :table)

def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
@table = fetch_wrapped_resource('items')
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
{
'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) },
'description' => ->(obj) { return :description, obj['description'] },
'id' => ->(obj) { return :id, obj['id'] },
'name' => ->(obj) { return :name, obj['name'] },
'ipCidrRange' => ->(obj) { return :ip_cidr_range, obj['ipCidrRange'] },
'parentPrefix' => ->(obj) { return :parent_prefix, obj['parentPrefix'] },
'isLiveMigration' => ->(obj) { return :is_live_migration, obj['isLiveMigration'] },
'fingerprint' => ->(obj) { return :fingerprint, obj['fingerprint'] },
'status' => ->(obj) { return :status, obj['status'] },
}
end

# Handles parsing RFC3339 time string
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end

private

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

def resource_base_url
'projects/{{project}}/regions/{{region}}/publicDelegatedPrefixes'
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ----------------------------------------------------------------------------
#
# *** 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.
#
# ----------------------------------------------------------------------------

title 'Test GCP google_compute_public_delegated_prefix resource.'

gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.')
public_delegated_prefix = attribute('public_delegated_prefix', default: {
"name": "test"
}, description: 'PublicDelegatedPrefix resource in the given region')
control 'google_compute_public_delegated_prefix-1.0' do
impact 1.0
title 'google_compute_public_delegated_prefix resource test'

describe google_compute_public_delegated_prefix(project: gcp_project_id, region: 'us-east1-b', name: public_delegated_prefix['name']) do
it { should exist }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ----------------------------------------------------------------------------
#
# *** 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.
#
# ----------------------------------------------------------------------------

title 'Test GCP google_compute_public_delegated_prefixes resource.'

gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.')
public_delegated_prefix = attribute('public_delegated_prefix', default: {
"name": "test"
}, description: 'PublicDelegatedPrefix resource in the given region')
control 'google_compute_public_delegated_prefixes-1.0' do
impact 1.0
title 'google_compute_public_delegated_prefixes resource test'

describe google_compute_public_delegated_prefixes(project: gcp_project_id, region: 'us-east1-b') do
it { should exist }
end
end