Skip to content

Commit

Permalink
Merge pull request #502 from inspec/CHEF-5566-MAGIC-MODULE-vertex_ai-…
Browse files Browse the repository at this point in the history
…MetadataStores__context

CHEF-5566-MAGIC-MODULE-vertex_ai-MetadataStores__context - Resource Implementation
  • Loading branch information
sa-progress authored Oct 10, 2023
2 parents cc04614 + 5a2e8b6 commit 77119c6
Show file tree
Hide file tree
Showing 9 changed files with 444 additions and 1 deletion.
15 changes: 14 additions & 1 deletion build/inspec/test/integration/configuration/mm-attributes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -802,4 +802,17 @@ datasets_annotation_spec:
parent: "projects/165434197229/locations/us-central1/datasets/1044994542735982592/annotationSpecs/"
etag : "value_etag"
create_time : "value_createtime"
annotation_schema_uri : "value_annotationschemauri"
annotation_schema_uri : "value_annotationschemauri"

metadata_stores_context:
name : "autologging-experiment-w0apl7la-autologging-tf-experiment-w0apl7la"
region : "us-central1"
parent : "projects/165434197229/locations/us-central1/metadataStores/default/contexts/"
metadataStore: "default",
schema_title : "value_schematitle"
etag : "value_etag"
description : "value_description"
display_name : "autologging-tf-experiment-w0apl7la"
schema_version : "value_schemaversion"
create_time : "value_createtime"
update_time : "value_updatetime"
60 changes: 60 additions & 0 deletions docs/resources/google_vertex_ai_metadata_stores_context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: About the google_vertex_ai_metadata_stores_context resource
platform: gcp
---

## Syntax
A `google_vertex_ai_metadata_stores_context` is used to test a Google MetadataStoresContext resource

## Examples
```
describe google_vertex_ai_metadata_stores_context(name: "projects/#{gcp_project_id}/locations/#{metadata_stores_context['region']}/metadataStores/#{metadata_stores_context['metadataStore']}/contexts/#{metadata_stores_context['name']}", region: ' value_region') do
it { should exist }
its('name') { should cmp 'value_name' }
its('schema_title') { should cmp 'value_schematitle' }
its('etag') { should cmp 'value_etag' }
its('description') { should cmp 'value_description' }
its('display_name') { should cmp 'value_displayname' }
its('schema_version') { should cmp 'value_schemaversion' }
its('create_time') { should cmp 'value_createtime' }
its('update_time') { should cmp 'value_updatetime' }
end
describe google_vertex_ai_metadata_stores_context(name: "does_not_exit", region: ' value_region') do
it { should_not exist }
end
```

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


* `name`: Immutable. The resource name of the Context.

* `schema_title`: The title of the schema describing the metadata. Schema title and version is expected to be registered in earlier Create Schema calls. And both are used together as unique identifiers to identify schemas within the local metadata store.

* `etag`: An eTag used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens.

* `description`: Description of the Context

* `display_name`: User provided display name of the Context. May be up to 128 Unicode characters.

* `schema_version`: The version of the schema in schema_name to use. Schema title and version is expected to be registered in earlier Create Schema calls. And both are used together as unique identifiers to identify schemas within the local metadata store.

* `create_time`: Output only. Timestamp when this Context was created.

* `labels`: The labels with user-defined metadata to organize your Contexts. Label keys and values can be no longer than 64 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. No more than 64 user labels can be associated with one Context (System labels are excluded).

* `additional_properties`:

* `metadata`: Properties of the Context. Top level metadata keys' heading and trailing spaces will be trimmed. The size of this field should not exceed 200KB.

* `additional_properties`: Properties of the object.

* `update_time`: Output only. Timestamp when this Context was last updated.

* `parent_contexts`: Output only. A list of resource names of Contexts that are parents of this Context. A Context may have at most 10 parent_contexts.


## GCP Permissions
36 changes: 36 additions & 0 deletions docs/resources/google_vertex_ai_metadata_stores_contexts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: About the google_vertex_ai_metadata_stores_contexts resource
platform: gcp
---

## Syntax
A `google_vertex_ai_metadata_stores_contexts` is used to test a Google MetadataStoresContext resource

## Examples
```
describe google_vertex_ai_metadata_stores_contexts(parent: "projects/#{gcp_project_id}/locations/#{metadata_stores_context['region']}/metadataStores/#{metadata_stores_context['metadataStore']}", region: ' value_region') do
it { should exist }
end
```

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

See [google_vertex_ai_metadata_stores_context.md](google_vertex_ai_metadata_stores_context.md) for more detailed information
* `names`: an array of `google_vertex_ai_metadata_stores_context` name
* `schema_titles`: an array of `google_vertex_ai_metadata_stores_context` schema_title
* `etags`: an array of `google_vertex_ai_metadata_stores_context` etag
* `descriptions`: an array of `google_vertex_ai_metadata_stores_context` description
* `display_names`: an array of `google_vertex_ai_metadata_stores_context` display_name
* `schema_versions`: an array of `google_vertex_ai_metadata_stores_context` schema_version
* `create_times`: an array of `google_vertex_ai_metadata_stores_context` create_time
* `labels`: an array of `google_vertex_ai_metadata_stores_context` labels
* `metadata`: an array of `google_vertex_ai_metadata_stores_context` metadata
* `update_times`: an array of `google_vertex_ai_metadata_stores_context` update_time
* `parent_contexts`: an array of `google_vertex_ai_metadata_stores_context` parent_contexts

## 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
34 changes: 34 additions & 0 deletions libraries/google/vertexai/property/metadatastorescontext_labels.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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 VertexAI
module Property
class MetadataStoresContextLabels
attr_reader :additional_properties

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

def to_s
"#{@parent_identifier} MetadataStoresContextLabels"
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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 VertexAI
module Property
class MetadataStoresContextMetadata
attr_reader :additional_properties

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

def to_s
"#{@parent_identifier} MetadataStoresContextMetadata"
end
end
end
end
end
77 changes: 77 additions & 0 deletions libraries/google_vertex_ai_metadata_stores_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 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/vertexai/property/metadatastorescontext_labels'
require 'google/vertexai/property/metadatastorescontext_metadata'

# A provider to manage Vertex AI resources.
class VertexAIMetadataStoresContext < GcpResourceBase
name 'google_vertex_ai_metadata_stores_context'
desc 'MetadataStoresContext'
supports platform: 'gcp'

attr_reader :params
attr_reader :name
attr_reader :schema_title
attr_reader :etag
attr_reader :description
attr_reader :display_name
attr_reader :schema_version
attr_reader :create_time
attr_reader :labels
attr_reader :metadata
attr_reader :update_time
attr_reader :parent_contexts

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']
@schema_title = @fetched['schemaTitle']
@etag = @fetched['etag']
@description = @fetched['description']
@display_name = @fetched['displayName']
@schema_version = @fetched['schemaVersion']
@create_time = @fetched['createTime']
@labels = GoogleInSpec::VertexAI::Property::MetadataStoresContextLabels.new(@fetched['labels'], to_s)
@metadata = GoogleInSpec::VertexAI::Property::MetadataStoresContextMetadata.new(@fetched['metadata'], to_s)
@update_time = @fetched['updateTime']
@parent_contexts = @fetched['parentContexts']
end

def exists?
!@fetched.nil?
end

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

private

def product_url(_ = nil)
'https://{{region}}-aiplatform.googleapis.com/v1/'
end

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

attr_reader :table

filter_table_config = FilterTable.create

filter_table_config.add(:names, field: :name)
filter_table_config.add(:schema_titles, field: :schema_title)
filter_table_config.add(:etags, field: :etag)
filter_table_config.add(:descriptions, field: :description)
filter_table_config.add(:display_names, field: :display_name)
filter_table_config.add(:schema_versions, field: :schema_version)
filter_table_config.add(:create_times, field: :create_time)
filter_table_config.add(:labels, field: :labels)
filter_table_config.add(:metadata, field: :metadata)
filter_table_config.add(:update_times, field: :update_time)
filter_table_config.add(:parent_contexts, field: :parent_contexts)

filter_table_config.connect(self, :table)

def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
@table = fetch_wrapped_resource('contexts')
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) { return :name, obj['name'] },
'schemaTitle' => ->(obj) { return :schema_title, obj['schemaTitle'] },
'etag' => ->(obj) { return :etag, obj['etag'] },
'description' => ->(obj) { return :description, obj['description'] },
'displayName' => ->(obj) { return :display_name, obj['displayName'] },
'schemaVersion' => ->(obj) { return :schema_version, obj['schemaVersion'] },
'createTime' => ->(obj) { return :create_time, obj['createTime'] },
'labels' => ->(obj) { return :labels, GoogleInSpec::VertexAI::Property::MetadataStoresContextLabels.new(obj['labels'], to_s) },
'metadata' => ->(obj) { return :metadata, GoogleInSpec::VertexAI::Property::MetadataStoresContextMetadata.new(obj['metadata'], to_s) },
'updateTime' => ->(obj) { return :update_time, obj['updateTime'] },
'parentContexts' => ->(obj) { return :parent_contexts, obj['parentContexts'] },
}
end

private

def product_url(_ = nil)
'https://{{region}}-aiplatform.googleapis.com/v1/'
end

def resource_base_url
'{{parent}}/contexts'
end
end
Loading

0 comments on commit 77119c6

Please sign in to comment.