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-MAGIC-MODULE-cloudkms-Projects__locations__keyRing - Resource Implementation #560

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
34 changes: 34 additions & 0 deletions docs/resources/google_cloudkms_project_location_key_ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: About the google_cloudkms_project_location_key_ring resource
platform: gcp
---

## Syntax
A `google_cloudkms_project_location_key_ring` is used to test a Google ProjectLocationKeyRing resource

## Examples
```
describe google_cloudkms_project_location_key_ring(name: ' value_name') do
it { should exist }
its('name') { should cmp 'value_name' }
its('create_time') { should cmp 'value_createtime' }

end

describe google_cloudkms_project_location_key_ring(name: "does_not_exit") do
it { should_not exist }
end
```

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


* `name`: Output only. The resource name for the KeyRing in the format `projects/*/locations/*/keyRings/*`.

* `create_time`: Output only. The time at which this KeyRing was created.


## GCP Permissions

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

## Syntax
A `google_cloudkms_project_location_key_rings` is used to test a Google ProjectLocationKeyRing resource

## Examples
```
describe google_cloudkms_project_location_key_rings() do
it { should exist }
end
```

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

See [google_cloudkms_project_location_key_ring.md](google_cloudkms_project_location_key_ring.md) for more detailed information
* `names`: an array of `google_cloudkms_project_location_key_ring` name
* `create_times`: an array of `google_cloudkms_project_location_key_ring` create_time

## 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 [https://cloudkms.googleapis.com/](https://console.cloud.google.com/apis/library/cloudkms.googleapis.com/) is enabled for the current project.
57 changes: 57 additions & 0 deletions libraries/google_cloudkms_project_location_key_ring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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 cloudkms resources.
class CloudkmsProjectLocationKeyRing < GcpResourceBase
name 'google_cloudkms_project_location_key_ring'
desc 'ProjectLocationKeyRing'
supports platform: 'gcp'

attr_reader :params
attr_reader :name
attr_reader :create_time

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
@name = @fetched['name']
@create_time = @fetched['createTime']
end

def exists?
[email protected]?
end

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

private

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

def resource_base_url
'{{name}}'
end
end
81 changes: 81 additions & 0 deletions libraries/google_cloudkms_project_location_key_rings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 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 CloudkmsProjectLocationKeyRings < GcpResourceBase
name 'google_cloudkms_project_location_key_rings'
desc 'ProjectLocationKeyRing plural resource'
supports platform: 'gcp'

attr_reader :table

filter_table_config = FilterTable.create

filter_table_config.add(:names, field: :name)
filter_table_config.add(:create_times, field: :create_time)

filter_table_config.connect(self, :table)

def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
@table = fetch_wrapped_resource('projectLocationKeyRings')
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
{
'name' => ->(obj) { [:name, obj['name']] },
'createTime' => ->(obj) { [:create_time, obj['createTime']] },
}
end

private

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

def resource_base_url
'{{parent}}/keyRings'
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ----------------------------------------------------------------------------
#
# *** 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_cloudkms_project_location_key_ring resource.'

gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.')

project_location_key_ring = input('project_location_key_ring', value: {
"name": "value_name",
"parent": "value_parent",
"create_time": "value_createtime"
}, description: 'project_location_key_ring description')
control 'google_cloudkms_project_location_key_ring-1.0' do
impact 1.0
title 'google_cloudkms_project_location_key_ring resource test'

describe google_cloudkms_project_location_key_ring(name: project_location_key_ring['name']) do
it { should exist }
its('name') { should cmp project_location_key_ring['name'] }
its('create_time') { should cmp project_location_key_ring['create_time'] }

end

describe google_cloudkms_project_location_key_ring(name: "does_not_exit") do
it { should_not exist }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ----------------------------------------------------------------------------
#
# *** 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_cloudkms_project_location_key_rings resource.'

gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.')

project_location_key_ring = input('project_location_key_ring', value: {
"name": "value_name",
"parent": "value_parent",
"create_time": "value_createtime"
}, description: 'project_location_key_ring description')
control 'google_cloudkms_project_location_key_rings-1.0' do
impact 1.0
title 'google_cloudkms_project_location_key_rings resource test'

describe google_cloudkms_project_location_key_rings() do
it { should exist }
end
end