Skip to content

Commit

Permalink
refactor: use build tags with generator instead
Browse files Browse the repository at this point in the history
Signed-off-by: Samantha Coyle <[email protected]>
  • Loading branch information
sicoyle committed Dec 18, 2024
1 parent 39b98d3 commit 5f27d19
Show file tree
Hide file tree
Showing 15 changed files with 1,727 additions and 1,086 deletions.
60 changes: 30 additions & 30 deletions .build-tools/builtin-authentication-profiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ aws:
description: |
The AWS Region where the AWS resource is deployed to.
This will be marked required in Dapr 1.17.
example: '"us-east-1"'
example: us-east-1
- name: awsRegion
type: string
required: false
description: |
This maintains backwards compatibility with existing fields.
It will be deprecated as of Dapr 1.17. Use 'region' instead.
The AWS Region where the AWS resource is deployed to.
example: '"us-east-1"'
example: us-east-1
- name: accessKey
description: AWS access key associated with an IAM account
required: false
sensitive: true
example: '"AKIAIOSFODNN7EXAMPLE"'
example: AKIAIOSFODNN7EXAMPLE
- name: secretKey
description: The secret key associated with the access key
required: false
sensitive: true
example: '"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"'
example: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
- name: sessionToken
type: string
required: false
sensitive: true
description: |
AWS session token to use. A session token is only required if you are using
temporary security credentials.
example: '"TOKEN"'
example: TOKEN
- title: "AWS: Assume IAM Role"
description: |
Assume a specific IAM role. Note: This is only supported for Kafka and PostgreSQL.
Expand All @@ -45,21 +45,21 @@ aws:
required: true
description: |
The AWS Region where the AWS resource is deployed to.
example: '"us-east-1"'
example: us-east-1
- name: assumeRoleArn
type: string
required: false
description: |
IAM role that has access to AWS resource.
This is another option to authenticate with MSK and RDS Aurora aside from the AWS Credentials.
This will be marked required in Dapr 1.17.
example: '"arn:aws:iam::123456789:role/mskRole"'
example: arn:aws:iam::123456789:role/mskRole
- name: sessionName
type: string
description: |
The session name for assuming a role.
example: '"MyAppSession"'
default: '"DaprDefaultSession"'
example: MyAppSession
default: DaprDefaultSession
- title: "AWS: Credentials from Environment Variables"
description: Use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from the environment
- title: "AWS: IAM Roles Anywhere"
Expand Down Expand Up @@ -88,12 +88,12 @@ azuread:
- name: azureClientId
description: |
Client ID (application ID). Required if the service has multiple identities assigned.
example: '"c7dd251f-811f-4ba2-a905-acd4d3f8f08b"'
example: c7dd251f-811f-4ba2-a905-acd4d3f8f08b
- name: azureEnvironment
description: |
Optional name for the Azure environment if using a different Azure cloud
default: AzurePublicCloud
example: '"AzurePublicCloud"'
example: AzurePublicCloud
allowedValues:
- AzurePublicCloud
- AzureChinaCloud
Expand All @@ -105,21 +105,21 @@ azuread:
- name: azureTenantId
description: ID of the Azure AD tenant
required: true
example: '"cd4b2887-304c-47e1-b4d5-65447fdd542a"'
example: cd4b2887-304c-47e1-b4d5-65447fdd542a
- name: azureClientId
description: Client ID (application ID)
required: true
example: '"c7dd251f-811f-4ba2-a905-acd4d3f8f08b"'
example: c7dd251f-811f-4ba2-a905-acd4d3f8f08b
- name: azureClientSecret
description: Client secret (application password)
required: true
sensitive: true
example: '"Ecy3XG7zVZK3/vl/a2NSB+a1zXLa8RnMum/IgD0E"'
example: Ecy3XG7zVZK3/vl/a2NSB+a1zXLa8RnMum/IgD0E
- name: azureEnvironment
description: |
Optional name for the Azure environment if using a different Azure cloud
default: AzurePublicCloud
example: '"AzurePublicCloud"'
example: AzurePublicCloud
allowedValues:
- AzurePublicCloud
- AzureChinaCloud
Expand All @@ -131,11 +131,11 @@ azuread:
- name: azureTenantId
description: ID of the Azure AD tenant
required: true
example: '"cd4b2887-304c-47e1-b4d5-65447fdd542a"'
example: cd4b2887-304c-47e1-b4d5-65447fdd542a
- name: azureClientId
description: Client ID (application ID)
required: true
example: '"c7dd251f-811f-4ba2-a905-acd4d3f8f08b"'
example: c7dd251f-811f-4ba2-a905-acd4d3f8f08b
- name: azureCertificate
description: |
Certificate and private key (in either a PEM file containing both the certificate and key, or in PFX/PKCS#12 format)
Expand All @@ -146,16 +146,16 @@ azuread:
- name: azureCertificateFile
description: |
Path to PEM or PFX/PKCS#12 file on disk, containing the certificate and private key.
example: '"/path/to/file.pem"'
example: /path/to/file.pem
- name: azureCertificatePassword
description: Password for the certificate if encrypted.
sensitive: true
example: '"password"'
example: password
- name: azureEnvironment
description: |
Optional name for the Azure environment if using a different Azure cloud
default: AzurePublicCloud
example: '"AzurePublicCloud"'
example: AzurePublicCloud
allowedValues:
- AzurePublicCloud
- AzureChinaCloud
Expand All @@ -171,61 +171,61 @@ gcp:
sensitive: true
description: |
The GCP private key id. Replace with the value of "private_key_id" field of the Service Account Key file.
example: '"privateKeyID"'
example: privateKeyID
- name: privateKey
required: true
sensitive: true
description: |
The GCP credentials private key. Replace with the value of "private_key" field of the Service Account Key file.
example: '"-----BEGIN PRIVATE KEY-----\nMIIE...\\n-----END PRIVATE KEY-----\n"'
example: -----BEGIN PRIVATE KEY-----\nMIIE...\\n-----END PRIVATE KEY-----\n
- name: type
type: string
required: false
description: |
The GCP credentials type.
example: '"service_account"'
example: service_account
allowedValues:
- service_account
- name: projectID
type: string
required: true
description: |
GCP project id.
example: '"projectID"'
example: projectID
- name: clientEmail
type: string
required: true
description: |
GCP client email.
example: '"[email protected]"'
example: [email protected]
- name: clientID
type: string
required: true
description: |
The GCP client ID.
example: '"0123456789-0123456789"'
example: 0123456789-0123456789
- name: authURI
type: string
required: false
description: |
The GCP account OAuth2 authorization server endpoint URI.
example: '"https://accounts.google.com/o/oauth2/auth"'
example: https://accounts.google.com/o/oauth2/auth
- name: tokenURI
type: string
required: false
description: |
The GCP account token server endpoint URI.
example: '"https://oauth2.googleapis.com/token"'
example: https://oauth2.googleapis.com/token
- name: authProviderX509CertURL
type: string
required: false
description: |
The GCP URL of the public x509 certificate, used to verify the signature
on JWTs, such as ID tokens, signed by the authentication provider.
example: '"https://www.googleapis.com/oauth2/v1/certs"'
example: https://www.googleapis.com/oauth2/v1/certs
- name: clientX509CertURL
type: string
required: false
description: |
The GCP URL of the public x509 certificate, used to verify JWTs signed by the client.
example: '"https://www.googleapis.com/robot/v1/metadata/x509/<PROJECT_NAME>.iam.gserviceaccount.com"'
example: https://www.googleapis.com/robot/v1/metadata/x509/<PROJECT_NAME>.iam.gserviceaccount.com
4 changes: 2 additions & 2 deletions .build-tools/cmd/cmd-bundle-component-metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ var bundleComponentMetadataCmd = &cobra.Command{
Components: make([]*metadataschema.ComponentMetadata, 0, len(list)),
}
for _, component := range list {
componentMetadata, err := parser.LoadForComponent(component)
if err != nil {
componentMetadata, loadErr := parser.LoadForComponent(component)
if loadErr != nil {
panic(fmt.Errorf("failed to load metadata for component %s: %w", component, err))
}
if componentMetadata == nil {
Expand Down
147 changes: 147 additions & 0 deletions .build-tools/cmd/cmd-gen-component-metadata-ast-mocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"go/ast"
"go/token"
)

func createMockASTFileWithFunc(funcName string, found bool) *ast.File {
if !found {
return &ast.File{}
}
// Create a mock AST with the specified function name
return &ast.File{
Decls: []ast.Decl{
&ast.FuncDecl{
Name: &ast.Ident{Name: funcName},
Body: createValidFunctionBody(),
},
},
}
}

func createValidFunctionBody() *ast.BlockStmt {
return &ast.BlockStmt{
List: []ast.Stmt{
&ast.ReturnStmt{
Results: []ast.Expr{createValidCompositeLit()},
},
},
}
}

func createValidCompositeLit() *ast.CompositeLit {
return &ast.CompositeLit{
// Using SelectorExpr for the type field to match 'Binding' type
Type: &ast.SelectorExpr{
X: &ast.Ident{Name: "metadataschema"}, // Package name
Sel: &ast.Ident{Name: "Binding"}, // Type name
},
Elts: []ast.Expr{
&ast.KeyValueExpr{
Key: &ast.Ident{Name: "Input"},
Value: &ast.Ident{Name: "true"}, // Keep it as an Ident (literal bool type)
},
&ast.KeyValueExpr{
Key: &ast.Ident{Name: "Output"},
Value: &ast.Ident{Name: "false"}, // Keep it as an Ident (literal bool type)
},
&ast.KeyValueExpr{
Key: &ast.Ident{Name: "Operations"},
Value: &ast.CompositeLit{
Elts: []ast.Expr{
&ast.CompositeLit{
Elts: []ast.Expr{
&ast.KeyValueExpr{
Key: &ast.Ident{Name: "Name"},
Value: &ast.BasicLit{Kind: token.STRING, Value: `"create"`}, // Correct string literal
},
&ast.KeyValueExpr{
Key: &ast.Ident{Name: "Description"},
Value: &ast.BasicLit{Kind: token.STRING, Value: `"Create blob"`}, // Correct string literal
},
},
},
&ast.CompositeLit{
Elts: []ast.Expr{
&ast.KeyValueExpr{
Key: &ast.Ident{Name: "Name"},
Value: &ast.BasicLit{Kind: token.STRING, Value: `"get"`}, // Correct string literal
},
&ast.KeyValueExpr{
Key: &ast.Ident{Name: "Description"},
Value: &ast.BasicLit{Kind: token.STRING, Value: `"Get blob"`}, // Correct string literal
},
},
},
},
},
},
},
}
}

func createInvalidCompositeLit() *ast.CompositeLit {
return &ast.CompositeLit{
Type: &ast.Ident{Name: "NotBinding"},
Elts: []ast.Expr{
&ast.KeyValueExpr{
Key: &ast.Ident{Name: "InvalidInput"},
Value: &ast.Ident{Name: "true"},
},
&ast.KeyValueExpr{
Key: &ast.Ident{Name: "InvalidOutput"},
Value: &ast.Ident{Name: "false"},
},
},
}
}

func createKeyValueExpr(key, value string) *ast.KeyValueExpr {
return &ast.KeyValueExpr{
Key: &ast.Ident{Name: key},
Value: &ast.BasicLit{Kind: token.STRING, Value: value},
}
}

func createInvalidKeyValueExpr(value string) *ast.KeyValueExpr {
return &ast.KeyValueExpr{
Key: nil, // this is invalid intentionally and should actually be &ast.Ident{Name: key},
Value: &ast.Ident{Name: value},
}
}

func createBodyWithoutBindingReturn() *ast.BlockStmt {
return &ast.BlockStmt{
List: []ast.Stmt{
&ast.ReturnStmt{
Results: []ast.Expr{
// createNonBindingReturn(),
},
},
},
}
}

// Helper function to create a CompositeLit for a single BindingOperation
func createBindingOperationCompositeLit(name, description string) *ast.CompositeLit {
return &ast.CompositeLit{
Elts: []ast.Expr{
createKeyValueExpr("Name", name),
createKeyValueExpr("Description", description),
},
}
}
Loading

0 comments on commit 5f27d19

Please sign in to comment.