Skip to content

Commit

Permalink
Merge branch 'main' into add-vertex-ai-model-COPY
Browse files Browse the repository at this point in the history
  • Loading branch information
BBBmau committed May 8, 2024
2 parents eb3ffc6 + e1dd414 commit 81902a3
Show file tree
Hide file tree
Showing 35 changed files with 447 additions and 1,501 deletions.
9 changes: 1 addition & 8 deletions .ci/magician/github/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
utils "magician/utility"
"math/rand"
"time"

"golang.org/x/exp/maps"
)

var (
Expand Down Expand Up @@ -72,11 +70,6 @@ var (
startDate: newDate(2024, 4, 20, pdtLoc),
endDate: newDate(2024, 4, 27, pdtLoc),
},
{
id: "ScottSuarez",
startDate: newDate(2024, 4, 30, pdtLoc),
endDate: newDate(2024, 7, 31, pdtLoc),
},
}
)

Expand Down Expand Up @@ -165,7 +158,7 @@ func GetRandomReviewer() string {
}

func AvailableReviewers() []string {
return available(time.Now(), maps.Keys(reviewerRotation), onVacationReviewers)
return available(time.Now(), reviewerRotation, onVacationReviewers)
}

func available(nowTime time.Time, allReviewers []string, vacationList []onVacationReviewer) []string {
Expand Down
3 changes: 2 additions & 1 deletion .ci/magician/github/membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"golang.org/x/exp/slices"
)

func TestTrustedContributors(t *testing.T) {
Expand All @@ -32,7 +33,7 @@ func TestTrustedContributors(t *testing.T) {

func TestOnVacationReviewers(t *testing.T) {
for _, member := range onVacationReviewers {
if !IsCoreReviewer(member.id) {
if !slices.Contains(reviewerRotation, member.id) {
t.Fatalf(`%v is not on reviewerRotation list`, member)
}
}
Expand Down
3 changes: 1 addition & 2 deletions .ci/magician/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ require (
)

require (
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v61 v61.0.0
github.com/google/go-cmp v0.5.9
github.com/otiai10/copy v1.12.0
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v2 v2.4.0
Expand Down
47 changes: 6 additions & 41 deletions mmv1/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ type Resource struct {

// The compiler to generate the downstream files, for example "terraformgoogleconversion-codegen".
Compiler string

ImportPath string
}

func (r *Resource) UnmarshalYAML(n *yaml.Node) error {
Expand Down Expand Up @@ -975,46 +973,13 @@ func (r Resource) GetIdFormat() string {
// ====================
// Template Methods
// ====================
// Functions used to create slices of resource properties that could not otherwise be called from within generating templates.

func (r Resource) ReadProperties() []*Type {
return google.Reject(r.GettableProperties(), func(p *Type) bool {
return p.IgnoreRead
})
}
// 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 Resource to terminate the calls up the parent chain.

// checks a resource for if it has properties that have FlattenObject=true on fields where IgnoreRead=false
// used to decide whether or not to import "google.golang.org/api/googleapi"
func (r Resource) FlattenedProperties() []*Type {
return google.Select(r.ReadProperties(), func(p *Type) bool {
return p.FlattenObject
})
}

func (r Resource) IsInIdentity(t Type) bool {
for _, i := range r.GetIdentity() {
if i.Name == t.Name {
return true
}
}
return false
}

func OrderProperties(props []*Type) []*Type {
req := google.Select(props, func(p *Type) bool {
return p.Required
})
slices.SortFunc(req, CompareByName)
rest := google.Reject(props, func(p *Type) bool {
return p.Output || p.Required
})
slices.SortFunc(rest, CompareByName)
output := google.Select(props, func(p *Type) bool {
return p.Output
})
slices.SortFunc(output, CompareByName)
returnProps := google.Concat(req, rest)
return google.Concat(returnProps, output)
}

func CompareByName(a, b *Type) int {
return strings.Compare(a.Name, b.Name)
return google.Select(google.Reject(r.GettableProperties(), func(p *Type) bool { return p.IgnoreRead }), func(p *Type) bool { return p.FlattenObject })
}
9 changes: 5 additions & 4 deletions mmv1/api/resource/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (e *Examples) UnmarshalYAML(n *yaml.Node) error {

// Executes example templates for documentation and tests
func (e *Examples) SetHCLText() {
e.DocumentationHCLText = ExecuteTemplate(e, e.ConfigPath)
e.DocumentationHCLText = ExecuteHCL(e)

copy := e
// Override vars to inject test values into configs - will have
Expand Down Expand Up @@ -206,10 +206,11 @@ func (e *Examples) SetHCLText() {
copy.Vars[key] = fmt.Sprintf("%%{%s}", key)
}

e.TestHCLText = ExecuteTemplate(copy, copy.ConfigPath)
e.TestHCLText = ExecuteHCL(copy)
}

func ExecuteTemplate(e any, templatePath string) string {
func ExecuteHCL(e *Examples) string {
templatePath := e.ConfigPath
templates := []string{
templatePath,
}
Expand Down Expand Up @@ -363,7 +364,7 @@ func (e *Examples) OiCSLink() string {
}

func (e *Examples) TestSlug(productName, resourceName string) string {
ret := fmt.Sprintf("%s%s_%sExample", productName, resourceName, google.Camelize(e.Name, "lower"))
ret := fmt.Sprintf("%s%s_%sExample", productName, resourceName, google.Camelize(e.Name, "upper"))
return ret
}

Expand Down
7 changes: 0 additions & 7 deletions mmv1/products/bigquery/Table.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,3 @@ properties:
in the namespaced format, for example "123456789012/environment" where 123456789012 is the
ID of the parent organization or project resource for this tag key. Tag value is expected
to be the short name, for example "Production".
virtual_fields:
- !ruby/object:Api::Type::Boolean
name: 'allow_resource_tags_on_deletion'
min_version: beta
description: |
Whether or not to allow table deletion when there are still resource tags attached.
default_value: false
7 changes: 0 additions & 7 deletions mmv1/products/integrationconnectors/Connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ examples:
primary_resource_id: "pubsubconnection"
vars:
connection_name: "test-pubsub"
skip_test: true
ignore_read_extra:
- 'status.0.description'
- !ruby/object:Provider::Terraform::Examples
Expand All @@ -51,7 +50,6 @@ examples:
vars:
connection_name: "test-zendesk"
secret_id: "test-secret"
skip_test: true
ignore_read_extra:
- 'status.0.description'
- !ruby/object:Provider::Terraform::Examples
Expand All @@ -61,7 +59,6 @@ examples:
connection_name: "test-zendesk"
secret_id: "test-secret"
skip_docs: true
skip_test: true
ignore_read_extra:
- 'status.0.description'
- !ruby/object:Provider::Terraform::Examples
Expand All @@ -71,7 +68,6 @@ examples:
connection_name: "test-box"
secret_id: "test-secret"
skip_docs: true
skip_test: true
ignore_read_extra:
- 'status.0.description'
- !ruby/object:Provider::Terraform::Examples
Expand All @@ -81,7 +77,6 @@ examples:
connection_name: "test-box"
secret_id: "test-secret"
skip_docs: true
skip_test: true
ignore_read_extra:
- 'status.0.description'
- !ruby/object:Provider::Terraform::Examples
Expand All @@ -91,7 +86,6 @@ examples:
connection_name: "test-box"
secret_id: "test-secret"
skip_docs: true
skip_test: true
ignore_read_extra:
- 'status.0.description'
- !ruby/object:Provider::Terraform::Examples
Expand All @@ -101,7 +95,6 @@ examples:
connection_name: "test-box"
secret_id: "test-secret"
skip_docs: true
skip_test: true
ignore_read_extra:
- 'status.0.description'
async: !ruby/object:Api::OpAsync
Expand Down
File renamed without changes.
105 changes: 50 additions & 55 deletions mmv1/provider/template_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package provider
import (
"bytes"
"errors"
"fmt"
"go/format"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -65,18 +63,16 @@ func wrapMultipleParams(params ...interface{}) (map[string]interface{}, error) {
}

var TemplateFunctions = template.FuncMap{
"title": google.SpaceSeparatedTitle,
"replace": strings.Replace,
"camelize": google.Camelize,
"underscore": google.Underscore,
"plural": google.Plural,
"contains": strings.Contains,
"join": strings.Join,
"lower": strings.ToLower,
"upper": strings.ToUpper,
"dict": wrapMultipleParams,
"format2regex": google.Format2Regex,
"orderProperties": api.OrderProperties,
"title": google.SpaceSeparatedTitle,
"replace": strings.Replace,
"camelize": google.Camelize,
"underscore": google.Underscore,
"plural": google.Plural,
"contains": strings.Contains,
"join": strings.Join,
"lower": strings.ToLower,
"upper": strings.ToUpper,
"dict": wrapMultipleParams,
}

var GA_VERSION = "ga"
Expand All @@ -103,13 +99,11 @@ func NewTemplateData(outputFolder string, version product.Version) *TemplateData
func (td *TemplateData) GenerateResourceFile(filePath string, resource api.Resource) {
templatePath := "templates/terraform/resource.go.tmpl"
templates := []string{
templatePath,
"templates/terraform/schema_property.go.tmpl",
"templates/terraform/schema_subresource.go.tmpl",
templatePath,
"templates/terraform/expand_resource_ref.tmpl",
"templates/terraform/custom_flatten/go/bigquery_table_ref.go.tmpl",
"templates/terraform/flatten_property_method.go.tmpl",
"templates/terraform/expand_property_method.go.tmpl",
}
td.GenerateFile(filePath, templatePath, resource, true, templates...)
}
Expand All @@ -120,6 +114,7 @@ func (td *TemplateData) GenerateDocumentationFile(filePath string, resource api.
templatePath,
"templates/terraform/property_documentation.html.markdown.tmpl",
"templates/terraform/nested_property_documentation.html.markdown.tmpl",
templatePath,
}
td.GenerateFile(filePath, templatePath, resource, false, templates...)
}
Expand All @@ -131,21 +126,22 @@ func (td *TemplateData) GenerateTestFile(filePath string, resource api.Resource)
templatePath,
}
tmplInput := TestInput{
Res: resource,
ImportPath: td.ImportPath(),
PROJECT_NAME: "my-project-name",
CREDENTIALS: "my/credentials/filename.json",
REGION: "us-west1",
ORG_ID: "123456789",
ORG_DOMAIN: "example.com",
ORG_TARGET: "123456789",
PROJECT_NUMBER: "1111111111111",
BILLING_ACCT: "000000-0000000-0000000-000000",
MASTER_BILLING_ACCT: "000000-0000000-0000000-000000",
SERVICE_ACCT: "[email protected]",
CUST_ID: "A01b123xz",
IDENTITY_USER: "cloud_identity_user",
PAP_DESCRIPTION: "description",
Res: resource,
ImportPath: td.ImportPath(),
PROJECT_NAME: "my-project-name",
FIRESTORE_PROJECT_NAME: "my-project-name",
CREDENTIALS: "my/credentials/filename.json",
REGION: "us-west1",
ORG_ID: "123456789",
ORG_DOMAIN: "example.com",
ORG_TARGET: "123456789",
PROJECT_NUMBER: "1111111111111",
BILLING_ACCT: "000000-0000000-0000000-000000",
MASTER_BILLING_ACCT: "000000-0000000-0000000-000000",
SERVICE_ACCT: "[email protected]",
CUST_ID: "A01b123xz",
IDENTITY_USER: "cloud_identity_user",
PAP_DESCRIPTION: "description",
}

td.GenerateFile(filePath, templatePath, tmplInput, true, templates...)
Expand All @@ -168,14 +164,12 @@ func (td *TemplateData) GenerateFile(filePath, templatePath string, input any, g

sourceByte := contents.Bytes()

if goFormat {
formattedByte, err := format.Source(sourceByte)
if err != nil {
glog.Error(fmt.Errorf("error formatting %s: %s", filePath, err))
} else {
sourceByte = formattedByte
}
}
// if goFormat {
// sourceByte, err = format.Source(sourceByte)
// if err != nil {
// glog.Error(fmt.Errorf("error formatting %s", filePath))
// }
// }

err = os.WriteFile(filePath, sourceByte, 0644)
if err != nil {
Expand Down Expand Up @@ -282,19 +276,20 @@ func (td *TemplateData) ImportPath() string {
}

type TestInput struct {
Res api.Resource
ImportPath string
PROJECT_NAME string
CREDENTIALS string
REGION string
ORG_ID string
ORG_DOMAIN string
ORG_TARGET string
PROJECT_NUMBER string
BILLING_ACCT string
MASTER_BILLING_ACCT string
SERVICE_ACCT string
CUST_ID string
IDENTITY_USER string
PAP_DESCRIPTION string
Res api.Resource
ImportPath string
PROJECT_NAME string
FIRESTORE_PROJECT_NAME string
CREDENTIALS string
REGION string
ORG_ID string
ORG_DOMAIN string
ORG_TARGET string
PROJECT_NUMBER string
BILLING_ACCT string
MASTER_BILLING_ACCT string
SERVICE_ACCT string
CUST_ID string
IDENTITY_USER string
PAP_DESCRIPTION string
}
Loading

0 comments on commit 81902a3

Please sign in to comment.