Skip to content

Commit

Permalink
Cleanup Go rewrite TODOs and remove unused fields (GoogleCloudPlatfor…
Browse files Browse the repository at this point in the history
  • Loading branch information
zli82016 authored Sep 6, 2024
1 parent 6231f4d commit 5cb12b8
Show file tree
Hide file tree
Showing 26 changed files with 128 additions and 1,248 deletions.
52 changes: 0 additions & 52 deletions mmv1/api/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import (

// Base class from which other Async classes can inherit.
type Async struct {
// Embed YamlValidator object
// google.YamlValidator

// Describes an operation
Operation *Operation

Expand All @@ -40,7 +37,6 @@ type Async struct {
PollAsync `yaml:",inline"`
}

// def allow?(method)
func (a Async) Allow(method string) bool {
return slices.Contains(a.Actions, strings.ToLower(method))
}
Expand All @@ -56,9 +52,7 @@ type Operation struct {
OpAsyncOperation `yaml:",inline"`
}

// def initialize(path, base_url, wait_ms, timeouts)
func NewOperation() *Operation {
// super()
op := new(Operation)
op.Timeouts = NewTimeouts()
return op
Expand Down Expand Up @@ -86,14 +80,6 @@ type OpAsync struct {
IncludeProject bool `yaml:"include_project"`
}

// def initialize(operation, result, status, error)
// super()
// @operation = operation
// @result = result
// @status = status
// @error = error
// end

type OpAsyncOperation struct {
Kind string

Expand All @@ -107,51 +93,23 @@ type OpAsyncOperation struct {
FullUrl string `yaml:"full_url"`
}

// def validate
// super

// check :kind, type: String
// check :path, type: String
// check :base_url, type: String
// check :wait_ms, type: Integer

// check :full_url, type: String

// conflicts %i[base_url full_url]
// end

// Represents the results of an Operation request
type OpAsyncResult struct {
ResourceInsideResponse bool `yaml:"resource_inside_response"`

Path string
}

// def initialize(path = nil, resource_inside_response = nil)
// super()
// @path = path
// @resource_inside_response = resource_inside_response
// end

// Provides information to parse the result response to check operation
// status
type OpAsyncStatus struct {
// google.YamlValidator

Path string

Complete bool

Allowed []bool
}

// def initialize(path, complete, allowed)
// super()
// @path = path
// @complete = complete
// @allowed = allowed
// end

// Provides information on how to retrieve errors of the executed operations
type OpAsyncError struct {
google.YamlValidator
Expand All @@ -161,12 +119,6 @@ type OpAsyncError struct {
Message string
}

// def initialize(path, message)
// super()
// @path = path
// @message = message
// end

// Async implementation for polling in Terraform
type PollAsync struct {
// Details how to poll for an eventually-consistent resource state.
Expand All @@ -179,10 +131,6 @@ type PollAsync struct {
// deleting a resource
CheckResponseFuncAbsence string `yaml:"check_response_func_absence"`

// Custom code to get a poll response, if needed.
// Will default to same logic as Read() to get current resource
CustomPollRead string `yaml:"custom_poll_read"`

// If true, will suppress errors from polling and default to the
// result of the final Read()
SuppressError bool `yaml:"suppress_error"`
Expand Down
85 changes: 0 additions & 85 deletions mmv1/api/object.go

This file was deleted.

39 changes: 9 additions & 30 deletions mmv1/api/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import (

// Represents a product to be managed
type Product struct {
NamedObject `yaml:",inline"`

// Inherited:
// The name of the product's API capitalised in the appropriate places.
// This isn't just the API name because it doesn't meaningfully separate
// words in the api name - "accesscontextmanager" vs "AccessContextManager"
// Example inputs: "Compute", "AccessContextManager"
// Name string
Name string

// original value of :name before the provider override happens
// same as :name if not overridden in provider
ApiName string `yaml:"api_name"`

// Display Name: The full name of the GCP product; eg "Cloud Bigtable"
DisplayName string `yaml:"display_name"`
Expand All @@ -41,23 +42,19 @@ type Product struct {

// The list of permission scopes available for the service
// For example: `https://www.googleapis.com/auth/compute`

Scopes []string

// The API versions of this product

Versions []*product.Version

// The base URL for the service API endpoint
// For example: `https://www.googleapis.com/compute/v1/`

BaseUrl string `yaml:"base_url"`

// A function reference designed for the rare case where you
// need to use retries in operation calls. Used for the service api
// as it enables itself (self referential) and can result in occasional
// failures on operation_get. see github.com/hashicorp/terraform-provider-google/issues/9489

OperationRetry string `yaml:"operation_retry"`

Async *Async
Expand All @@ -82,6 +79,10 @@ func (p *Product) UnmarshalYAML(unmarshal func(any) error) error {
}

func (p *Product) Validate() {
if len(p.Name) == 0 {
log.Fatalf("Missing `name` for product")
}

// product names must start with a capital
for i, ch := range p.Name {
if !unicode.IsUpper(ch) {
Expand Down Expand Up @@ -224,31 +225,9 @@ func (p *Product) TerraformName() string {
// Debugging Methods
// ====================

// def to_s
// // relies on the custom to_json definitions
// JSON.pretty_generate(self)
// end

// Prints a dot notation path to where the field is nested within the parent
// object when called on a property. eg: parent.meta.label.foo
// Redefined on Product to terminate the calls up the parent chain.
func (p Product) Lineage() string {
return p.Name
}

// def to_json(opts = nil)
// json_out = {}

// instance_variables.each do |v|
// if v == :@objects
// json_out['@resources'] = objects.to_h { |o| [o.name, o] }
// elsif instance_variable_get(v) == false || instance_variable_get(v).nil?
// // ignore false or missing because omitting them cleans up result
// // and both are the effective defaults of their types
// else
// json_out[v] = instance_variable_get(v)
// end
// end

// JSON.generate(json_out, opts)
// end
23 changes: 2 additions & 21 deletions mmv1/api/product/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,16 @@ import (
"golang.org/x/exp/slices"
)

// require 'api/object'

var ORDER = []string{"ga", "beta", "alpha", "private"}

// A version of the API for a given product / API group
// In GCP, different product versions are generally ordered where alpha is
// a superset of beta, and beta a superset of GA. Each version will have a
// different version url.
type Version struct {
// TODO: Should embed NamedObject or not?
// < Api::NamedObject
// include Comparable

// attr_reader
CaiBaseUrl string `yaml:"cai_base_url"`

// attr_accessor
BaseUrl string `yaml:"base_url"`

// attr_accessor
Name string
BaseUrl string `yaml:"base_url"`
Name string
}

func (v *Version) Validate(pName string) {
Expand All @@ -51,14 +40,6 @@ func (v *Version) Validate(pName string) {
}
}

// def to_s
// "//{name}: //{base_url}"
// end

// def <=>(other)
// ORDER.index(name) <=> ORDER.index(other.name) if other.is_a?(Version)
// end

func (v *Version) CompareTo(other *Version) int {
return slices.Index(ORDER, v.Name) - slices.Index(ORDER, other.Name)
}
Loading

0 comments on commit 5cb12b8

Please sign in to comment.