diff --git a/.build-tools/builtin-authentication-profiles.yaml b/.build-tools/builtin-authentication-profiles.yaml new file mode 100644 index 0000000000..81e07c3635 --- /dev/null +++ b/.build-tools/builtin-authentication-profiles.yaml @@ -0,0 +1,97 @@ +aws: + - title: "AWS: Access Key ID and Secret Access Key" + description: | + Authenticate using an Access Key ID and Secret Access Key included in the metadata + metadata: + - name: accessKey + description: AWS access key associated with an IAM account + required: true + sensitive: true + example: '"AKIAIOSFODNN7EXAMPLE"' + - name: secretKey + description: The secret key associated with the access key + required: true + sensitive: true + example: '"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"' + - title: "AWS: Credentials from Environment Variables" + description: Use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from the environment + +azuread: + - title: "Azure AD: Managed identity" + description: Authenticate using Azure AD and a managed identity. + metadata: + - name: azureClientId + description: | + Client ID (application ID). Required if the service has multiple identities assigned. + 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"' + allowedValues: + - AzurePublicCloud + - AzureChinaCloud + - AzureUSGovernmentCloud + - title: "Azure AD: Client credentials" + description: | + Authenticate using Azure AD with client credentials, also known as "service principals". + metadata: + - name: azureTenantId + description: ID of the Azure AD tenant + required: true + example: '"cd4b2887-304c-47e1-b4d5-65447fdd542a"' + - name: azureClientId + description: Client ID (application ID) + required: true + example: '"c7dd251f-811f-4ba2-a905-acd4d3f8f08b"' + - name: azureClientSecret + description: Client secret (application password) + required: true + sensitive: true + 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"' + allowedValues: + - AzurePublicCloud + - AzureChinaCloud + - AzureUSGovernmentCloud + - title: "Azure AD: Client certificate" + description: | + Authenticate using Azure AD with a client certificate. One of "azureCertificate" and "azureCertificateFile" is required. + metadata: + - name: azureTenantId + description: ID of the Azure AD tenant + required: true + example: '"cd4b2887-304c-47e1-b4d5-65447fdd542a"' + - name: azureClientId + description: Client ID (application ID) + required: true + 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) + sensitive: true + example: | + "-----BEGIN PRIVATE KEY-----\n MIIEvgI... \n -----END PRIVATE KEY----- + \n -----BEGIN CERTIFICATE----- \n MIICoTC... \n -----END CERTIFICATE----- \n" + - name: azureCertificateFile + description: | + Path to PEM or PFX/PKCS#12 file on disk, containing the certificate and private key. + example: '"/path/to/file.pem"' + - name: azureCertificatePassword + description: Password for the certificate if encrypted. + sensitive: true + example: '"password"' + - name: azureEnvironment + description: | + Optional name for the Azure environment if using a different Azure cloud + default: AzurePublicCloud + example: '"AzurePublicCloud"' + allowedValues: + - AzurePublicCloud + - AzureChinaCloud + - AzureUSGovernmentCloud diff --git a/.build-tools/component-folders.json b/.build-tools/component-folders.json deleted file mode 100644 index ecea136ffb..0000000000 --- a/.build-tools/component-folders.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "componentFolders": [ - "bindings", - "configuration", - "crypto", - "lock", - "middleware/http", - "nameresolution", - "pubsub", - "secretstores", - "state", - "workflows" - ], - "excludeFolders": [ - "bindings/alicloud", - "bindings/aws", - "bindings/azure", - "bindings/gcp", - "bindings/huawei", - "bindings/rethinkdb", - "bindings/twilio", - "bindings/zeebe", - "configuration/azure", - "configuration/redis/internal", - "crypto/azure", - "crypto/kubernetes", - "pubsub/aws", - "pubsub/azure", - "pubsub/azure/servicebus", - "pubsub/gcp", - "secretstores/alicloud", - "secretstores/aws", - "secretstores/azure", - "secretstores/gcp", - "secretstores/hashicorp", - "secretstores/huaweicloud", - "secretstores/local", - "state/alicloud", - "state/aws", - "state/azure", - "state/gcp", - "state/hashicorp", - "state/oci", - "state/utils" - ] -} diff --git a/.build-tools/component-folders.yaml b/.build-tools/component-folders.yaml new file mode 100644 index 0000000000..13b0882176 --- /dev/null +++ b/.build-tools/component-folders.yaml @@ -0,0 +1,43 @@ +componentFolders: + - bindings + - configuration + - crypto + - lock + - middleware/http + - nameresolution + - pubsub + - secretstores + - state + - workflows + +excludeFolders: + - bindings/alicloud + - bindings/aws + - bindings/azure + - bindings/gcp + - bindings/huawei + - bindings/rethinkdb + - bindings/twilio + - bindings/zeebe + - configuration/azure + - configuration/redis/internal + - crypto/azure + - crypto/kubernetes + - pubsub/aws + - pubsub/azure + - pubsub/azure/servicebus + - pubsub/gcp + - secretstores/alicloud + - secretstores/aws + - secretstores/azure + - secretstores/gcp + - secretstores/hashicorp + - secretstores/huaweicloud + - secretstores/local + - state/alicloud + - state/aws + - state/azure + - state/gcp + - state/hashicorp + - state/oci + - state/utils diff --git a/.build-tools/go.mod b/.build-tools/go.mod index a75f66cde6..6b9370e53b 100644 --- a/.build-tools/go.mod +++ b/.build-tools/go.mod @@ -8,6 +8,7 @@ require ( github.com/spf13/cobra v1.6.1 github.com/xeipuuv/gojsonschema v1.2.1-0.20201027075954-b076d39a02e5 golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 + gopkg.in/yaml.v3 v3.0.1 sigs.k8s.io/yaml v1.3.0 ) diff --git a/.build-tools/main.go b/.build-tools/main.go index fcfbf4adb3..ee602c3b3a 100644 --- a/.build-tools/main.go +++ b/.build-tools/main.go @@ -15,28 +15,39 @@ package main import ( _ "embed" - "encoding/json" + + "gopkg.in/yaml.v3" "github.com/dapr/components-contrib/build-tools/cmd" + "github.com/dapr/components-contrib/build-tools/pkg/metadataschema" ) -//go:embed component-folders.json -var componentFoldersJSON []byte +var ( + //go:embed component-folders.yaml + componentFoldersYAML []byte + //go:embed builtin-authentication-profiles.yaml + builtinAuthenticationProfilesYAML []byte +) -func init() { - parsed := struct { - ComponentFolders []string `json:"componentFolders"` - ExcludeFolders []string `json:"excludeFolders"` +func main() { + // Parse component-folders.json + parsedComponentFolders := struct { + ComponentFolders []string `json:"componentFolders" yaml:"componentFolders"` + ExcludeFolders []string `json:"excludeFolders" yaml:"excludeFolders"` }{} - err := json.Unmarshal(componentFoldersJSON, &parsed) + err := yaml.Unmarshal(componentFoldersYAML, &parsedComponentFolders) if err != nil { panic(err) } - cmd.ComponentFolders = parsed.ComponentFolders - cmd.ExcludeFolders = parsed.ExcludeFolders -} + cmd.ComponentFolders = parsedComponentFolders.ComponentFolders + cmd.ExcludeFolders = parsedComponentFolders.ExcludeFolders + + // Parse builtin-authentication-profiles.yaml + err = yaml.Unmarshal(builtinAuthenticationProfilesYAML, &metadataschema.BuiltinAuthenticationProfiles) + if err != nil { + panic(err) + } -func main() { cmd.Execute() } diff --git a/.build-tools/pkg/metadataanalyzer/analyzer.template b/.build-tools/pkg/metadataanalyzer/analyzer.template index b5fc62ecf3..6177c0050c 100644 --- a/.build-tools/pkg/metadataanalyzer/analyzer.template +++ b/.build-tools/pkg/metadataanalyzer/analyzer.template @@ -6,7 +6,7 @@ import ( "os" "strings" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "github.com/dapr/kit/logger" mdutils "github.com/dapr/components-contrib/metadata" @@ -17,24 +17,24 @@ import ( ) func main() { - if len(os.Args) < 2 { - fmt.Println("Please provide the path to the components-contrib root as an argument") - os.Exit(1) - } - basePath := os.Args[1] - log := logger.NewLogger("metadata") + if len(os.Args) < 2 { + fmt.Println("Please provide the path to the components-contrib root as an argument") + os.Exit(1) + } + basePath := os.Args[1] + log := logger.NewLogger("metadata") - var ( + var ( yamlMetadata *map[string]string - missing map[string]string + missing []string unexpected []string ) - missingByComponent := make(map[string]map[string]string) + missingByComponent := make(map[string][]string) unexpectedByComponent := make(map[string][]string) {{range $fullpkg, $val := .Pkgs}} instanceOf_{{index $val 0}} := {{index $val 0}}.{{index $val 1}}(log) - metadataFor_{{index $val 0}} := instanceOf_{{index $val 0}}.GetComponentMetadata() + metadataFor_{{index $val 0}} := instanceOf_{{index $val 0}}.(mdutils.ComponentWithMetadata).GetComponentMetadata() yamlMetadata = getYamlMetadata(basePath, "{{$fullpkg}}") missing = checkMissingMetadata(yamlMetadata, metadataFor_{{index $val 0}}) if len(missing) > 0 { @@ -127,14 +127,17 @@ func getYamlMetadata(basePath string, pkg string) *map[string]string { return &names } -func checkMissingMetadata(yamlMetadata *map[string]string, componentMetadata map[string]string) map[string]string { - missingMetadata := make(map[string]string) +func checkMissingMetadata(yamlMetadata *map[string]string, componentMetadata mdutils.MetadataMap) []string { + missingMetadata := make([]string, 0) // if there is no yaml metadata, then we are not missing anything yet if yamlMetadata != nil && len(*yamlMetadata) > 0 { - for key := range componentMetadata { + for key, md := range componentMetadata { + if md.Ignored { + continue + } lowerKey := strings.ToLower(key) if _, ok := (*yamlMetadata)[lowerKey]; !ok { - missingMetadata[lowerKey] = componentMetadata[key] + missingMetadata = append(missingMetadata, key) } // todo - check if the metadata is the same data type } diff --git a/.build-tools/pkg/metadataschema/builtin-authentication-profiles.go b/.build-tools/pkg/metadataschema/builtin-authentication-profiles.go index d2fb6983b8..bcb76d5ed0 100644 --- a/.build-tools/pkg/metadataschema/builtin-authentication-profiles.go +++ b/.build-tools/pkg/metadataschema/builtin-authentication-profiles.go @@ -17,131 +17,22 @@ import ( "fmt" ) +// Built-in authentication profiles +var BuiltinAuthenticationProfiles map[string][]AuthenticationProfile + // ParseBuiltinAuthenticationProfile returns an AuthenticationProfile(s) from a given BuiltinAuthenticationProfile. func ParseBuiltinAuthenticationProfile(bi BuiltinAuthenticationProfile) ([]AuthenticationProfile, error) { - switch bi.Name { - case "aws": - return []AuthenticationProfile{ - { - Title: "AWS: Access Key ID and Secret Access Key", - Description: "Authenticate using an Access Key ID and Secret Access Key included in the metadata", - Metadata: []Metadata{ - { - Name: "accessKey", - Required: true, - Sensitive: true, - Description: "AWS access key associated with an IAM account", - Example: `"AKIAIOSFODNN7EXAMPLE"`, - }, - { - Name: "secretKey", - Required: true, - Sensitive: true, - Description: "The secret key associated with the access key", - Example: `"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"`, - }, - }, - }, - { - Title: "AWS: Credentials from Environment Variables", - Description: "Use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from the environment", - Metadata: []Metadata{}, - }, - }, nil - case "azuread": - azureEnvironmentMetadata := Metadata{ - Name: "azureEnvironment", - Required: false, - Description: "Optional name for the Azure environment if using a different Azure cloud", - Example: `"AzurePublicCloud"`, - Default: "AzurePublicCloud", - AllowedValues: []string{"AzurePublicCloud", "AzureChinaCloud", "AzureUSGovernmentCloud"}, - } - profiles := []AuthenticationProfile{ - { - Title: "Azure AD: Managed identity", - Description: "Authenticate using Azure AD and a managed identity.", - Metadata: mergedMetadata(bi.Metadata, - Metadata{ - Name: "azureClientId", - Description: "Client ID (application ID). Required if the service has multiple identities assigned.", - Example: `"c7dd251f-811f-4ba2-a905-acd4d3f8f08b"`, - Required: false, - }, - azureEnvironmentMetadata, - ), - }, - { - Title: "Azure AD: Client credentials", - Description: "Authenticate using Azure AD with client credentials, also known as \"service principals\".", - Metadata: mergedMetadata(bi.Metadata, - Metadata{ - Name: "azureTenantId", - Description: "ID of the Azure AD tenant", - Example: `"cd4b2887-304c-47e1-b4d5-65447fdd542a"`, - Required: true, - }, - Metadata{ - Name: "azureClientId", - Description: "Client ID (application ID)", - Example: `"c7dd251f-811f-4ba2-a905-acd4d3f8f08b"`, - Required: true, - }, - Metadata{ - Name: "azureClientSecret", - Description: "Client secret (application password)", - Example: `"Ecy3XG7zVZK3/vl/a2NSB+a1zXLa8RnMum/IgD0E"`, - Required: true, - Sensitive: true, - }, - azureEnvironmentMetadata, - ), - }, - { - Title: "Azure AD: Client certificate", - Description: `Authenticate using Azure AD with a client certificate. One of "azureCertificate" and "azureCertificateFile" is required.`, - Metadata: mergedMetadata(bi.Metadata, - Metadata{ - Name: "azureTenantId", - Description: "ID of the Azure AD tenant", - Example: `"cd4b2887-304c-47e1-b4d5-65447fdd542a"`, - Required: true, - }, - Metadata{ - Name: "azureClientId", - Description: "Client ID (application ID)", - Example: `"c7dd251f-811f-4ba2-a905-acd4d3f8f08b"`, - Required: true, - }, - Metadata{ - Name: "azureCertificate", - Description: "Certificate and private key (in either a PEM file containing both the certificate and key, or in PFX/PKCS#12 format)", - Example: `"-----BEGIN PRIVATE KEY-----\n MIIEvgI... \n -----END PRIVATE KEY----- \n -----BEGIN CERTIFICATE----- \n MIICoTC... \n -----END CERTIFICATE----- \n"`, - Required: false, - Sensitive: true, - }, - Metadata{ - Name: "azureCertificateFile", - Description: "Path to PEM or PFX/PKCS#12 file on disk, containing the certificate and private key.", - Example: `"/path/to/file.pem"`, - Required: false, - Sensitive: false, - }, - Metadata{ - Name: "azureCertificatePassword", - Description: "Password for the certificate if encrypted.", - Example: `"password"`, - Required: false, - Sensitive: true, - }, - azureEnvironmentMetadata, - ), - }, - } - return profiles, nil - default: + profiles, ok := BuiltinAuthenticationProfiles[bi.Name] + if !ok { return nil, fmt.Errorf("built-in authentication profile %s does not exist", bi.Name) } + + res := make([]AuthenticationProfile, len(profiles)) + for i, profile := range profiles { + res[i] = profile + res[i].Metadata = mergedMetadata(bi.Metadata, res[i].Metadata...) + } + return res, nil } func mergedMetadata(base []Metadata, add ...Metadata) []Metadata { diff --git a/.build-tools/pkg/metadataschema/schema.go b/.build-tools/pkg/metadataschema/schema.go index c807f0f65c..2e49338aec 100644 --- a/.build-tools/pkg/metadataschema/schema.go +++ b/.build-tools/pkg/metadataschema/schema.go @@ -18,116 +18,113 @@ package metadataschema // ComponentMetadata is the schema for the metadata.yaml / metadata.json files. type ComponentMetadata struct { // Version of the component metadata schema. - SchemaVersion string `json:"schemaVersion" jsonschema:"enum=v1"` + SchemaVersion string `json:"schemaVersion" yaml:"schemaVersion" jsonschema:"enum=v1"` // Component type, of one of the allowed values. - Type string `json:"type" jsonschema:"enum=bindings,enum=state,enum=secretstores,enum=pubsub,enum=workflows,enum=configuration,enum=lock,enum=middleware"` + Type string `json:"type" yaml:"type" jsonschema:"enum=bindings,enum=state,enum=secretstores,enum=pubsub,enum=workflows,enum=configuration,enum=lock,enum=middleware"` // Name of the component (without the inital type, e.g. "http" instead of "bindings.http"). - Name string `json:"name"` + Name string `json:"name" yaml:"name"` // Version of the component, with the leading "v", e.g. "v1". - Version string `json:"version"` + Version string `json:"version" yaml:"version"` // Component status. - Status string `json:"status" jsonschema:"enum=stable,enum=beta,enum=alpha,enum=development-only"` + Status string `json:"status" yaml:"status" jsonschema:"enum=stable,enum=beta,enum=alpha,enum=development-only"` // Title of the component, e.g. "HTTP". - Title string `json:"title"` + Title string `json:"title" yaml:"title"` // Additional description for the component, optional. - Description string `json:"description,omitempty"` + Description string `json:"description,omitempty" yaml:"description,omitempty"` // URLs with additional resources for the component, such as docs. - URLs []URL `json:"urls"` + URLs []URL `json:"urls" yaml:"urls"` // Properties for bindings only. // This should not present unless "type" is "bindings". - Binding *Binding `json:"binding,omitempty"` + Binding *Binding `json:"binding,omitempty" yaml:"binding,omitempty"` // Component capabilities. // For state stores, the presence of "actorStateStore" implies that the metadata property "actorStateStore" can be set. In that case, do not manually specify "actorStateStore" as metadata option. - Capabilities []string `json:"capabilities,omitempty"` + Capabilities []string `json:"capabilities,omitempty" yaml:"capabilities,omitempty"` // Authentication profiles for the component. - AuthenticationProfiles []AuthenticationProfile `json:"authenticationProfiles,omitempty"` + AuthenticationProfiles []AuthenticationProfile `json:"authenticationProfiles,omitempty" yaml:"authenticationProfiles,omitempty"` // Built-in authentication profiles to import. - BuiltInAuthenticationProfiles []BuiltinAuthenticationProfile `json:"builtinAuthenticationProfiles,omitempty"` + BuiltInAuthenticationProfiles []BuiltinAuthenticationProfile `json:"builtinAuthenticationProfiles,omitempty" yaml:"builtinAuthenticationProfiles,omitempty"` // Metadata options for the component. - Metadata []Metadata `json:"metadata,omitempty"` + Metadata []Metadata `json:"metadata,omitempty" yaml:"metadata,omitempty"` } // URL represents one URL with additional resources. type URL struct { // Title of the URL. - Title string `json:"title"` + Title string `json:"title" yaml:"title"` // URL. - URL string `json:"url"` + URL string `json:"url" yaml:"url"` } // Binding represents properties that are specific to bindings type Binding struct { // If "true", the binding can be used as input binding. - Input bool `json:"input,omitempty"` + Input bool `json:"input,omitempty" yaml:"input,omitempty"` // If "true", the binding can be used as output binding. - Output bool `json:"output,omitempty"` + Output bool `json:"output,omitempty" yaml:"output,omitempty"` // List of operations that the output binding support. // Required in output bindings, and not allowed in input-only bindings. - Operations []BindingOperation `json:"operations"` + Operations []BindingOperation `json:"operations" yaml:"operations"` } // BindingOperation represents an operation offered by an output binding. type BindingOperation struct { // Name of the operation, such as "create", "post", "delete", etc. - Name string `json:"name"` + Name string `json:"name" yaml:"name"` // Descrption of the operation. - Description string `json:"description"` + Description string `json:"description" yaml:"description"` } // Metadata property. type Metadata struct { // Name of the metadata property. - Name string `json:"name"` + Name string `json:"name" yaml:"name"` // Description of the property. - Description string `json:"description"` + Description string `json:"description" yaml:"description"` // If "true", the property is required - Required bool `json:"required,omitempty"` + Required bool `json:"required,omitempty" yaml:"required,omitempty"` // If "true", the property represents a sensitive value such as a password. - Sensitive bool `json:"sensitive,omitempty"` + Sensitive bool `json:"sensitive,omitempty" yaml:"sensitive,omitempty"` // Type of the property. // If this is empty, it's interpreted as "string". - Type string `json:"type,omitempty" jsonschema:"enum=string,enum=number,enum=bool,enum=duration"` + Type string `json:"type,omitempty" yaml:"type,omitempty" jsonschema:"enum=string,enum=number,enum=bool,enum=duration"` // Default value for the property. // If it's a string, don't forget to add quotes. - Default string `json:"default,omitempty"` + Default string `json:"default,omitempty" yaml:"default,omitempty"` // Example value. - Example string `json:"example"` + Example string `json:"example" yaml:"example"` // If set, forces the value to be one of those specified in this allowlist. - AllowedValues []string `json:"allowedValues,omitempty"` + AllowedValues []string `json:"allowedValues,omitempty" yaml:"allowedValues,omitempty"` // If set, specifies that the property is only applicable to bindings of the type specified below. // At least one of "input" and "output" must be "true". - Binding *MetadataBinding `json:"binding,omitempty"` + Binding *MetadataBinding `json:"binding,omitempty" yaml:"binding,omitempty"` // URL with additional information, such as docs. - URL *URL `json:"url,omitempty"` + URL *URL `json:"url,omitempty" yaml:"url,omitempty"` // If set, specifies that the property is deprecated and should not be used in new configurations. - Deprecated bool `json:"deprecated,omitempty"` + Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"` } // MetadataBinding is the type for the "binding" property in the "metadata" object. type MetadataBinding struct { // If "true", the property can be used with the binding as input binding only. - Input bool `json:"input,omitempty"` + Input bool `json:"input,omitempty" yaml:"input,omitempty"` // If "true", the property can be used with the binding as output binding only. - Output bool `json:"output,omitempty"` + Output bool `json:"output,omitempty" yaml:"output,omitempty"` } // AuthenticationProfile is the type for an authentication profile. type AuthenticationProfile struct { // Title of the authentication profile. - Title string `json:"title"` + Title string `json:"title" yaml:"title"` // Additional description for the authentication profile, optional. - Description string `json:"description"` + Description string `json:"description" yaml:"description"` // Metadata options applicable when using this authentication profile. - Metadata []Metadata `json:"metadata,omitempty"` + Metadata []Metadata `json:"metadata,omitempty" yaml:"metadata,omitempty"` } // BuiltinAuthenticationProfile is a reference to a built-in authentication profile. type BuiltinAuthenticationProfile struct { // Name of the built-in authentication profile. - // Currently supports: - // - // - `azuread` (Azure AD, including Managed Identity). - Name string `json:"name"` + Name string `json:"name" yaml:"name"` // Additional metadata options applicable when using this authentication profile. - Metadata []Metadata `json:"metadata,omitempty"` + Metadata []Metadata `json:"metadata,omitempty" yaml:"metadata,omitempty"` } diff --git a/.build-tools/pkg/metadataschema/validators.go b/.build-tools/pkg/metadataschema/validators.go index 9527508fea..88b026e690 100644 --- a/.build-tools/pkg/metadataschema/validators.go +++ b/.build-tools/pkg/metadataschema/validators.go @@ -23,6 +23,13 @@ import ( mdutils "github.com/dapr/components-contrib/metadata" ) +const ( + bindingDirectionMetadataKey = "direction" + bindingDirectionInput = "input" + bindingDirectionOutput = "output" + bindingRouteMetadataKey = "route" +) + // IsValid performs additional validation and returns true if the object is valid. func (c *ComponentMetadata) IsValid() error { // Check valid component type @@ -70,6 +77,18 @@ func (c *ComponentMetadata) IsValid() error { // Remove the property builtinAuthenticationProfiles now c.BuiltInAuthenticationProfiles = nil + // Trim newlines from all descriptions + c.Description = strings.TrimSpace(c.Description) + for i := range c.AuthenticationProfiles { + c.AuthenticationProfiles[i].Description = strings.TrimSpace(c.AuthenticationProfiles[i].Description) + for j := range c.AuthenticationProfiles[i].Metadata { + c.AuthenticationProfiles[i].Metadata[j].Description = strings.TrimSpace(c.AuthenticationProfiles[i].Metadata[j].Description) + } + } + for i := range c.Metadata { + c.Metadata[i].Description = strings.TrimSpace(c.Metadata[i].Description) + } + return nil } @@ -135,6 +154,51 @@ func (c *ComponentMetadata) AppendBuiltin() error { }, }, ) + case mdutils.BindingType: + if c.Binding != nil { + if c.Metadata == nil { + c.Metadata = []Metadata{} + } + + if c.Binding.Input { + direction := bindingDirectionInput + allowedValues := []string{ + bindingDirectionInput, + } + + if c.Binding.Output { + direction = fmt.Sprintf("%s,%s", bindingDirectionInput, bindingDirectionOutput) + allowedValues = append(allowedValues, bindingDirectionOutput, direction) + } + + c.Metadata = append(c.Metadata, + Metadata{ + Name: bindingDirectionMetadataKey, + Type: "string", + Description: "Indicates the direction of the binding component.", + Example: `"`+direction+`"`, + URL: &URL{ + Title: "Documentation", + URL: "https://docs.dapr.io/reference/api/bindings_api/#binding-direction-optional", + }, + AllowedValues: allowedValues, + }, + ) + + c.Metadata = append(c.Metadata, + Metadata{ + Name: bindingRouteMetadataKey, + Type: "string", + Description: "Specifies a custom route for incoming events.", + Example: `"/custom-path"`, + URL: &URL{ + Title: "Documentation", + URL: "https://docs.dapr.io/developing-applications/building-blocks/bindings/howto-triggers/#specifying-a-custom-route", + }, + }, + ) + } + } } // Sanity check to ensure the data is in sync diff --git a/.golangci.yml b/.golangci.yml index 6b635ebc3c..73e3b28b38 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,6 +15,7 @@ run: # list of build tags, all linters use it. Default is empty list. build-tags: - certtests + - metadata # which dirs to skip: they won't be analyzed; # can use regexp here: generated.*, regexp is applied on full path; diff --git a/Makefile b/Makefile index 4b4743b177..4028525320 100644 --- a/Makefile +++ b/Makefile @@ -109,14 +109,13 @@ verify-linter-version: ################################################################################ .PHONY: test test: - CGO_ENABLED=$(CGO) go test ./... $(COVERAGE_OPTS) $(BUILDMODE) --timeout=15m + CGO_ENABLED=$(CGO) go test ./... $(COVERAGE_OPTS) $(BUILDMODE) -tags metadata --timeout=15m ################################################################################ # Target: lint # ################################################################################ .PHONY: lint lint: verify-linter-installed verify-linter-version - # Due to https://github.com/golangci/golangci-lint/issues/580, we need to add --fix for windows $(GOLANGCI_LINT) run --timeout=20m ################################################################################ @@ -228,7 +227,7 @@ check-component-metadata: go get "github.com/dapr/components-contrib@master" && \ go mod edit -replace "github.com/dapr/components-contrib"="../" && \ go mod tidy && \ - go build . && \ + go build -tags metadata . && \ rm ./go.mod && rm ./go.sum && rm ./main.go && \ ./metadataanalyzer ../ diff --git a/bindings/alicloud/dingtalk/webhook/webhook.go b/bindings/alicloud/dingtalk/webhook/webhook.go index 30d5f10dec..14964f3443 100644 --- a/bindings/alicloud/dingtalk/webhook/webhook.go +++ b/bindings/alicloud/dingtalk/webhook/webhook.go @@ -207,11 +207,10 @@ func (t *DingTalkWebhook) sendMessage(ctx context.Context, req *bindings.InvokeR } // GetComponentMetadata returns the metadata of the component. -func (t *DingTalkWebhook) GetComponentMetadata() map[string]string { +func (t *DingTalkWebhook) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := Settings{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } func getPostURL(urlPath, secret string) (string, error) { diff --git a/bindings/alicloud/oss/oss.go b/bindings/alicloud/oss/oss.go index 4d43c1fb80..c124098f0d 100644 --- a/bindings/alicloud/oss/oss.go +++ b/bindings/alicloud/oss/oss.go @@ -108,9 +108,8 @@ func (s *AliCloudOSS) getClient(metadata *ossMetadata) (*oss.Client, error) { } // GetComponentMetadata returns the metadata of the component. -func (s *AliCloudOSS) GetComponentMetadata() map[string]string { +func (s *AliCloudOSS) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := ossMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/alicloud/sls/sls.go b/bindings/alicloud/sls/sls.go index 5b16fa494c..04c509b9b3 100644 --- a/bindings/alicloud/sls/sls.go +++ b/bindings/alicloud/sls/sls.go @@ -128,9 +128,8 @@ func (callback *Callback) Fail(result *producer.Result) { } // GetComponentMetadata returns the metadata of the component. -func (s *AliCloudSlsLogstorage) GetComponentMetadata() map[string]string { +func (s *AliCloudSlsLogstorage) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := SlsLogstorageMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/alicloud/tablestore/tablestore.go b/bindings/alicloud/tablestore/tablestore.go index 4d0cf6be6d..abb34a43be 100644 --- a/bindings/alicloud/tablestore/tablestore.go +++ b/bindings/alicloud/tablestore/tablestore.go @@ -347,9 +347,8 @@ func contains(arr []string, str string) bool { } // GetComponentMetadata returns the metadata of the component. -func (s *AliCloudTableStore) GetComponentMetadata() map[string]string { +func (s *AliCloudTableStore) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := tablestoreMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/apns/apns.go b/bindings/apns/apns.go index 273244cb98..df15daf86e 100644 --- a/bindings/apns/apns.go +++ b/bindings/apns/apns.go @@ -261,9 +261,8 @@ func makeErrorResponse(httpResponse *http.Response) (*bindings.InvokeResponse, e } // GetComponentMetadata returns the metadata of the component. -func (a *APNS) GetComponentMetadata() map[string]string { +func (a *APNS) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := APNSmetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/aws/dynamodb/dynamodb.go b/bindings/aws/dynamodb/dynamodb.go index db297d8164..d9ef0e53a4 100644 --- a/bindings/aws/dynamodb/dynamodb.go +++ b/bindings/aws/dynamodb/dynamodb.go @@ -115,9 +115,8 @@ func (d *DynamoDB) getClient(metadata *dynamoDBMetadata) (*dynamodb.DynamoDB, er } // GetComponentMetadata returns the metadata of the component. -func (d *DynamoDB) GetComponentMetadata() map[string]string { +func (d *DynamoDB) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := dynamoDBMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/aws/kinesis/kinesis.go b/bindings/aws/kinesis/kinesis.go index 5c646e4090..0f6547f232 100644 --- a/bindings/aws/kinesis/kinesis.go +++ b/bindings/aws/kinesis/kinesis.go @@ -418,9 +418,8 @@ func (p *recordProcessor) Shutdown(input *interfaces.ShutdownInput) { } // GetComponentMetadata returns the metadata of the component. -func (a *AWSKinesis) GetComponentMetadata() map[string]string { +func (a *AWSKinesis) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := &kinesisMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/aws/s3/s3.go b/bindings/aws/s3/s3.go index a7ba93d6f7..ff84145e74 100644 --- a/bindings/aws/s3/s3.go +++ b/bindings/aws/s3/s3.go @@ -62,10 +62,12 @@ type AWSS3 struct { } type s3Metadata struct { + // Ignored by metadata parser because included in built-in authentication profile + AccessKey string `json:"accessKey" mapstructure:"accessKey" mdignore:"true"` + SecretKey string `json:"secretKey" mapstructure:"secretKey" mdignore:"true"` + Region string `json:"region" mapstructure:"region"` Endpoint string `json:"endpoint" mapstructure:"endpoint"` - AccessKey string `json:"accessKey" mapstructure:"accessKey"` - SecretKey string `json:"secretKey" mapstructure:"secretKey"` SessionToken string `json:"sessionToken" mapstructure:"sessionToken"` Bucket string `json:"bucket" mapstructure:"bucket"` DecodeBase64 bool `json:"decodeBase64,string" mapstructure:"decodeBase64"` @@ -416,9 +418,8 @@ func (metadata s3Metadata) mergeWithRequestMetadata(req *bindings.InvokeRequest) } // GetComponentMetadata returns the metadata of the component. -func (s *AWSS3) GetComponentMetadata() map[string]string { +func (s *AWSS3) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := s3Metadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/aws/ses/ses.go b/bindings/aws/ses/ses.go index e609c1467c..03b48c6fd1 100644 --- a/bindings/aws/ses/ses.go +++ b/bindings/aws/ses/ses.go @@ -171,9 +171,8 @@ func (a *AWSSES) getClient(metadata *sesMetadata) (*ses.SES, error) { } // GetComponentMetadata returns the metadata of the component. -func (a *AWSSES) GetComponentMetadata() map[string]string { +func (a *AWSSES) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := sesMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/aws/sns/sns.go b/bindings/aws/sns/sns.go index e2d587fda9..7731401171 100644 --- a/bindings/aws/sns/sns.go +++ b/bindings/aws/sns/sns.go @@ -117,9 +117,8 @@ func (a *AWSSNS) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bind } // GetComponentMetadata returns the metadata of the component. -func (a *AWSSNS) GetComponentMetadata() map[string]string { +func (a *AWSSNS) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := snsMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/aws/sqs/sqs.go b/bindings/aws/sqs/sqs.go index 58c999b55d..231ac80151 100644 --- a/bindings/aws/sqs/sqs.go +++ b/bindings/aws/sqs/sqs.go @@ -187,9 +187,8 @@ func (a *AWSSQS) getClient(metadata *sqsMetadata) (*sqs.SQS, error) { } // GetComponentMetadata returns the metadata of the component. -func (a *AWSSQS) GetComponentMetadata() map[string]string { +func (a *AWSSQS) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := sqsMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/azure/blobstorage/blobstorage.go b/bindings/azure/blobstorage/blobstorage.go index 8779ec01e8..c28034edab 100644 --- a/bindings/azure/blobstorage/blobstorage.go +++ b/bindings/azure/blobstorage/blobstorage.go @@ -358,9 +358,8 @@ func (a *AzureBlobStorage) isValidDeleteSnapshotsOptionType(accessType azblob.De } // GetComponentMetadata returns the metadata of the component. -func (a *AzureBlobStorage) GetComponentMetadata() map[string]string { +func (a *AzureBlobStorage) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := storageinternal.BlobStorageMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/azure/cosmosdb/cosmosdb.go b/bindings/azure/cosmosdb/cosmosdb.go index 785514f74f..381f8e667a 100644 --- a/bindings/azure/cosmosdb/cosmosdb.go +++ b/bindings/azure/cosmosdb/cosmosdb.go @@ -192,9 +192,8 @@ func (c *CosmosDB) lookup(m map[string]interface{}, ks []string) (val interface{ } // GetComponentMetadata returns the metadata of the component. -func (c *CosmosDB) GetComponentMetadata() map[string]string { +func (c *CosmosDB) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := cosmosDBCredentials{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/azure/cosmosdbgremlinapi/cosmosdbgremlinapi.go b/bindings/azure/cosmosdbgremlinapi/cosmosdbgremlinapi.go index f235d1ee91..74109da384 100644 --- a/bindings/azure/cosmosdbgremlinapi/cosmosdbgremlinapi.go +++ b/bindings/azure/cosmosdbgremlinapi/cosmosdbgremlinapi.go @@ -130,9 +130,8 @@ func (c *CosmosDBGremlinAPI) Invoke(_ context.Context, req *bindings.InvokeReque } // GetComponentMetadata returns the metadata of the component. -func (c *CosmosDBGremlinAPI) GetComponentMetadata() map[string]string { +func (c *CosmosDBGremlinAPI) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := cosmosDBGremlinAPICredentials{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/azure/eventgrid/eventgrid.go b/bindings/azure/eventgrid/eventgrid.go index 4c7edb4da4..377f9f4bc2 100644 --- a/bindings/azure/eventgrid/eventgrid.go +++ b/bindings/azure/eventgrid/eventgrid.go @@ -535,9 +535,8 @@ func (a *AzureEventGrid) subscriptionNeedsUpdating(res armeventgrid.EventSubscri } // GetComponentMetadata returns the metadata of the component. -func (a *AzureEventGrid) GetComponentMetadata() map[string]string { +func (a *AzureEventGrid) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := azureEventGridMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/azure/eventgrid/metadata.yaml b/bindings/azure/eventgrid/metadata.yaml index 7c99fc44fa..dd8bbc4dda 100644 --- a/bindings/azure/eventgrid/metadata.yaml +++ b/bindings/azure/eventgrid/metadata.yaml @@ -27,7 +27,7 @@ metadata: output: false description: | The HTTPS endpoint of the webhook Event Grid sends events (formatted as - Cloud Events) to. If you’re not re-writing URLs on ingress, it should be + Cloud Events) to. If you're not re-writing URLs on ingress, it should be in the form of: `"https://[YOUR HOSTNAME]/"` If testing on your local machine, you can use something like `ngrok` to create a public endpoint. diff --git a/bindings/azure/eventhubs/eventhubs.go b/bindings/azure/eventhubs/eventhubs.go index cd48ab6bb2..ec68b4e378 100644 --- a/bindings/azure/eventhubs/eventhubs.go +++ b/bindings/azure/eventhubs/eventhubs.go @@ -96,9 +96,8 @@ func (a *AzureEventHubs) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (a *AzureEventHubs) GetComponentMetadata() map[string]string { +func (a *AzureEventHubs) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := impl.AzureEventHubsMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/azure/eventhubs/metadata.yaml b/bindings/azure/eventhubs/metadata.yaml index 77c221cfa2..f6250ce69d 100644 --- a/bindings/azure/eventhubs/metadata.yaml +++ b/bindings/azure/eventhubs/metadata.yaml @@ -89,14 +89,6 @@ builtinAuthenticationProfiles: Number of partitions for the new Event Hub namespace. Used only when entity management is enabled. metadata: - # Input and output metadata - - name: partitionId - type: string - required: false - description: | - DEPRECATED. - deprecated: true - example: "" # Input-only metadata # consumerGroup is an alias for consumerId, if both are defined consumerId takes precedence. - name: consumerId diff --git a/bindings/azure/openai/openai.go b/bindings/azure/openai/openai.go index 83d189203a..9df8009a33 100644 --- a/bindings/azure/openai/openai.go +++ b/bindings/azure/openai/openai.go @@ -318,9 +318,8 @@ func (p *AzOpenAI) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (p *AzOpenAI) GetComponentMetadata() map[string]string { +func (p *AzOpenAI) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := openAIMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/azure/servicebusqueues/servicebusqueues.go b/bindings/azure/servicebusqueues/servicebusqueues.go index 27d74f4088..3ab133fbe4 100644 --- a/bindings/azure/servicebusqueues/servicebusqueues.go +++ b/bindings/azure/servicebusqueues/servicebusqueues.go @@ -204,10 +204,9 @@ func (a *AzureServiceBusQueues) Close() (err error) { } // GetComponentMetadata returns the metadata of the component. -func (a *AzureServiceBusQueues) GetComponentMetadata() map[string]string { +func (a *AzureServiceBusQueues) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := impl.Metadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) delete(metadataInfo, "consumerID") // only applies to topics, not queues - return metadataInfo + return } diff --git a/bindings/azure/signalr/signalr.go b/bindings/azure/signalr/signalr.go index a446ffc9a1..2e4e3821fa 100644 --- a/bindings/azure/signalr/signalr.go +++ b/bindings/azure/signalr/signalr.go @@ -301,9 +301,8 @@ func (s *SignalR) getToken(ctx context.Context, url string) (string, error) { } // GetComponentMetadata returns the metadata of the component. -func (s *SignalR) GetComponentMetadata() map[string]string { +func (s *SignalR) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := SignalRMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/azure/storagequeues/storagequeues.go b/bindings/azure/storagequeues/storagequeues.go index 183b2f92cd..babfb2feab 100644 --- a/bindings/azure/storagequeues/storagequeues.go +++ b/bindings/azure/storagequeues/storagequeues.go @@ -370,9 +370,8 @@ func (a *AzureStorageQueues) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (a *AzureStorageQueues) GetComponentMetadata() map[string]string { +func (a *AzureStorageQueues) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := storageQueuesMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/cloudflare/queues/cfqueues.go b/bindings/cloudflare/queues/cfqueues.go index 1b3d04a106..30d89ccb49 100644 --- a/bindings/cloudflare/queues/cfqueues.go +++ b/bindings/cloudflare/queues/cfqueues.go @@ -136,9 +136,8 @@ func (q *CFQueues) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (q *CFQueues) GetComponentMetadata() map[string]string { +func (q *CFQueues) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := componentMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/commercetools/commercetools.go b/bindings/commercetools/commercetools.go index 55010f4e2e..7efd4053cf 100644 --- a/bindings/commercetools/commercetools.go +++ b/bindings/commercetools/commercetools.go @@ -201,9 +201,8 @@ func (ct *Binding) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (ct Binding) GetComponentMetadata() map[string]string { +func (ct Binding) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := commercetoolsMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/cron/cron.go b/bindings/cron/cron.go index 53a5754582..db892616b9 100644 --- a/bindings/cron/cron.go +++ b/bindings/cron/cron.go @@ -132,9 +132,8 @@ func (b *Binding) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (b *Binding) GetComponentMetadata() map[string]string { +func (b *Binding) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := metadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/dubbo/dubbo_output.go b/bindings/dubbo/dubbo_output.go index d57d823739..ab117589b3 100644 --- a/bindings/dubbo/dubbo_output.go +++ b/bindings/dubbo/dubbo_output.go @@ -27,6 +27,7 @@ import ( dubboImpl "dubbo.apache.org/dubbo-go/v3/protocol/dubbo/impl" "github.com/dapr/components-contrib/bindings" + "github.com/dapr/components-contrib/metadata" "github.com/dapr/kit/logger" ) @@ -93,7 +94,6 @@ func (out *DubboOutputBinding) Operations() []bindings.OperationKind { } // GetComponentMetadata returns the metadata of the component. -func (out *DubboOutputBinding) GetComponentMetadata() map[string]string { - metadataInfo := map[string]string{} - return metadataInfo +func (out *DubboOutputBinding) GetComponentMetadata() metadata.MetadataMap { + return metadata.MetadataMap{} } diff --git a/bindings/gcp/bucket/bucket.go b/bindings/gcp/bucket/bucket.go index e682c170b1..941b43ff4c 100644 --- a/bindings/gcp/bucket/bucket.go +++ b/bindings/gcp/bucket/bucket.go @@ -31,7 +31,7 @@ import ( "github.com/dapr/components-contrib/bindings" "github.com/dapr/components-contrib/internal/utils" - contribMetadata "github.com/dapr/components-contrib/metadata" + "github.com/dapr/components-contrib/metadata" "github.com/dapr/kit/logger" ) @@ -110,7 +110,7 @@ func (g *GCPStorage) Init(ctx context.Context, metadata bindings.Metadata) error func (g *GCPStorage) parseMetadata(meta bindings.Metadata) (*gcpMetadata, error) { m := gcpMetadata{} - err := contribMetadata.DecodeMetadata(meta.Properties, &m) + err := metadata.DecodeMetadata(meta.Properties, &m) if err != nil { return nil, err } @@ -311,9 +311,8 @@ func (g *GCPStorage) handleBackwardCompatibilityForMetadata(metadata map[string] } // GetComponentMetadata returns the metadata of the component. -func (g *GCPStorage) GetComponentMetadata() map[string]string { +func (g *GCPStorage) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := gcpMetadata{} - metadataInfo := map[string]string{} - contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) + return } diff --git a/bindings/gcp/pubsub/pubsub.go b/bindings/gcp/pubsub/pubsub.go index 7cc7483f09..dfc8a69787 100644 --- a/bindings/gcp/pubsub/pubsub.go +++ b/bindings/gcp/pubsub/pubsub.go @@ -151,9 +151,8 @@ func (g *GCPPubSub) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (g *GCPPubSub) GetComponentMetadata() map[string]string { +func (g *GCPPubSub) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := pubSubMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/graphql/graphql.go b/bindings/graphql/graphql.go index 91edb090e9..379c863e54 100644 --- a/bindings/graphql/graphql.go +++ b/bindings/graphql/graphql.go @@ -186,9 +186,8 @@ func (gql *GraphQL) runRequest(ctx context.Context, requestKey string, req *bind } // GetComponentMetadata returns the metadata of the component. -func (gql *GraphQL) GetComponentMetadata() map[string]string { +func (gql *GraphQL) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := graphQLMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/http/http.go b/bindings/http/http.go index 63fe4ee4f6..177a3af087 100644 --- a/bindings/http/http.go +++ b/bindings/http/http.go @@ -338,9 +338,8 @@ func (h *HTTPSource) Invoke(parentCtx context.Context, req *bindings.InvokeReque } // GetComponentMetadata returns the metadata of the component. -func (h *HTTPSource) GetComponentMetadata() map[string]string { +func (h *HTTPSource) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := httpMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/huawei/obs/obs.go b/bindings/huawei/obs/obs.go index 8e68e2d8d2..26cad599f3 100644 --- a/bindings/huawei/obs/obs.go +++ b/bindings/huawei/obs/obs.go @@ -322,9 +322,8 @@ func (o *HuaweiOBS) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*b } // GetComponentMetadata returns the metadata of the component. -func (o *HuaweiOBS) GetComponentMetadata() map[string]string { +func (o *HuaweiOBS) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := obsMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/influx/influx.go b/bindings/influx/influx.go index 87fad6b805..30bc43595e 100644 --- a/bindings/influx/influx.go +++ b/bindings/influx/influx.go @@ -167,9 +167,8 @@ func (i *Influx) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (i *Influx) GetComponentMetadata() map[string]string { +func (i *Influx) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := influxMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/input_binding.go b/bindings/input_binding.go index 5892bf2d72..b87f7b9d4c 100644 --- a/bindings/input_binding.go +++ b/bindings/input_binding.go @@ -19,10 +19,13 @@ import ( "io" "github.com/dapr/components-contrib/health" + "github.com/dapr/components-contrib/metadata" ) // InputBinding is the interface to define a binding that triggers on incoming events. type InputBinding interface { + metadata.ComponentWithMetadata + // Init passes connection and properties metadata to the binding implementation. Init(ctx context.Context, metadata Metadata) error // Read is a method that runs in background and triggers the callback function whenever an event arrives. @@ -30,7 +33,6 @@ type InputBinding interface { // Close is a method that closes the connection to the binding. Must be // called when the binding is no longer needed to free up resources. io.Closer - GetComponentMetadata() map[string]string } // Handler is the handler used to invoke the app handler. diff --git a/bindings/kafka/kafka.go b/bindings/kafka/kafka.go index ddcb899bb6..266c4a43b2 100644 --- a/bindings/kafka/kafka.go +++ b/bindings/kafka/kafka.go @@ -138,9 +138,8 @@ func adaptHandler(handler bindings.Handler) kafka.EventHandler { } // GetComponentMetadata returns the metadata of the component. -func (b *Binding) GetComponentMetadata() map[string]string { +func (b *Binding) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := kafka.KafkaMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) - return metadataInfo + return } diff --git a/bindings/kitex/kitex_output.go b/bindings/kitex/kitex_output.go index 4709218df3..171a832837 100644 --- a/bindings/kitex/kitex_output.go +++ b/bindings/kitex/kitex_output.go @@ -18,6 +18,7 @@ import ( "sync" "github.com/dapr/components-contrib/bindings" + "github.com/dapr/components-contrib/metadata" "github.com/dapr/kit/logger" ) @@ -79,7 +80,6 @@ func (out *kitexOutputBinding) Operations() []bindings.OperationKind { } // GetComponentMetadata returns the metadata of the component. -func (out *kitexOutputBinding) GetComponentMetadata() map[string]string { - metadataInfo := map[string]string{} - return metadataInfo +func (out *kitexOutputBinding) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { + return } diff --git a/bindings/kubemq/kubemq.go b/bindings/kubemq/kubemq.go index dde819568a..bee647248e 100644 --- a/bindings/kubemq/kubemq.go +++ b/bindings/kubemq/kubemq.go @@ -172,9 +172,8 @@ func (k *kubeMQ) processQueueMessage(ctx context.Context, handler bindings.Handl } // GetComponentMetadata returns the metadata of the component. -func (k *kubeMQ) GetComponentMetadata() map[string]string { +func (k *kubeMQ) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := options{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/kubernetes/kubernetes.go b/bindings/kubernetes/kubernetes.go index f854fa6678..0312888db3 100644 --- a/bindings/kubernetes/kubernetes.go +++ b/bindings/kubernetes/kubernetes.go @@ -202,9 +202,8 @@ func (k *kubernetesInput) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (k *kubernetesInput) GetComponentMetadata() map[string]string { +func (k *kubernetesInput) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := kubernetesMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/localstorage/localstorage.go b/bindings/localstorage/localstorage.go index 654bc54346..79b10388ff 100644 --- a/bindings/localstorage/localstorage.go +++ b/bindings/localstorage/localstorage.go @@ -336,9 +336,8 @@ func (ls *LocalStorage) Invoke(_ context.Context, req *bindings.InvokeRequest) ( } // GetComponentMetadata returns the metadata of the component. -func (ls *LocalStorage) GetComponentMetadata() map[string]string { +func (ls *LocalStorage) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := Metadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/mqtt3/mqtt.go b/bindings/mqtt3/mqtt.go index d11ecb0b2c..bac9ae5ea6 100644 --- a/bindings/mqtt3/mqtt.go +++ b/bindings/mqtt3/mqtt.go @@ -384,9 +384,8 @@ func (m *MQTT) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (m *MQTT) GetComponentMetadata() map[string]string { +func (m *MQTT) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := mqtt3Metadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/mysql/mysql.go b/bindings/mysql/mysql.go index 2127caf0f3..5143a02096 100644 --- a/bindings/mysql/mysql.go +++ b/bindings/mysql/mysql.go @@ -370,9 +370,8 @@ func (m *Mysql) convert(columnTypes []*sql.ColumnType, values []any) map[string] } // GetComponentMetadata returns the metadata of the component. -func (m *Mysql) GetComponentMetadata() map[string]string { +func (m *Mysql) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := mysqlMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/nacos/nacos.go b/bindings/nacos/nacos.go index c0e506f5e9..7296e70f65 100644 --- a/bindings/nacos/nacos.go +++ b/bindings/nacos/nacos.go @@ -457,9 +457,8 @@ func parseServerURL(s string) (*constant.ServerConfig, error) { } // GetComponentMetadata returns the metadata of the component. -func (n *Nacos) GetComponentMetadata() map[string]string { +func (n *Nacos) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := Settings{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/output_binding.go b/bindings/output_binding.go index 39f52988c5..42c46bb9ab 100644 --- a/bindings/output_binding.go +++ b/bindings/output_binding.go @@ -18,14 +18,16 @@ import ( "fmt" "github.com/dapr/components-contrib/health" + "github.com/dapr/components-contrib/metadata" ) // OutputBinding is the interface for an output binding, allowing users to invoke remote systems with optional payloads. type OutputBinding interface { + metadata.ComponentWithMetadata + Init(ctx context.Context, metadata Metadata) error Invoke(ctx context.Context, req *InvokeRequest) (*InvokeResponse, error) Operations() []OperationKind - GetComponentMetadata() map[string]string } func PingOutBinding(ctx context.Context, outputBinding OutputBinding) error { diff --git a/bindings/postgres/postgres.go b/bindings/postgres/postgres.go index 637b88d344..3a0ab98252 100644 --- a/bindings/postgres/postgres.go +++ b/bindings/postgres/postgres.go @@ -213,9 +213,8 @@ func (p *Postgres) exec(ctx context.Context, sql string, args ...any) (result in } // GetComponentMetadata returns the metadata of the component. -func (p *Postgres) GetComponentMetadata() map[string]string { +func (p *Postgres) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := psqlMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/postmark/postmark.go b/bindings/postmark/postmark.go index 21bece8a93..7560bff28b 100644 --- a/bindings/postmark/postmark.go +++ b/bindings/postmark/postmark.go @@ -161,9 +161,8 @@ func (p *Postmark) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bi } // GetComponentMetadata returns the metadata of the component. -func (p *Postmark) GetComponentMetadata() map[string]string { +func (p *Postmark) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := postmarkMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/rabbitmq/rabbitmq.go b/bindings/rabbitmq/rabbitmq.go index b8a59457f8..e10f7422f3 100644 --- a/bindings/rabbitmq/rabbitmq.go +++ b/bindings/rabbitmq/rabbitmq.go @@ -548,9 +548,8 @@ func (r *RabbitMQ) reset() (err error) { return err } -func (r *RabbitMQ) GetComponentMetadata() map[string]string { +func (r *RabbitMQ) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := rabbitMQMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/redis/redis.go b/bindings/redis/redis.go index 0da6043f0c..5d029886d3 100644 --- a/bindings/redis/redis.go +++ b/bindings/redis/redis.go @@ -145,9 +145,8 @@ func (r *Redis) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (r *Redis) GetComponentMetadata() map[string]string { +func (r *Redis) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := rediscomponent.Settings{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/rethinkdb/statechange/statechange.go b/bindings/rethinkdb/statechange/statechange.go index 0d3188b80e..81639d473c 100644 --- a/bindings/rethinkdb/statechange/statechange.go +++ b/bindings/rethinkdb/statechange/statechange.go @@ -166,9 +166,8 @@ func metadataToConfig(cfg map[string]string, logger logger.Logger) (StateConfig, } // GetComponentMetadata returns the metadata of the component. -func (b *Binding) GetComponentMetadata() map[string]string { +func (b *Binding) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := StateConfig{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/smtp/smtp.go b/bindings/smtp/smtp.go index 668b88ddda..12ff6473af 100644 --- a/bindings/smtp/smtp.go +++ b/bindings/smtp/smtp.go @@ -231,9 +231,8 @@ func (metadata Metadata) parseAddresses(addresses string) []string { } // GetComponentMetadata returns the metadata of the component. -func (s *Mailer) GetComponentMetadata() map[string]string { +func (s *Mailer) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := Metadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/twilio/sendgrid/sendgrid.go b/bindings/twilio/sendgrid/sendgrid.go index 1bb75ffbb6..1204c977a0 100644 --- a/bindings/twilio/sendgrid/sendgrid.go +++ b/bindings/twilio/sendgrid/sendgrid.go @@ -264,11 +264,10 @@ func (sg *SendGrid) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*b } // GetComponentMetadata returns the metadata of the component. -func (sg *SendGrid) GetComponentMetadata() map[string]string { +func (sg *SendGrid) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := sendGridMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } // Function that unmarshals the Dynamic Template Data JSON String into a map[string]any. diff --git a/bindings/twilio/sms/sms.go b/bindings/twilio/sms/sms.go index b4e35c5a5d..13723c6f0a 100644 --- a/bindings/twilio/sms/sms.go +++ b/bindings/twilio/sms/sms.go @@ -135,9 +135,8 @@ func (t *SMS) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*binding } // GetComponentMetadata returns the metadata of the component. -func (t *SMS) GetComponentMetadata() map[string]string { +func (t *SMS) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := twilioMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/wasm/output.go b/bindings/wasm/output.go index 9d80d5511e..429eb8f6a0 100644 --- a/bindings/wasm/output.go +++ b/bindings/wasm/output.go @@ -168,9 +168,8 @@ func detectImports(imports []api.FunctionDefinition) importMode { } // GetComponentMetadata returns the metadata of the component. -func (out *outputBinding) GetComponentMetadata() map[string]string { +func (out *outputBinding) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := wasm.InitMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/zeebe/command/command.go b/bindings/zeebe/command/command.go index 1e7ab1b71e..a0f8a76011 100644 --- a/bindings/zeebe/command/command.go +++ b/bindings/zeebe/command/command.go @@ -131,9 +131,8 @@ func (z *ZeebeCommand) Invoke(ctx context.Context, req *bindings.InvokeRequest) } // GetComponentMetadata returns the metadata of the component. -func (z *ZeebeCommand) GetComponentMetadata() map[string]string { +func (z *ZeebeCommand) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := zeebe.ClientMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/bindings/zeebe/jobworker/jobworker.go b/bindings/zeebe/jobworker/jobworker.go index 60703a4f02..21638ca26a 100644 --- a/bindings/zeebe/jobworker/jobworker.go +++ b/bindings/zeebe/jobworker/jobworker.go @@ -256,9 +256,8 @@ func (h *jobHandler) failJob(ctx context.Context, client worker.JobClient, job e } // GetComponentMetadata returns the metadata of the component. -func (z *ZeebeJobWorker) GetComponentMetadata() map[string]string { +func (z *ZeebeJobWorker) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := jobWorkerMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) - return metadataInfo + return } diff --git a/component-metadata-schema.json b/component-metadata-schema.json index be4333ad68..b6d7020727 100644 --- a/component-metadata-schema.json +++ b/component-metadata-schema.json @@ -76,7 +76,7 @@ "properties": { "name": { "type": "string", - "description": "Name of the built-in authentication profile.\nCurrently supports:\n\n- `azuread` (Azure AD, including Managed Identity)." + "description": "Name of the built-in authentication profile." }, "metadata": { "items": { diff --git a/configuration/azure/appconfig/appconfig.go b/configuration/azure/appconfig/appconfig.go index 2a27d410ee..a18f5d367c 100644 --- a/configuration/azure/appconfig/appconfig.go +++ b/configuration/azure/appconfig/appconfig.go @@ -338,9 +338,8 @@ func (r *ConfigurationStore) Unsubscribe(ctx context.Context, req *configuration } // GetComponentMetadata returns the metadata of the component. -func (r *ConfigurationStore) GetComponentMetadata() map[string]string { +func (r *ConfigurationStore) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := metadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.ConfigurationStoreType) - return metadataInfo + return } diff --git a/configuration/postgres/postgres.go b/configuration/postgres/postgres.go index 3a072da851..f5cef79234 100644 --- a/configuration/postgres/postgres.go +++ b/configuration/postgres/postgres.go @@ -376,9 +376,8 @@ func (p *ConfigurationStore) subscribeToChannel(ctx context.Context, pgNotifyCha } // GetComponentMetadata returns the metadata of the component. -func (p *ConfigurationStore) GetComponentMetadata() map[string]string { +func (p *ConfigurationStore) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := metadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.ConfigurationStoreType) - return metadataInfo + return } diff --git a/configuration/redis/redis.go b/configuration/redis/redis.go index 2ddb62012f..e5125e5601 100644 --- a/configuration/redis/redis.go +++ b/configuration/redis/redis.go @@ -245,9 +245,8 @@ func (r *ConfigurationStore) handleSubscribedChange(ctx context.Context, req *co } // GetComponentMetadata returns the metadata of the component. -func (r *ConfigurationStore) GetComponentMetadata() map[string]string { +func (r *ConfigurationStore) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := rediscomponent.Settings{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.ConfigurationStoreType) - return metadataInfo + return } diff --git a/configuration/store.go b/configuration/store.go index 0a82b4d8a2..c0f167fe57 100644 --- a/configuration/store.go +++ b/configuration/store.go @@ -13,10 +13,16 @@ limitations under the License. package configuration -import "context" +import ( + "context" + + "github.com/dapr/components-contrib/metadata" +) // Store is an interface to perform operations on store. type Store interface { + metadata.ComponentWithMetadata + // Init configuration store. Init(ctx context.Context, metadata Metadata) error @@ -28,9 +34,6 @@ type Store interface { // Unsubscribe configuration with keys Unsubscribe(ctx context.Context, req *UnsubscribeRequest) error - - // GetComponentMetadata returns information on the component's metadata. - GetComponentMetadata() map[string]string } // UpdateHandler is the handler used to send event to daprd. diff --git a/crypto/azure/keyvault/component.go b/crypto/azure/keyvault/component.go index b009ed00a5..558775b919 100644 --- a/crypto/azure/keyvault/component.go +++ b/crypto/azure/keyvault/component.go @@ -406,11 +406,10 @@ func (keyvaultCrypto) SupportedSignatureAlgorithms() []string { return signatureAlgsList } -func (keyvaultCrypto) GetComponentMetadata() map[string]string { +func (keyvaultCrypto) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := keyvaultMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.CryptoType) - return metadataInfo + return } type keyID struct { diff --git a/crypto/jwks/component.go b/crypto/jwks/component.go index 56e22c1184..42a18d11d9 100644 --- a/crypto/jwks/component.go +++ b/crypto/jwks/component.go @@ -126,9 +126,8 @@ func (k *jwksCrypto) retrieveKeyFromSecretFn(parentCtx context.Context, kid stri return key, nil } -func (k *jwksCrypto) GetComponentMetadata() map[string]string { +func (k *jwksCrypto) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := jwksMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.CryptoType) - return metadataInfo + return } diff --git a/crypto/kubernetes/secrets/component.go b/crypto/kubernetes/secrets/component.go index c4a7436533..7acd88238d 100644 --- a/crypto/kubernetes/secrets/component.go +++ b/crypto/kubernetes/secrets/component.go @@ -28,7 +28,7 @@ import ( contribCrypto "github.com/dapr/components-contrib/crypto" kubeclient "github.com/dapr/components-contrib/internal/authentication/kubernetes" - contribMetadata "github.com/dapr/components-contrib/metadata" + "github.com/dapr/components-contrib/metadata" internals "github.com/dapr/kit/crypto" "github.com/dapr/kit/logger" ) @@ -136,9 +136,8 @@ func (k *kubeSecretsCrypto) parseKeyString(param string) (namespace string, secr return } -func (kubeSecretsCrypto) GetComponentMetadata() map[string]string { +func (kubeSecretsCrypto) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := secretsMetadata{} - metadataInfo := map[string]string{} - contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.CryptoType) - return metadataInfo + metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.CryptoType) + return } diff --git a/crypto/localstorage/component.go b/crypto/localstorage/component.go index 45cc7f654c..f74bae7d03 100644 --- a/crypto/localstorage/component.go +++ b/crypto/localstorage/component.go @@ -105,9 +105,8 @@ func (l *localStorageCrypto) retrieveKey(parentCtx context.Context, key string) return jwkObj, nil } -func (localStorageCrypto) GetComponentMetadata() map[string]string { +func (localStorageCrypto) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := localStorageMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.CryptoType) - return metadataInfo + return } diff --git a/crypto/subtlecrypto.go b/crypto/subtlecrypto.go index dad9dba3c1..6f227f807d 100644 --- a/crypto/subtlecrypto.go +++ b/crypto/subtlecrypto.go @@ -17,10 +17,14 @@ import ( "context" "github.com/lestrrat-go/jwx/v2/jwk" + + "github.com/dapr/components-contrib/metadata" ) // SubtleCrypto offers an interface to perform low-level ("subtle") cryptographic operations with keys stored in a vault. type SubtleCrypto interface { + metadata.ComponentWithMetadata + SubtleCryptoAlgorithms // Init the component. @@ -161,9 +165,6 @@ type SubtleCrypto interface { valid bool, err error, ) - - // GetComponentMetadata returns information on the component's metadata. - GetComponentMetadata() map[string]string } // SubtleCryptoAlgorithms is an extension to SubtleCrypto that includes methods to return information on the supported algorithms. diff --git a/internal/component/azure/blobstorage/metadata.go b/internal/component/azure/blobstorage/metadata.go index 4a24f72f09..743ecbeebd 100644 --- a/internal/component/azure/blobstorage/metadata.go +++ b/internal/component/azure/blobstorage/metadata.go @@ -25,7 +25,7 @@ import ( type BlobStorageMetadata struct { ContainerClientOpts `json:",inline" mapstructure:",squash"` - DecodeBase64 bool `json:"decodeBase64,string" mapstructure:"decodeBase64" only:"bindings"` + DecodeBase64 bool `json:"decodeBase64,string" mapstructure:"decodeBase64" mdonly:"bindings"` PublicAccessLevel azblob.PublicAccessType } diff --git a/internal/component/azure/eventhubs/metadata.go b/internal/component/azure/eventhubs/metadata.go index 4f6152c198..2547f7fb73 100644 --- a/internal/component/azure/eventhubs/metadata.go +++ b/internal/component/azure/eventhubs/metadata.go @@ -40,9 +40,8 @@ type AzureEventHubsMetadata struct { ResourceGroupName string `json:"resourceGroupName" mapstructure:"resourceGroupName"` // Binding only - EventHub string `json:"eventHub" mapstructure:"eventHub" only:"bindings"` - ConsumerGroup string `json:"consumerGroup" mapstructure:"consumerGroup" only:"bindings"` // Alias for ConsumerID - PartitionID string `json:"partitionID" mapstructure:"partitionID" only:"bindings"` // Deprecated + EventHub string `json:"eventHub" mapstructure:"eventHub" mdonly:"bindings"` + ConsumerGroup string `json:"consumerGroup" mapstructure:"consumerGroup" mdonly:"bindings"` // Alias for ConsumerID // Internal properties namespaceName string @@ -91,16 +90,9 @@ func parseEventHubsMetadata(meta map[string]string, isBinding bool, log logger.L return nil, errors.New("the provided connection string does not contain a value for 'EntityPath' and no 'eventHub' property was passed") } } - - // Property partitionID is deprecated - if m.PartitionID != "" { - log.Info("Property partitionID is deprecated and will be ignored") - m.PartitionID = "" - } } else { // Ignored when not a binding m.EventHub = "" - m.PartitionID = "" // If connecting using a connection string, parse hubName if m.ConnectionString != "" { diff --git a/internal/component/azure/servicebus/metadata.go b/internal/component/azure/servicebus/metadata.go index 84950e9583..5f49e23e9c 100644 --- a/internal/component/azure/servicebus/metadata.go +++ b/internal/component/azure/servicebus/metadata.go @@ -49,7 +49,7 @@ type Metadata struct { NamespaceName string `mapstructure:"namespaceName"` // Only for Azure AD /** For bindings only **/ - QueueName string `mapstructure:"queueName" only:"bindings"` // Only queues + QueueName string `mapstructure:"queueName" mdonly:"bindings"` // Only queues } // Keys. diff --git a/internal/component/postgresql/postgresql.go b/internal/component/postgresql/postgresql.go index f44d8abdfa..76af6bb568 100644 --- a/internal/component/postgresql/postgresql.go +++ b/internal/component/postgresql/postgresql.go @@ -120,9 +120,8 @@ func (p *PostgreSQL) GetDBAccess() dbAccess { return p.dbaccess } -func (p *PostgreSQL) GetComponentMetadata() map[string]string { +func (p *PostgreSQL) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := postgresMetadataStruct{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/internal/component/redis/settings.go b/internal/component/redis/settings.go index f71afff8ef..172e7a183e 100644 --- a/internal/component/redis/settings.go +++ b/internal/component/redis/settings.go @@ -79,23 +79,23 @@ type Settings struct { EnableTLS bool `mapstructure:"enableTLS"` // == state only properties == - TTLInSeconds *int `mapstructure:"ttlInSeconds" only:"state"` - QueryIndexes string `mapstructure:"queryIndexes" only:"state"` + TTLInSeconds *int `mapstructure:"ttlInSeconds" mdonly:"state"` + QueryIndexes string `mapstructure:"queryIndexes" mdonly:"state"` // == pubsub only properties == // The consumer identifier - ConsumerID string `mapstructure:"consumerID" only:"pubsub"` + ConsumerID string `mapstructure:"consumerID" mdonly:"pubsub"` // The interval between checking for pending messages to redelivery (0 disables redelivery) - RedeliverInterval time.Duration `mapstructure:"-" only:"pubsub"` + RedeliverInterval time.Duration `mapstructure:"-" mdonly:"pubsub"` // The amount time a message must be pending before attempting to redeliver it (0 disables redelivery) - ProcessingTimeout time.Duration `mapstructure:"processingTimeout" only:"pubsub"` + ProcessingTimeout time.Duration `mapstructure:"processingTimeout" mdonly:"pubsub"` // The size of the message queue for processing - QueueDepth uint `mapstructure:"queueDepth" only:"pubsub"` + QueueDepth uint `mapstructure:"queueDepth" mdonly:"pubsub"` // The number of concurrent workers that are processing messages - Concurrency uint `mapstructure:"concurrency" only:"pubsub"` + Concurrency uint `mapstructure:"concurrency" mdonly:"pubsub"` - // the max len of stream - MaxLenApprox int64 `mapstructure:"maxLenApprox" only:"pubsub"` + // The max len of stream + MaxLenApprox int64 `mapstructure:"maxLenApprox" mdonly:"pubsub"` } func (s *Settings) Decode(in interface{}) error { diff --git a/lock/redis/standalone.go b/lock/redis/standalone.go index 672b78e85c..12f3305de0 100644 --- a/lock/redis/standalone.go +++ b/lock/redis/standalone.go @@ -183,9 +183,8 @@ func (r *StandaloneRedisLock) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (r *StandaloneRedisLock) GetComponentMetadata() map[string]string { +func (r *StandaloneRedisLock) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := rediscomponent.Settings{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.LockStoreType) - return metadataInfo + return } diff --git a/lock/store.go b/lock/store.go index 9617a9d11b..0fb1758e2c 100644 --- a/lock/store.go +++ b/lock/store.go @@ -13,9 +13,15 @@ limitations under the License. package lock -import "context" +import ( + "context" + + "github.com/dapr/components-contrib/metadata" +) type Store interface { + metadata.ComponentWithMetadata + // Init this component. InitLockStore(ctx context.Context, metadata Metadata) error @@ -24,7 +30,4 @@ type Store interface { // Unlock tries to release a lock. Unlock(ctx context.Context, req *UnlockRequest) (*UnlockResponse, error) - - // GetComponentMetadata returns information on the component's metadata. - GetComponentMetadata() map[string]string } diff --git a/metadata/componentmetadata.go b/metadata/componentmetadata.go new file mode 100644 index 0000000000..d7dd83e6b6 --- /dev/null +++ b/metadata/componentmetadata.go @@ -0,0 +1,23 @@ +//go:build !metadata +// +build !metadata + +/* +Copyright 2021 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 metadata + +// ComponentWithMetadata is empty when the `metadata` build tag is not present. +// The build tag is present when running the linter. +type ComponentWithMetadata interface { + // Empty +} diff --git a/metadata/componentmetadata_metadata.go b/metadata/componentmetadata_metadata.go new file mode 100644 index 0000000000..3aa007d8e6 --- /dev/null +++ b/metadata/componentmetadata_metadata.go @@ -0,0 +1,23 @@ +//go:build metadata +// +build metadata + +/* +Copyright 2021 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 metadata + +// ComponentWithMetadata includes the GetComponentMetadata method when the `metadata` build tag is present. +// The build tag is present when running the linter. +type ComponentWithMetadata interface { + GetComponentMetadata() MetadataMap +} diff --git a/metadata/utils.go b/metadata/utils.go index 49d1811a84..1c9248c9ab 100644 --- a/metadata/utils.go +++ b/metadata/utils.go @@ -140,7 +140,7 @@ func GetMetadataProperty(props map[string]string, keys ...string) (val string, o // DecodeMetadata decodes metadata into a struct // This is an extension of mitchellh/mapstructure which also supports decoding durations -func DecodeMetadata(input interface{}, result interface{}) error { +func DecodeMetadata(input any, result any) error { // avoids a common mistake of passing the metadata struct, instead of the properties map // if input is of type struct, case it to metadata.Base and access the Properties instead v := reflect.ValueOf(input) @@ -174,8 +174,8 @@ func toTruthyBoolHookFunc() mapstructure.DecodeHookFunc { return func( f reflect.Type, t reflect.Type, - data interface{}, - ) (interface{}, error) { + data any, + ) (any, error) { if f == reflect.TypeOf("") && t == reflect.TypeOf(true) { val := data.(string) return utils.IsTruthy(val), nil @@ -192,8 +192,8 @@ func toStringArrayHookFunc() mapstructure.DecodeHookFunc { return func( f reflect.Type, t reflect.Type, - data interface{}, - ) (interface{}, error) { + data any, + ) (any, error) { if f == reflect.TypeOf("") && t == reflect.TypeOf([]string{}) { val := data.(string) return strings.Split(val, ","), nil @@ -231,8 +231,8 @@ func toTimeDurationArrayHookFunc() mapstructure.DecodeHookFunc { return func( f reflect.Type, t reflect.Type, - data interface{}, - ) (interface{}, error) { + data any, + ) (any, error) { if f == reflect.TypeOf("") && t == reflect.TypeOf([]time.Duration{}) { inputArrayString := data.(string) return convert(inputArrayString) @@ -296,9 +296,22 @@ func (t ComponentType) BuiltInMetadataProperties() []string { } } +type MetadataField struct { + // Field type + Type string + // True if the field should be ignored by the metadata analyzer + Ignored bool + // True if the field is deprecated + Deprecated bool + // Aliases used for old, deprecated names + Aliases []string +} + +type MetadataMap map[string]MetadataField + // GetMetadataInfoFromStructType converts a struct to a map of field name (or struct tag) to field type. // This is used to generate metadata documentation for components. -func GetMetadataInfoFromStructType(t reflect.Type, metadataMap *map[string]string, componentType ComponentType) error { +func GetMetadataInfoFromStructType(t reflect.Type, metadataMap *MetadataMap, componentType ComponentType) error { // Return if not struct or pointer to struct. if t.Kind() == reflect.Ptr { t = t.Elem() @@ -307,6 +320,10 @@ func GetMetadataInfoFromStructType(t reflect.Type, metadataMap *map[string]strin return fmt.Errorf("not a struct: %s", t.Kind().String()) } + if *metadataMap == nil { + *metadataMap = MetadataMap{} + } + for i := 0; i < t.NumField(); i++ { currentField := t.Field(i) // fields that are not exported cannot be set via the mapstructure metadata decoding mechanism @@ -318,10 +335,11 @@ func GetMetadataInfoFromStructType(t reflect.Type, metadataMap *map[string]strin if mapStructureTag == "-" { continue } - onlyTag := currentField.Tag.Get("only") - if onlyTag != "" { + + // If there's a "mdonly" tag, that metadata option is only included for certain component types + if mdOnlyTag := currentField.Tag.Get("mdonly"); mdOnlyTag != "" { include := false - onlyTags := strings.Split(onlyTag, ",") + onlyTags := strings.Split(mdOnlyTag, ",") for _, tag := range onlyTags { if tag == string(componentType) { include = true @@ -332,6 +350,24 @@ func GetMetadataInfoFromStructType(t reflect.Type, metadataMap *map[string]strin continue } } + + mdField := MetadataField{ + Type: currentField.Type.String(), + } + + // If there's a mdignore tag and that's truthy, the field should be ignored by the metadata analyzer + mdField.Ignored = utils.IsTruthy(currentField.Tag.Get("mdignore")) + + // If there's a "mddeprecated" tag, the field may be deprecated + mdField.Deprecated = utils.IsTruthy(currentField.Tag.Get("mddeprecated")) + + // If there's a "mdaliases" tag, the field contains aliases + // The value is a comma-separated string + if mdAliasesTag := currentField.Tag.Get("mdaliases"); mdAliasesTag != "" { + mdField.Aliases = strings.Split(mdAliasesTag, ",") + } + + // Handle mapstructure tags and get the field name mapStructureTags := strings.Split(mapStructureTag, ",") numTags := len(mapStructureTags) if numTags > 1 && mapStructureTags[numTags-1] == "squash" && currentField.Anonymous { @@ -345,7 +381,9 @@ func GetMetadataInfoFromStructType(t reflect.Type, metadataMap *map[string]strin } else { fieldName = currentField.Name } - (*metadataMap)[fieldName] = currentField.Type.String() + + // Add the field + (*metadataMap)[fieldName] = mdField } return nil diff --git a/metadata/utils_test.go b/metadata/utils_test.go index a26f9a608a..33a4af23c5 100644 --- a/metadata/utils_test.go +++ b/metadata/utils_test.go @@ -245,33 +245,61 @@ func TestMetadataStructToStringMap(t *testing.T) { Mybool *bool MyRegularDuration time.Duration SomethingWithCustomName string `mapstructure:"something_with_custom_name"` - PubSubOnlyProperty string `mapstructure:"pubsub_only_property" only:"pubsub"` - BindingOnlyProperty string `mapstructure:"binding_only_property" only:"bindings"` - PubSubAndBindingProperty string `mapstructure:"pubsub_and_binding_property" only:"pubsub,bindings"` + PubSubOnlyProperty string `mapstructure:"pubsub_only_property" mdonly:"pubsub"` + BindingOnlyProperty string `mapstructure:"binding_only_property" mdonly:"bindings"` + PubSubAndBindingProperty string `mapstructure:"pubsub_and_binding_property" mdonly:"pubsub,bindings"` MyDurationArray []time.Duration NotExportedByMapStructure string `mapstructure:"-"` notExported string //nolint:structcheck,unused + DeprecatedProperty string `mapstructure:"something_deprecated" mddeprecated:"true"` + Aliased string `mapstructure:"aliased" mdaliases:"another,name"` + Ignored string `mapstructure:"ignored" mdignore:"true"` } m := testMetadata{} - metadatainfo := map[string]string{} + metadatainfo := MetadataMap{} GetMetadataInfoFromStructType(reflect.TypeOf(m), &metadatainfo, BindingType) - assert.Equal(t, "string", metadatainfo["Mystring"]) - assert.Equal(t, "metadata.Duration", metadatainfo["Myduration"]) - assert.Equal(t, "int", metadatainfo["Myinteger"]) - assert.Equal(t, "float64", metadatainfo["Myfloat64"]) - assert.Equal(t, "*bool", metadatainfo["Mybool"]) - assert.Equal(t, "time.Duration", metadatainfo["MyRegularDuration"]) - assert.Equal(t, "string", metadatainfo["something_with_custom_name"]) + _ = assert.NotEmpty(t, metadatainfo["Mystring"]) && + assert.Equal(t, "string", metadatainfo["Mystring"].Type) + _ = assert.NotEmpty(t, metadatainfo["Myduration"]) && + assert.Equal(t, "metadata.Duration", metadatainfo["Myduration"].Type) + _ = assert.NotEmpty(t, metadatainfo["Myinteger"]) && + assert.Equal(t, "int", metadatainfo["Myinteger"].Type) + _ = assert.NotEmpty(t, metadatainfo["Myfloat64"]) && + assert.Equal(t, "float64", metadatainfo["Myfloat64"].Type) + _ = assert.NotEmpty(t, metadatainfo["Mybool"]) && + assert.Equal(t, "*bool", metadatainfo["Mybool"].Type) + _ = assert.NotEmpty(t, metadatainfo["MyRegularDuration"]) && + assert.Equal(t, "time.Duration", metadatainfo["MyRegularDuration"].Type) + _ = assert.NotEmpty(t, metadatainfo["something_with_custom_name"]) && + assert.Equal(t, "string", metadatainfo["something_with_custom_name"].Type) assert.NotContains(t, metadatainfo, "NestedStruct") assert.NotContains(t, metadatainfo, "SomethingWithCustomName") - assert.Equal(t, "string", metadatainfo["nested_string_custom"]) - assert.Equal(t, "string", metadatainfo["NestedString"]) + _ = assert.NotEmpty(t, metadatainfo["nested_string_custom"]) && + assert.Equal(t, "string", metadatainfo["nested_string_custom"].Type) + _ = assert.NotEmpty(t, metadatainfo["NestedString"]) && + assert.Equal(t, "string", metadatainfo["NestedString"].Type) assert.NotContains(t, metadatainfo, "pubsub_only_property") - assert.Equal(t, "string", metadatainfo["binding_only_property"]) - assert.Equal(t, "string", metadatainfo["pubsub_and_binding_property"]) - assert.Equal(t, "[]time.Duration", metadatainfo["MyDurationArray"]) + _ = assert.NotEmpty(t, metadatainfo["binding_only_property"]) && + assert.Equal(t, "string", metadatainfo["binding_only_property"].Type) + _ = assert.NotEmpty(t, metadatainfo["pubsub_and_binding_property"]) && + assert.Equal(t, "string", metadatainfo["pubsub_and_binding_property"].Type) + _ = assert.NotEmpty(t, metadatainfo["MyDurationArray"]) && + assert.Equal(t, "[]time.Duration", metadatainfo["MyDurationArray"].Type) assert.NotContains(t, metadatainfo, "NotExportedByMapStructure") assert.NotContains(t, metadatainfo, "notExported") + _ = assert.NotEmpty(t, metadatainfo["something_deprecated"]) && + assert.Equal(t, "string", metadatainfo["something_deprecated"].Type) && + assert.True(t, metadatainfo["something_deprecated"].Deprecated) + _ = assert.NotEmpty(t, metadatainfo["aliased"]) && + assert.Equal(t, "string", metadatainfo["aliased"].Type) && + assert.False(t, metadatainfo["aliased"].Deprecated) && + assert.False(t, metadatainfo["aliased"].Ignored) && + assert.Equal(t, []string{"another", "name"}, metadatainfo["aliased"].Aliases) + _ = assert.NotEmpty(t, metadatainfo["ignored"]) && + assert.Equal(t, "string", metadatainfo["ignored"].Type) && + assert.False(t, metadatainfo["ignored"].Deprecated) && + assert.True(t, metadatainfo["ignored"].Ignored) && + assert.Empty(t, metadatainfo["ignored"].Aliases) }) } diff --git a/middleware/http/bearer/bearer_middleware.go b/middleware/http/bearer/bearer_middleware.go index 404dd2dcd0..030403716a 100644 --- a/middleware/http/bearer/bearer_middleware.go +++ b/middleware/http/bearer/bearer_middleware.go @@ -126,9 +126,8 @@ func (m *Middleware) GetHandler(ctx context.Context, metadata middleware.Metadat }, nil } -func (m *Middleware) GetComponentMetadata() map[string]string { +func (m *Middleware) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := bearerMiddlewareMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.MiddlewareType) - return metadataInfo + return } diff --git a/middleware/http/oauth2/oauth2_middleware.go b/middleware/http/oauth2/oauth2_middleware.go index 7a7cb78c72..6ad773ea8d 100644 --- a/middleware/http/oauth2/oauth2_middleware.go +++ b/middleware/http/oauth2/oauth2_middleware.go @@ -155,9 +155,8 @@ func (m *Middleware) getNativeMetadata(metadata middleware.Metadata) (*oAuth2Mid return &middlewareMetadata, nil } -func (m *Middleware) GetComponentMetadata() map[string]string { +func (m *Middleware) GetComponentMetadata() (metadataInfo mdutils.MetadataMap) { metadataStruct := oAuth2MiddlewareMetadata{} - metadataInfo := map[string]string{} mdutils.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, mdutils.MiddlewareType) - return metadataInfo + return } diff --git a/middleware/http/oauth2clientcredentials/oauth2clientcredentials_middleware.go b/middleware/http/oauth2clientcredentials/oauth2clientcredentials_middleware.go index f71a7ae36a..a3cfff4036 100644 --- a/middleware/http/oauth2clientcredentials/oauth2clientcredentials_middleware.go +++ b/middleware/http/oauth2clientcredentials/oauth2clientcredentials_middleware.go @@ -178,9 +178,8 @@ func (m *Middleware) GetToken(ctx context.Context, conf *clientcredentials.Confi return tokenSource.Token() } -func (m *Middleware) GetComponentMetadata() map[string]string { +func (m *Middleware) GetComponentMetadata() (metadataInfo mdutils.MetadataMap) { metadataStruct := oAuth2ClientCredentialsMiddlewareMetadata{} - metadataInfo := map[string]string{} mdutils.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, mdutils.MiddlewareType) - return metadataInfo + return } diff --git a/middleware/http/opa/middleware.go b/middleware/http/opa/middleware.go index 12175152ae..c0c664441f 100644 --- a/middleware/http/opa/middleware.go +++ b/middleware/http/opa/middleware.go @@ -260,9 +260,8 @@ func (m *Middleware) getNativeMetadata(metadata middleware.Metadata) (*middlewar return &meta, nil } -func (m *Middleware) GetComponentMetadata() map[string]string { +func (m *Middleware) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := middlewareMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.MiddlewareType) - return metadataInfo + return } diff --git a/middleware/http/ratelimit/ratelimit_middleware.go b/middleware/http/ratelimit/ratelimit_middleware.go index 1bd342b425..b3caa87821 100644 --- a/middleware/http/ratelimit/ratelimit_middleware.go +++ b/middleware/http/ratelimit/ratelimit_middleware.go @@ -101,9 +101,8 @@ func (m *Middleware) getNativeMetadata(metadata middleware.Metadata) (*rateLimit return &middlewareMetadata, nil } -func (m *Middleware) GetComponentMetadata() map[string]string { +func (m *Middleware) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := rateLimitMiddlewareMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.MiddlewareType) - return metadataInfo + return } diff --git a/middleware/http/routeralias/routeralias_middleware.go b/middleware/http/routeralias/routeralias_middleware.go index 36ed67310e..1ac1929955 100644 --- a/middleware/http/routeralias/routeralias_middleware.go +++ b/middleware/http/routeralias/routeralias_middleware.go @@ -18,6 +18,7 @@ import ( "errors" "fmt" "net/http" + "reflect" "github.com/gorilla/mux" "gopkg.in/yaml.v3" @@ -118,6 +119,10 @@ func vars(r *http.Request) map[string]string { return nil } -func (m *Middleware) GetComponentMetadata() map[string]string { - return map[string]string{} +func (m *Middleware) GetComponentMetadata() (metadataInfo mdutils.MetadataMap) { + metadataStruct := struct { + Routes string `mapstructure:"routes"` + }{} + mdutils.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, mdutils.MiddlewareType) + return } diff --git a/middleware/http/routerchecker/routerchecker_middleware.go b/middleware/http/routerchecker/routerchecker_middleware.go index ed9bd5ce32..eaf01825eb 100644 --- a/middleware/http/routerchecker/routerchecker_middleware.go +++ b/middleware/http/routerchecker/routerchecker_middleware.go @@ -74,9 +74,8 @@ func (m *Middleware) getNativeMetadata(metadata middleware.Metadata) (*Metadata, return &middlewareMetadata, nil } -func (m *Middleware) GetComponentMetadata() map[string]string { +func (m *Middleware) GetComponentMetadata() (metadataInfo mdutils.MetadataMap) { metadataStruct := Metadata{} - metadataInfo := map[string]string{} mdutils.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, mdutils.MiddlewareType) - return metadataInfo + return } diff --git a/middleware/http/sentinel/middleware.go b/middleware/http/sentinel/middleware.go index 8ea851ac33..4680824d07 100644 --- a/middleware/http/sentinel/middleware.go +++ b/middleware/http/sentinel/middleware.go @@ -157,9 +157,8 @@ func getNativeMetadata(metadata middleware.Metadata) (*middlewareMetadata, error return &md, nil } -func (m *Middleware) GetComponentMetadata() map[string]string { +func (m *Middleware) GetComponentMetadata() (metadataInfo mdutils.MetadataMap) { metadataStruct := middlewareMetadata{} - metadataInfo := map[string]string{} mdutils.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, mdutils.MiddlewareType) - return metadataInfo + return } diff --git a/middleware/http/wasm/httpwasm.go b/middleware/http/wasm/httpwasm.go index aa024f6a55..af707c8e2d 100644 --- a/middleware/http/wasm/httpwasm.go +++ b/middleware/http/wasm/httpwasm.go @@ -121,9 +121,8 @@ func (rh *requestHandler) Close() error { return rh.mw.Close(ctx) } -func (m *middleware) GetComponentMetadata() map[string]string { +func (m *middleware) GetComponentMetadata() (metadataInfo mdutils.MetadataMap) { metadataStruct := wasm.InitMetadata{} - metadataInfo := map[string]string{} mdutils.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, mdutils.MiddlewareType) - return metadataInfo + return } diff --git a/middleware/middleware.go b/middleware/middleware.go index 4e61da34f3..88e13660e5 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -21,5 +21,4 @@ import ( // Middleware is the interface for a middleware. type Middleware interface { GetHandler(ctx context.Context, metadata Metadata) (func(next http.Handler) http.Handler, error) - GetComponentMetadata() map[string]string } diff --git a/pubsub/aws/snssqs/snssqs.go b/pubsub/aws/snssqs/snssqs.go index 9c8fd09aad..1d71d21ae9 100644 --- a/pubsub/aws/snssqs/snssqs.go +++ b/pubsub/aws/snssqs/snssqs.go @@ -931,9 +931,8 @@ func (s *snsSqs) Features() []pubsub.Feature { } // GetComponentMetadata returns the metadata of the component. -func (s *snsSqs) GetComponentMetadata() map[string]string { +func (s *snsSqs) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := snsSqsMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/azure/eventhubs/eventhubs.go b/pubsub/azure/eventhubs/eventhubs.go index 7fca9570c7..766c904a0d 100644 --- a/pubsub/azure/eventhubs/eventhubs.go +++ b/pubsub/azure/eventhubs/eventhubs.go @@ -147,9 +147,8 @@ func (aeh *AzureEventHubs) Close() (err error) { } // GetComponentMetadata returns the metadata of the component. -func (aeh *AzureEventHubs) GetComponentMetadata() map[string]string { +func (aeh *AzureEventHubs) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := impl.AzureEventHubsMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/azure/servicebus/queues/servicebus.go b/pubsub/azure/servicebus/queues/servicebus.go index 2870efc08f..61328d3b61 100644 --- a/pubsub/azure/servicebus/queues/servicebus.go +++ b/pubsub/azure/servicebus/queues/servicebus.go @@ -227,10 +227,9 @@ func (a *azureServiceBus) Features() []pubsub.Feature { } // GetComponentMetadata returns the metadata of the component. -func (a *azureServiceBus) GetComponentMetadata() map[string]string { +func (a *azureServiceBus) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := impl.Metadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.PubSubType) - delete(metadataInfo, "consumerID") // does not apply to queues - return metadataInfo + delete(metadataInfo, "consumerID") // only applies to topics, not queues + return } diff --git a/pubsub/azure/servicebus/topics/servicebus.go b/pubsub/azure/servicebus/topics/servicebus.go index 244c045740..97fbb6baef 100644 --- a/pubsub/azure/servicebus/topics/servicebus.go +++ b/pubsub/azure/servicebus/topics/servicebus.go @@ -317,9 +317,8 @@ func (a *azureServiceBus) connectAndReceiveWithSessions(ctx context.Context, req } // GetComponentMetadata returns the metadata of the component. -func (a *azureServiceBus) GetComponentMetadata() map[string]string { +func (a *azureServiceBus) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := impl.Metadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/gcp/pubsub/pubsub.go b/pubsub/gcp/pubsub/pubsub.go index d960371737..43db539871 100644 --- a/pubsub/gcp/pubsub/pubsub.go +++ b/pubsub/gcp/pubsub/pubsub.go @@ -402,9 +402,8 @@ func (g *GCPPubSub) Features() []pubsub.Feature { } // GetComponentMetadata returns the metadata of the component. -func (g *GCPPubSub) GetComponentMetadata() map[string]string { +func (g *GCPPubSub) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := metadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/in-memory/in-memory.go b/pubsub/in-memory/in-memory.go index 1521230453..b6b4ab2696 100644 --- a/pubsub/in-memory/in-memory.go +++ b/pubsub/in-memory/in-memory.go @@ -21,6 +21,7 @@ import ( "time" "github.com/dapr/components-contrib/internal/eventbus" + "github.com/dapr/components-contrib/metadata" "github.com/dapr/components-contrib/pubsub" "github.com/dapr/kit/logger" ) @@ -112,6 +113,6 @@ func (a *bus) Subscribe(ctx context.Context, req pubsub.SubscribeRequest, handle } // GetComponentMetadata returns the metadata of the component. -func (a *bus) GetComponentMetadata() map[string]string { - return map[string]string{} +func (a *bus) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { + return } diff --git a/pubsub/jetstream/jetstream.go b/pubsub/jetstream/jetstream.go index 1c5f743360..e991a157c8 100644 --- a/pubsub/jetstream/jetstream.go +++ b/pubsub/jetstream/jetstream.go @@ -299,9 +299,8 @@ func sigHandler(seedKey string, nonce []byte) ([]byte, error) { } // GetComponentMetadata returns the metadata of the component. -func (js *jetstreamPubSub) GetComponentMetadata() map[string]string { +func (js *jetstreamPubSub) GetComponentMetadata() (metadataInfo mdutils.MetadataMap) { metadataStruct := metadata{} - metadataInfo := map[string]string{} mdutils.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, mdutils.PubSubType) - return metadataInfo + return } diff --git a/pubsub/kafka/kafka.go b/pubsub/kafka/kafka.go index c2902d55ac..c341c77ea8 100644 --- a/pubsub/kafka/kafka.go +++ b/pubsub/kafka/kafka.go @@ -177,9 +177,8 @@ func adaptBulkHandler(handler pubsub.BulkHandler) kafka.BulkEventHandler { } // GetComponentMetadata returns the metadata of the component. -func (p *PubSub) GetComponentMetadata() map[string]string { +func (p *PubSub) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := kafka.KafkaMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/kubemq/kubemq.go b/pubsub/kubemq/kubemq.go index b0760fc694..164a9f2a58 100644 --- a/pubsub/kubemq/kubemq.go +++ b/pubsub/kubemq/kubemq.go @@ -79,9 +79,8 @@ func getRandomID() string { } // GetComponentMetadata returns the metadata of the component. -func (k *kubeMQ) GetComponentMetadata() map[string]string { +func (k *kubeMQ) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := &kubemqMetadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/mqtt3/mqtt.go b/pubsub/mqtt3/mqtt.go index 1f5c9fab13..2d50fbcc89 100644 --- a/pubsub/mqtt3/mqtt.go +++ b/pubsub/mqtt3/mqtt.go @@ -495,9 +495,8 @@ func buildRegexForTopic(topicName string) string { } // GetComponentMetadata returns the metadata of the component. -func (m *mqttPubSub) GetComponentMetadata() map[string]string { +func (m *mqttPubSub) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := mqttMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/natsstreaming/natsstreaming.go b/pubsub/natsstreaming/natsstreaming.go index a45f66707e..51817ac721 100644 --- a/pubsub/natsstreaming/natsstreaming.go +++ b/pubsub/natsstreaming/natsstreaming.go @@ -363,9 +363,8 @@ func (n *natsStreamingPubSub) Features() []pubsub.Feature { } // GetComponentMetadata returns the metadata of the component. -func (n *natsStreamingPubSub) GetComponentMetadata() map[string]string { +func (n *natsStreamingPubSub) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := natsMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/pubsub.go b/pubsub/pubsub.go index c17ed652ad..fb83761a8a 100644 --- a/pubsub/pubsub.go +++ b/pubsub/pubsub.go @@ -18,16 +18,18 @@ import ( "fmt" "github.com/dapr/components-contrib/health" + "github.com/dapr/components-contrib/metadata" ) // PubSub is the interface for message buses. type PubSub interface { + metadata.ComponentWithMetadata + Init(ctx context.Context, metadata Metadata) error Features() []Feature Publish(ctx context.Context, req *PublishRequest) error Subscribe(ctx context.Context, req SubscribeRequest, handler Handler) error Close() error - GetComponentMetadata() map[string]string } // BulkPublisher is the interface that wraps the BulkPublish method. diff --git a/pubsub/pulsar/pulsar.go b/pubsub/pulsar/pulsar.go index bf49defa68..a04bac1acb 100644 --- a/pubsub/pulsar/pulsar.go +++ b/pubsub/pulsar/pulsar.go @@ -496,11 +496,10 @@ func (p *Pulsar) formatTopic(topic string) string { } // GetComponentMetadata returns the metadata of the component. -func (p *Pulsar) GetComponentMetadata() map[string]string { +func (p *Pulsar) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := pulsarMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.PubSubType) - return metadataInfo + return } // isValidPEM validates the provided input has PEM formatted block. diff --git a/pubsub/rabbitmq/rabbitmq.go b/pubsub/rabbitmq/rabbitmq.go index 249d5d8b70..e332b58ade 100644 --- a/pubsub/rabbitmq/rabbitmq.go +++ b/pubsub/rabbitmq/rabbitmq.go @@ -677,9 +677,8 @@ func mustReconnect(channel rabbitMQChannelBroker, err error) bool { } // GetComponentMetadata returns the metadata of the component. -func (r *rabbitMQ) GetComponentMetadata() map[string]string { +func (r *rabbitMQ) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := rabbitmqMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/redis/redis.go b/pubsub/redis/redis.go index bd501bd531..7beca3fe69 100644 --- a/pubsub/redis/redis.go +++ b/pubsub/redis/redis.go @@ -401,9 +401,8 @@ func (r *redisStreams) Ping(ctx context.Context) error { return nil } -func (r *redisStreams) GetComponentMetadata() map[string]string { +func (r *redisStreams) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := rediscomponent.Settings{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/rocketmq/rocketmq.go b/pubsub/rocketmq/rocketmq.go index 761680d928..83c54e74c6 100644 --- a/pubsub/rocketmq/rocketmq.go +++ b/pubsub/rocketmq/rocketmq.go @@ -554,9 +554,8 @@ func (r *rocketMQ) Close() error { } // GetComponentMetadata returns the metadata of the component. -func (r *rocketMQ) GetComponentMetadata() map[string]string { +func (r *rocketMQ) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := rocketMQMetaData{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.PubSubType) - return metadataInfo + return } diff --git a/pubsub/solace/amqp/amqp.go b/pubsub/solace/amqp/amqp.go index 8e56aaaa06..11a95e1977 100644 --- a/pubsub/solace/amqp/amqp.go +++ b/pubsub/solace/amqp/amqp.go @@ -327,9 +327,8 @@ func (a *amqpPubSub) Features() []pubsub.Feature { } // GetComponentMetadata returns the metadata of the component. -func (a *amqpPubSub) GetComponentMetadata() map[string]string { +func (a *amqpPubSub) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { metadataStruct := metadata{} - metadataInfo := map[string]string{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.PubSubType) - return metadataInfo + return } diff --git a/secretstores/alicloud/parameterstore/parameterstore.go b/secretstores/alicloud/parameterstore/parameterstore.go index 66ce2f85d9..df42109129 100644 --- a/secretstores/alicloud/parameterstore/parameterstore.go +++ b/secretstores/alicloud/parameterstore/parameterstore.go @@ -197,9 +197,8 @@ func (o *oosSecretStore) Features() []secretstores.Feature { return []secretstores.Feature{} // No Feature supported. } -func (o *oosSecretStore) GetComponentMetadata() map[string]string { +func (o *oosSecretStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := ParameterStoreMetaData{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo + return } diff --git a/secretstores/aws/parameterstore/parameterstore.go b/secretstores/aws/parameterstore/parameterstore.go index e66632aab5..fef4294f32 100644 --- a/secretstores/aws/parameterstore/parameterstore.go +++ b/secretstores/aws/parameterstore/parameterstore.go @@ -172,9 +172,8 @@ func (s *ssmSecretStore) Features() []secretstores.Feature { return []secretstores.Feature{} // No Feature supported. } -func (s *ssmSecretStore) GetComponentMetadata() map[string]string { +func (s *ssmSecretStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := ParameterStoreMetaData{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo + return } diff --git a/secretstores/aws/secretmanager/secretmanager.go b/secretstores/aws/secretmanager/secretmanager.go index 1403b2535e..d30ce79e96 100644 --- a/secretstores/aws/secretmanager/secretmanager.go +++ b/secretstores/aws/secretmanager/secretmanager.go @@ -165,9 +165,8 @@ func (s *smSecretStore) Features() []secretstores.Feature { return []secretstores.Feature{} // No Feature supported. } -func (s *smSecretStore) GetComponentMetadata() map[string]string { +func (s *smSecretStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := SecretManagerMetaData{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo + return } diff --git a/secretstores/azure/keyvault/keyvault.go b/secretstores/azure/keyvault/keyvault.go index 80ca7c077f..3dc97d1b62 100644 --- a/secretstores/azure/keyvault/keyvault.go +++ b/secretstores/azure/keyvault/keyvault.go @@ -206,9 +206,8 @@ func (k *keyvaultSecretStore) Features() []secretstores.Feature { return []secretstores.Feature{} // No Feature supported. } -func (k *keyvaultSecretStore) GetComponentMetadata() map[string]string { +func (k *keyvaultSecretStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := KeyvaultMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo + return } diff --git a/secretstores/gcp/secretmanager/secretmanager.go b/secretstores/gcp/secretmanager/secretmanager.go index ef6dc5a2a6..01ea2133f1 100644 --- a/secretstores/gcp/secretmanager/secretmanager.go +++ b/secretstores/gcp/secretmanager/secretmanager.go @@ -203,9 +203,8 @@ func (s *Store) Features() []secretstores.Feature { return []secretstores.Feature{} // No Feature supported. } -func (s *Store) GetComponentMetadata() map[string]string { +func (s *Store) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := GcpSecretManagerMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo + return } diff --git a/secretstores/hashicorp/vault/vault.go b/secretstores/hashicorp/vault/vault.go index f9daa7a6ec..8fabf2819d 100644 --- a/secretstores/hashicorp/vault/vault.go +++ b/secretstores/hashicorp/vault/vault.go @@ -531,9 +531,8 @@ func (v *vaultSecretStore) Features() []secretstores.Feature { return []secretstores.Feature{secretstores.FeatureMultipleKeyValuesPerSecret} } -func (v *vaultSecretStore) GetComponentMetadata() map[string]string { +func (v *vaultSecretStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := VaultMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo + return } diff --git a/secretstores/huaweicloud/csms/csms.go b/secretstores/huaweicloud/csms/csms.go index c7d73e01e3..797b48cb14 100644 --- a/secretstores/huaweicloud/csms/csms.go +++ b/secretstores/huaweicloud/csms/csms.go @@ -157,9 +157,8 @@ func (c *csmsSecretStore) Features() []secretstores.Feature { return []secretstores.Feature{} // No Feature supported. } -func (c *csmsSecretStore) GetComponentMetadata() map[string]string { +func (c *csmsSecretStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := CsmsSecretStoreMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo + return } diff --git a/secretstores/kubernetes/kubernetes.go b/secretstores/kubernetes/kubernetes.go index 030b7a980c..3147c1ba37 100644 --- a/secretstores/kubernetes/kubernetes.go +++ b/secretstores/kubernetes/kubernetes.go @@ -18,7 +18,6 @@ import ( "context" "errors" "os" - "reflect" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" @@ -117,10 +116,7 @@ func (k *kubernetesSecretStore) Features() []secretstores.Feature { return []secretstores.Feature{} } -func (k *kubernetesSecretStore) GetComponentMetadata() map[string]string { - type unusedMetadataStruct struct{} - metadataStruct := unusedMetadataStruct{} - metadataInfo := map[string]string{} - metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo +func (k *kubernetesSecretStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { + // No component metadata + return } diff --git a/secretstores/local/env/envstore.go b/secretstores/local/env/envstore.go index 4395f227fe..11dbf2b005 100644 --- a/secretstores/local/env/envstore.go +++ b/secretstores/local/env/envstore.go @@ -114,11 +114,10 @@ func (s *envSecretStore) Features() []secretstores.Feature { return []secretstores.Feature{} // No Feature supported. } -func (s *envSecretStore) GetComponentMetadata() map[string]string { +func (s *envSecretStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := Metadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo + return } func (s *envSecretStore) isKeyAllowed(key string) bool { diff --git a/secretstores/local/file/filestore.go b/secretstores/local/file/filestore.go index 4373b075ae..a9b065a4b4 100644 --- a/secretstores/local/file/filestore.go +++ b/secretstores/local/file/filestore.go @@ -277,9 +277,8 @@ func (j *localSecretStore) Features() []secretstores.Feature { return j.features } -func (j *localSecretStore) GetComponentMetadata() map[string]string { +func (j *localSecretStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := localSecretStoreMetaData{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo + return } diff --git a/secretstores/secret_store.go b/secretstores/secret_store.go index 4257222b57..2241ba7580 100644 --- a/secretstores/secret_store.go +++ b/secretstores/secret_store.go @@ -18,10 +18,13 @@ import ( "fmt" "github.com/dapr/components-contrib/health" + "github.com/dapr/components-contrib/metadata" ) // SecretStore is the interface for a component that handles secrets management. type SecretStore interface { + metadata.ComponentWithMetadata + // Init authenticates with the actual secret store and performs other init operation Init(ctx context.Context, metadata Metadata) error // GetSecret retrieves a secret using a key and returns a map of decrypted string/string values. @@ -30,8 +33,6 @@ type SecretStore interface { BulkGetSecret(ctx context.Context, req BulkGetSecretRequest) (BulkGetSecretResponse, error) // Features lists the features supported by the secret store. Features() []Feature - // GetComponentMetadata returns the metadata options for the secret store. - GetComponentMetadata() map[string]string } func Ping(ctx context.Context, secretStore SecretStore) error { diff --git a/secretstores/tencentcloud/ssm/ssm.go b/secretstores/tencentcloud/ssm/ssm.go index 9f7834c3af..d40887661a 100644 --- a/secretstores/tencentcloud/ssm/ssm.go +++ b/secretstores/tencentcloud/ssm/ssm.go @@ -193,9 +193,8 @@ func (s *ssmSecretStore) Features() []secretstores.Feature { return []secretstores.Feature{} // No Feature supported. } -func (s *ssmSecretStore) GetComponentMetadata() map[string]string { +func (s *ssmSecretStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := SsmMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.SecretStoreType) - return metadataInfo + return } diff --git a/state/aerospike/aerospike.go b/state/aerospike/aerospike.go index 9568a76296..0a27094376 100644 --- a/state/aerospike/aerospike.go +++ b/state/aerospike/aerospike.go @@ -271,9 +271,8 @@ func convertETag(eTag string) (uint32, error) { return uint32(i), nil } -func (aspike *Aerospike) GetComponentMetadata() map[string]string { +func (aspike *Aerospike) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := aerospikeMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/alicloud/tablestore/tablestore.go b/state/alicloud/tablestore/tablestore.go index 1ea6cf3cf9..cf31709c79 100644 --- a/state/alicloud/tablestore/tablestore.go +++ b/state/alicloud/tablestore/tablestore.go @@ -228,9 +228,8 @@ func (s *AliCloudTableStore) primaryKey(key string) *tablestore.PrimaryKey { return pk } -func (s *AliCloudTableStore) GetComponentMetadata() map[string]string { +func (s *AliCloudTableStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := tablestoreMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/aws/dynamodb/dynamodb.go b/state/aws/dynamodb/dynamodb.go index 094a801f00..ba7c3ab96b 100644 --- a/state/aws/dynamodb/dynamodb.go +++ b/state/aws/dynamodb/dynamodb.go @@ -223,11 +223,10 @@ func (d *StateStore) Delete(ctx context.Context, req *state.DeleteRequest) error return err } -func (d *StateStore) GetComponentMetadata() map[string]string { +func (d *StateStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := dynamoDBMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } func (d *StateStore) getDynamoDBMetadata(meta state.Metadata) (*dynamoDBMetadata, error) { diff --git a/state/azure/blobstorage/blobstorage.go b/state/azure/blobstorage/blobstorage.go index 65644c5c51..803d50bb50 100644 --- a/state/azure/blobstorage/blobstorage.go +++ b/state/azure/blobstorage/blobstorage.go @@ -106,11 +106,10 @@ func (r *StateStore) Ping(ctx context.Context) error { return nil } -func (r *StateStore) GetComponentMetadata() map[string]string { +func (r *StateStore) GetComponentMetadata() (metadataInfo mdutils.MetadataMap) { metadataStruct := storageinternal.BlobStorageMetadata{} - metadataInfo := map[string]string{} mdutils.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, mdutils.StateStoreType) - return metadataInfo + return } // NewAzureBlobStorageStore instance. diff --git a/state/azure/cosmosdb/cosmosdb.go b/state/azure/cosmosdb/cosmosdb.go index c809634747..622c091b06 100644 --- a/state/azure/cosmosdb/cosmosdb.go +++ b/state/azure/cosmosdb/cosmosdb.go @@ -106,11 +106,10 @@ func NewCosmosDBStateStore(logger logger.Logger) state.Store { return s } -func (c *StateStore) GetComponentMetadata() map[string]string { +func (c *StateStore) GetComponentMetadata() (metadataInfo contribmeta.MetadataMap) { metadataStruct := metadata{} - metadataInfo := map[string]string{} contribmeta.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribmeta.StateStoreType) - return metadataInfo + return } // Init does metadata and connection parsing. diff --git a/state/azure/tablestorage/tablestorage.go b/state/azure/tablestorage/tablestorage.go index 8c89c66766..41a5e558c2 100644 --- a/state/azure/tablestorage/tablestorage.go +++ b/state/azure/tablestorage/tablestorage.go @@ -204,11 +204,10 @@ func (r *StateStore) Set(ctx context.Context, req *state.SetRequest) error { return r.writeRow(ctx, req) } -func (r *StateStore) GetComponentMetadata() map[string]string { +func (r *StateStore) GetComponentMetadata() (metadataInfo mdutils.MetadataMap) { metadataStruct := tablesMetadata{} - metadataInfo := map[string]string{} mdutils.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, mdutils.StateStoreType) - return metadataInfo + return } func NewAzureTablesStateStore(logger logger.Logger) state.Store { diff --git a/state/bulk_test.go b/state/bulk_test.go index d9e098d7ce..9c179fe985 100644 --- a/state/bulk_test.go +++ b/state/bulk_test.go @@ -22,6 +22,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/dapr/components-contrib/metadata" ) var errSimulated = errors.New("simulated") @@ -162,8 +164,8 @@ func (s *storeBulk) Set(ctx context.Context, req *SetRequest) error { return nil } -func (s *storeBulk) GetComponentMetadata() map[string]string { - return map[string]string{} +func (s *storeBulk) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { + return } func (s *storeBulk) Features() []Feature { diff --git a/state/cassandra/cassandra.go b/state/cassandra/cassandra.go index 9a74a962a0..3ac0cda60a 100644 --- a/state/cassandra/cassandra.go +++ b/state/cassandra/cassandra.go @@ -320,11 +320,10 @@ func (c *Cassandra) createSession(consistency gocql.Consistency) (*gocql.Session return session, nil } -func (c *Cassandra) GetComponentMetadata() map[string]string { +func (c *Cassandra) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := cassandraMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } // Close the connection to Cassandra. diff --git a/state/cloudflare/workerskv/workerskv.go b/state/cloudflare/workerskv/workerskv.go index 3e54e785c8..c1a8609f6b 100644 --- a/state/cloudflare/workerskv/workerskv.go +++ b/state/cloudflare/workerskv/workerskv.go @@ -82,11 +82,10 @@ func (q *CFWorkersKV) Init(_ context.Context, metadata state.Metadata) error { return q.Base.Init(workerBindings, componentDocsURL, infoResponseValidate) } -func (q *CFWorkersKV) GetComponentMetadata() map[string]string { +func (q *CFWorkersKV) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := componentMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } // Features returns the features supported by this state store. diff --git a/state/couchbase/couchbase.go b/state/couchbase/couchbase.go index 0ea4293dc9..3da43f1567 100644 --- a/state/couchbase/couchbase.go +++ b/state/couchbase/couchbase.go @@ -266,9 +266,8 @@ func eTagToCas(eTag string) (gocb.Cas, error) { return cas, nil } -func (cbs *Couchbase) GetComponentMetadata() map[string]string { +func (cbs *Couchbase) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := couchbaseMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/etcd/etcd.go b/state/etcd/etcd.go index 30b5c93df1..4bac16a911 100644 --- a/state/etcd/etcd.go +++ b/state/etcd/etcd.go @@ -303,11 +303,10 @@ func (e *Etcd) doValidateEtag(key string, etag *string, concurrency string) erro return nil } -func (e *Etcd) GetComponentMetadata() map[string]string { +func (e *Etcd) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := etcdConfig{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } func (e *Etcd) Close() error { diff --git a/state/gcp/firestore/firestore.go b/state/gcp/firestore/firestore.go index 8697651a8c..efda8e7d9c 100644 --- a/state/gcp/firestore/firestore.go +++ b/state/gcp/firestore/firestore.go @@ -168,11 +168,10 @@ func (f *Firestore) Delete(ctx context.Context, req *state.DeleteRequest) error return nil } -func (f *Firestore) GetComponentMetadata() map[string]string { +func (f *Firestore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := firestoreMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } func getFirestoreMetadata(meta state.Metadata) (*firestoreMetadata, error) { diff --git a/state/hashicorp/consul/consul.go b/state/hashicorp/consul/consul.go index eb79055204..6c5a2c5a92 100644 --- a/state/hashicorp/consul/consul.go +++ b/state/hashicorp/consul/consul.go @@ -157,9 +157,8 @@ func (c *Consul) Delete(ctx context.Context, req *state.DeleteRequest) error { return nil } -func (c *Consul) GetComponentMetadata() map[string]string { +func (c *Consul) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := consulConfig{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/hazelcast/hazelcast.go b/state/hazelcast/hazelcast.go index 6fae9efb62..0a41f04848 100644 --- a/state/hazelcast/hazelcast.go +++ b/state/hazelcast/hazelcast.go @@ -159,9 +159,8 @@ func (store *Hazelcast) Delete(ctx context.Context, req *state.DeleteRequest) er return nil } -func (store *Hazelcast) GetComponentMetadata() map[string]string { +func (store *Hazelcast) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := hazelcastMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/in-memory/in_memory.go b/state/in-memory/in_memory.go index 1d3d0e4753..a05f2bd94e 100644 --- a/state/in-memory/in_memory.go +++ b/state/in-memory/in_memory.go @@ -26,6 +26,7 @@ import ( "github.com/google/uuid" "k8s.io/utils/clock" + "github.com/dapr/components-contrib/metadata" "github.com/dapr/components-contrib/state" "github.com/dapr/components-contrib/state/utils" "github.com/dapr/kit/logger" @@ -410,9 +411,9 @@ func (store *inMemoryStore) doCleanExpiredItems() { } } -func (store *inMemoryStore) GetComponentMetadata() map[string]string { +func (store *inMemoryStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { // no metadata, hence no metadata struct to convert here - return map[string]string{} + return } type inMemStateStoreItem struct { diff --git a/state/jetstream/jetstream.go b/state/jetstream/jetstream.go index c493d82d1a..fedb1e2f68 100644 --- a/state/jetstream/jetstream.go +++ b/state/jetstream/jetstream.go @@ -170,9 +170,8 @@ func escape(key string) string { return strings.ReplaceAll(key, "||", ".") } -func (js *StateStore) GetComponentMetadata() map[string]string { +func (js *StateStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := jetstreamMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/memcached/memcached.go b/state/memcached/memcached.go index be2f427bb3..d4171e13ff 100644 --- a/state/memcached/memcached.go +++ b/state/memcached/memcached.go @@ -217,9 +217,8 @@ func (m *Memcached) Close() (err error) { return nil } -func (m *Memcached) GetComponentMetadata() map[string]string { +func (m *Memcached) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := memcachedMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/mongodb/mongodb.go b/state/mongodb/mongodb.go index 26a8847f6d..c8dac85c20 100644 --- a/state/mongodb/mongodb.go +++ b/state/mongodb/mongodb.go @@ -675,11 +675,10 @@ func getReadConcernObject(cn string) (*readconcern.ReadConcern, error) { return nil, fmt.Errorf("readConcern %s not found", cn) } -func (m *MongoDB) GetComponentMetadata() map[string]string { +func (m *MongoDB) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := mongoDBMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } // Close connection to the database. diff --git a/state/mysql/mysql.go b/state/mysql/mysql.go index 4c94a41ba8..6e5f6414b9 100644 --- a/state/mysql/mysql.go +++ b/state/mysql/mysql.go @@ -893,9 +893,8 @@ type querier interface { QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row } -func (m *MySQL) GetComponentMetadata() map[string]string { +func (m *MySQL) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := mySQLMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/oci/objectstorage/objectstorage.go b/state/oci/objectstorage/objectstorage.go index 2612d086df..7ed5748eca 100644 --- a/state/oci/objectstorage/objectstorage.go +++ b/state/oci/objectstorage/objectstorage.go @@ -517,9 +517,8 @@ func (c *ociObjectStorageClient) pingBucket(ctx context.Context) error { return nil } -func (r *StateStore) GetComponentMetadata() map[string]string { +func (r *StateStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := objectStoreMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/oracledatabase/oracledatabase.go b/state/oracledatabase/oracledatabase.go index 570f36453e..32e883287b 100644 --- a/state/oracledatabase/oracledatabase.go +++ b/state/oracledatabase/oracledatabase.go @@ -98,9 +98,8 @@ func (o *OracleDatabase) getDB() *sql.DB { return o.dbaccess.(*oracleDatabaseAccess).db } -func (o *OracleDatabase) GetComponentMetadata() map[string]string { +func (o *OracleDatabase) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := oracleDatabaseMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/redis/redis.go b/state/redis/redis.go index 2435a26da8..d5e1c33ee4 100644 --- a/state/redis/redis.go +++ b/state/redis/redis.go @@ -547,10 +547,8 @@ func (r *StateStore) Close() error { return r.client.Close() } -func (r *StateStore) GetComponentMetadata() map[string]string { +func (r *StateStore) GetComponentMetadata() (metadataInfo daprmetadata.MetadataMap) { settingsStruct := rediscomponent.Settings{} - metadataInfo := map[string]string{} daprmetadata.GetMetadataInfoFromStructType(reflect.TypeOf(settingsStruct), &metadataInfo, daprmetadata.StateStoreType) - - return metadataInfo + return } diff --git a/state/redis/redis_test.go b/state/redis/redis_test.go index fe2fed70e9..599de3ae41 100644 --- a/state/redis/redis_test.go +++ b/state/redis/redis_test.go @@ -507,8 +507,6 @@ func TestGetMetadata(t *testing.T) { metadataInfo := ss.GetComponentMetadata() assert.Contains(t, metadataInfo, "redisHost") assert.Contains(t, metadataInfo, "idleCheckFrequency") - assert.Equal(t, metadataInfo["redisHost"], "string") - assert.Equal(t, metadataInfo["idleCheckFrequency"], "redis.Duration") } func setupMiniredis() (*miniredis.Miniredis, rediscomponent.RedisClient) { diff --git a/state/rethinkdb/rethinkdb.go b/state/rethinkdb/rethinkdb.go index f506920a5d..b725ea17bc 100644 --- a/state/rethinkdb/rethinkdb.go +++ b/state/rethinkdb/rethinkdb.go @@ -306,9 +306,8 @@ func metadataToConfig(cfg map[string]string, logger logger.Logger) (*stateConfig return &c, nil } -func (s *RethinkDB) GetComponentMetadata() map[string]string { +func (s *RethinkDB) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := stateConfig{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/state/sqlite/sqlite.go b/state/sqlite/sqlite.go index fcb5f28635..218c16508f 100644 --- a/state/sqlite/sqlite.go +++ b/state/sqlite/sqlite.go @@ -58,11 +58,10 @@ func (s *SQLiteStore) Init(ctx context.Context, metadata state.Metadata) error { return s.dbaccess.Init(ctx, metadata) } -func (s SQLiteStore) GetComponentMetadata() map[string]string { +func (s SQLiteStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := sqliteMetadataStruct{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } // Features returns the features available in this state store. diff --git a/state/sqlserver/sqlserver.go b/state/sqlserver/sqlserver.go index 89806f3ee9..c87cafa491 100644 --- a/state/sqlserver/sqlserver.go +++ b/state/sqlserver/sqlserver.go @@ -20,9 +20,11 @@ import ( "encoding/json" "errors" "fmt" + "reflect" "time" internalsql "github.com/dapr/components-contrib/internal/component/sql" + "github.com/dapr/components-contrib/metadata" "github.com/dapr/components-contrib/state" "github.com/dapr/components-contrib/state/utils" "github.com/dapr/kit/logger" @@ -347,8 +349,10 @@ func (s *SQLServer) executeSet(ctx context.Context, db dbExecutor, req *state.Se return nil } -func (s *SQLServer) GetComponentMetadata() map[string]string { - return map[string]string{} +func (s *SQLServer) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { + settingsStruct := sqlServerMetadata{} + metadata.GetMetadataInfoFromStructType(reflect.TypeOf(settingsStruct), &metadataInfo, metadata.StateStoreType) + return } // Close implements io.Closer. diff --git a/state/store.go b/state/store.go index 9d23b50750..fa86851bd7 100644 --- a/state/store.go +++ b/state/store.go @@ -18,10 +18,13 @@ import ( "errors" "github.com/dapr/components-contrib/health" + "github.com/dapr/components-contrib/metadata" ) // Store is an interface to perform operations on store. type Store interface { + metadata.ComponentWithMetadata + BaseStore BulkStore } @@ -33,7 +36,6 @@ type BaseStore interface { Delete(ctx context.Context, req *DeleteRequest) error Get(ctx context.Context, req *GetRequest) (*GetResponse, error) Set(ctx context.Context, req *SetRequest) error - GetComponentMetadata() map[string]string } // TransactionalStore is an interface for initialization and support multiple transactional requests. diff --git a/state/zookeeper/zk.go b/state/zookeeper/zk.go index b4c92e2871..fe1985b941 100644 --- a/state/zookeeper/zk.go +++ b/state/zookeeper/zk.go @@ -303,9 +303,8 @@ func (s *StateStore) marshalData(v interface{}) ([]byte, error) { return jsoniter.ConfigFastest.Marshal(v) } -func (s *StateStore) GetComponentMetadata() map[string]string { +func (s *StateStore) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := properties{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.StateStoreType) - return metadataInfo + return } diff --git a/workflows/temporal/temporal.go b/workflows/temporal/temporal.go index 0b528c04c0..9b28bd555c 100644 --- a/workflows/temporal/temporal.go +++ b/workflows/temporal/temporal.go @@ -172,11 +172,10 @@ func (c *TemporalWF) parseMetadata(meta workflows.Metadata) (*temporalMetadata, return &m, err } -func (c *TemporalWF) GetComponentMetadata() map[string]string { +func (c *TemporalWF) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { metadataStruct := temporalMetadata{} - metadataInfo := map[string]string{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.WorkflowType) - return metadataInfo + return } func lookupStatus(status enums.WorkflowExecutionStatus) string { diff --git a/workflows/workflow.go b/workflows/workflow.go index 1dee2ba398..93a4591d79 100644 --- a/workflows/workflow.go +++ b/workflows/workflow.go @@ -30,5 +30,4 @@ type Workflow interface { Purge(ctx context.Context, req *PurgeRequest) error Pause(ctx context.Context, req *PauseRequest) error Resume(ctx context.Context, req *ResumeRequest) error - GetComponentMetadata() map[string]string }