diff --git a/bindings/azure/cosmosdb/authentication-profiles.yaml b/bindings/azure/cosmosdb/authentication-profiles.yaml deleted file mode 100644 index ebcf64ebe8..0000000000 --- a/bindings/azure/cosmosdb/authentication-profiles.yaml +++ /dev/null @@ -1,10 +0,0 @@ -- title: "Master key" - description: | - Authenticate using a pre-shared "master key". - metadata: - - name: masterKey - required: true - sensitive: true - description: | - The key to authenticate to the Cosmos DB account. - example: '"my-secret-key"' \ No newline at end of file diff --git a/bindings/azure/cosmosdb/cosmosdb.go b/bindings/azure/cosmosdb/cosmosdb.go index 54342a6c2b..b67e396bf8 100644 --- a/bindings/azure/cosmosdb/cosmosdb.go +++ b/bindings/azure/cosmosdb/cosmosdb.go @@ -67,8 +67,8 @@ func (c *CosmosDB) Init(ctx context.Context, metadata bindings.Metadata) error { // Create the client; first, try authenticating with a master key, if present var client *azcosmos.Client - if m.APMasterKey != "" { - cred, keyErr := azcosmos.NewKeyCredential(m.APMasterKey) + if m.MasterKey != "" { + cred, keyErr := azcosmos.NewKeyCredential(m.MasterKey) if keyErr != nil { return keyErr } diff --git a/bindings/azure/cosmosdb/cosmosdb_test.go b/bindings/azure/cosmosdb/cosmosdb_test.go index e23844554f..b4fe5bde58 100644 --- a/bindings/azure/cosmosdb/cosmosdb_test.go +++ b/bindings/azure/cosmosdb/cosmosdb_test.go @@ -32,7 +32,7 @@ func TestParseMetadata(t *testing.T) { require.NoError(t, err) assert.Equal(t, "a", meta.Collection) assert.Equal(t, "a", meta.Database) - assert.Equal(t, "a", meta.APMasterKey) + assert.Equal(t, "a", meta.MasterKey) assert.Equal(t, "a", meta.PartitionKey) assert.Equal(t, "a", meta.URL) } diff --git a/bindings/azure/cosmosdb/cosmosdbgremlinapi/metadata.go b/bindings/azure/cosmosdb/cosmosdbgremlinapi/metadata.go deleted file mode 100644 index 1a6a3946f1..0000000000 --- a/bindings/azure/cosmosdb/cosmosdbgremlinapi/metadata.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2024 The Dapr Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package cosmosdbgremlinapi - -type cosmosdbMetadata struct { - // The Cosmos DB url. - URL string `json:"url"` - // The key to authenticate to the Cosmos DB account. - APMasterKey string `json:"masterKey"` // AP prefix indicates auth profile metadata specifically - // The username of the Cosmos DB database. - APUsername string `json:"username"` // AP prefix indicates auth profile metadata specifically -} - -// Set the default values here. -// This unifies the setup across all componets, -// and makes it easy for us to auto-generate the component metadata default values, -// while also leveraging the default values for types thanks to Go. -func Defaults() cosmosdbMetadata { - return cosmosdbMetadata{} -} - -// Note: we do not include any mdignored field. -func Examples() cosmosdbMetadata { - return cosmosdbMetadata{ - URL: "https://******.documents.azure.com:443/", - APMasterKey: "my-secret-key", - APUsername: "/dbs//colls/", - } -} diff --git a/bindings/azure/cosmosdb/gremlinapi/cosmosdbgremlinapi.go b/bindings/azure/cosmosdb/gremlinapi/cosmosdbgremlinapi.go index ec05110ea0..5d1d835cdf 100644 --- a/bindings/azure/cosmosdb/gremlinapi/cosmosdbgremlinapi.go +++ b/bindings/azure/cosmosdb/gremlinapi/cosmosdbgremlinapi.go @@ -65,7 +65,7 @@ func (c *CosmosDBGremlinAPI) Init(_ context.Context, metadata bindings.Metadata) } c.metadata = m client, err := gremcos.New(c.metadata.URL, - gremcos.WithAuth(c.metadata.APUsername, c.metadata.APMasterKey), + gremcos.WithAuth(c.metadata.Username, c.metadata.MasterKey), ) if err != nil { return errors.New("CosmosDBGremlinAPI Error: failed to create the Cosmos Graph DB connector") diff --git a/bindings/azure/cosmosdb/gremlinapi/cosmosdbgremlinapi_test.go b/bindings/azure/cosmosdb/gremlinapi/cosmosdbgremlinapi_test.go index d15731b5d5..0ff0bfebab 100644 --- a/bindings/azure/cosmosdb/gremlinapi/cosmosdbgremlinapi_test.go +++ b/bindings/azure/cosmosdb/gremlinapi/cosmosdbgremlinapi_test.go @@ -30,6 +30,6 @@ func TestParseMetadata(t *testing.T) { im, err := cosmosdbgremlinapi.parseMetadata(m) require.NoError(t, err) assert.Equal(t, "a", im.URL) - assert.Equal(t, "a", im.APMasterKey) - assert.Equal(t, "a", im.APUsername) + assert.Equal(t, "a", im.MasterKey) + assert.Equal(t, "a", im.Username) } diff --git a/bindings/azure/cosmosdb/gremlinapi/metadata.go b/bindings/azure/cosmosdb/gremlinapi/metadata.go index 8f4ffa8543..846034e7c4 100644 --- a/bindings/azure/cosmosdb/gremlinapi/metadata.go +++ b/bindings/azure/cosmosdb/gremlinapi/metadata.go @@ -1,3 +1,5 @@ +//go:generate make -f ../../../../Makefile component-metadata-manifest type=bindings builtinAuth="azuread" status=alpha version=v1 direction=output origin=$PWD "title=Azure Cosmos DB (Gremlin API)" + /* Copyright 2024 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,28 +15,49 @@ limitations under the License. package gremlinapi +import ( + "github.com/dapr/components-contrib/build-tools/pkg/metadataschema" + "github.com/dapr/components-contrib/common/component" +) + +// implement MetadataBuilder so each component will be properly parsed for the ast to auto-generate metadata manifest. +var _ component.MetadataBuilder = &gremlinapiMetadata{} + type gremlinapiMetadata struct { // The Cosmos DB URL for Gremlin APIs. URL string `json:"url"` // The key to authenticate to the Cosmos DB account. - APMasterKey string `json:"masterKey"` // AP prefix indicates auth profile metadata specifically + MasterKey string `json:"masterKey" authenticationProfile:"masterKey"` // The username of the Cosmos DB database. - APUsername string `json:"username"` // AP prefix indicates auth profile metadata specifically + Username string `json:"username" authenticationProfile:"masterKey"` } // Set the default values here. // This unifies the setup across all components, // and makes it easy for us to auto-generate the component metadata default values, // while also leveraging the default values for types thanks to Go. -func Defaults() gremlinapiMetadata { +func (g *gremlinapiMetadata) Defaults() any { return gremlinapiMetadata{} } // Note: we do not include any mdignored field. -func Examples() gremlinapiMetadata { +func (g *gremlinapiMetadata) Examples() any { return gremlinapiMetadata{ - URL: "wss://******.gremlin.cosmos.azure.com:443/", - APMasterKey: "my-secret-key", - APUsername: "/dbs//colls/", + URL: "wss://******.gremlin.cosmos.azure.com:443/", + MasterKey: "my-secret-key", + Username: "/dbs//colls/", + } +} + +func (g *gremlinapiMetadata) Binding() metadataschema.Binding { + return metadataschema.Binding{ + Input: false, + Output: true, + Operations: []metadataschema.BindingOperation{ + { + Name: "query", + Description: "Perform a query", + }, + }, } } diff --git a/bindings/azure/cosmosdb/metadata.go b/bindings/azure/cosmosdb/metadata.go index ffac47bc77..148f97d18b 100644 --- a/bindings/azure/cosmosdb/metadata.go +++ b/bindings/azure/cosmosdb/metadata.go @@ -1,3 +1,5 @@ +//go:generate make -f ../../../Makefile component-metadata-manifest type=bindings builtinAuth="azuread" status=stable version=v1 direction=output origin=$PWD "title=Azure Cosmos DB (SQL API)" + /* Copyright 2024 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,11 +15,19 @@ limitations under the License. package cosmosdb +import ( + "github.com/dapr/components-contrib/build-tools/pkg/metadataschema" + "github.com/dapr/components-contrib/common/component" +) + +// implement MetadataBuilder so each component will be properly parsed for the ast to auto-generate metadata manifest. +var _ component.MetadataBuilder = &cosmosdbMetadata{} + type cosmosdbMetadata struct { // The Cosmos DB url. URL string `json:"url"` // The key to authenticate to the Cosmos DB account. - APMasterKey string `json:"masterKey"` // AP prefix indicates auth profile metadata specifically + MasterKey string `json:"masterKey" authenticationProfile:"masterKey"` // The name of the database. Database string `json:"database"` // The name of the collection (container). @@ -30,17 +40,30 @@ type cosmosdbMetadata struct { // This unifies the setup across all components, // and makes it easy for us to auto-generate the component metadata default values, // while also leveraging the default values for types thanks to Go. -func Defaults() cosmosdbMetadata { +func (c *cosmosdbMetadata) Defaults() any { return cosmosdbMetadata{} } // Note: we do not include any mdignored field. -func Examples() cosmosdbMetadata { +func (c *cosmosdbMetadata) Examples() any { return cosmosdbMetadata{ URL: "https://******.documents.azure.com:443/", - APMasterKey: "my-secret-key", + MasterKey: "my-secret-key", Database: "OrdersDB", Collection: "Orders", PartitionKey: "OrderId", } } + +func (c *cosmosdbMetadata) Binding() metadataschema.Binding { + return metadataschema.Binding{ + Input: true, + Output: true, + Operations: []metadataschema.BindingOperation{ + { + Name: "create", + Description: "Create an item", + }, + }, + } +} diff --git a/bindings/azure/eventgrid/metadata.go b/bindings/azure/eventgrid/metadata.go index 1a149a1f25..c9bda961f5 100644 --- a/bindings/azure/eventgrid/metadata.go +++ b/bindings/azure/eventgrid/metadata.go @@ -1,3 +1,5 @@ +//go:generate make -f ../../../Makefile component-metadata-manifest type=bindings builtinAuth="azure" status=beta version=v1 "direction=input,output" origin=$PWD "title=Azure Event Grid" + /* Copyright 2021 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +15,14 @@ limitations under the License. package eventgrid +import ( + "github.com/dapr/components-contrib/build-tools/pkg/metadataschema" + "github.com/dapr/components-contrib/common/component" +) + +// implement MetadataBuilder so each component will be properly parsed for the ast to auto-generate metadata manifest. +var _ component.MetadataBuilder = &eventgridMetadata{} + type eventgridMetadata struct { // Component Name Name string `json:"-" mapstructure:"-"` @@ -44,14 +54,14 @@ type eventgridMetadata struct { // This unifies the setup across all components, // and makes it easy for us to auto-generate the component metadata default values, // while also leveraging the default values for types thanks to Go. -func Defaults() eventgridMetadata { +func (e *eventgridMetadata) Defaults() any { return eventgridMetadata{ HandshakePort: "8080", } } // Note: we do not include any mdignored field. -func Examples() eventgridMetadata { +func (e *eventgridMetadata) Examples() any { return eventgridMetadata{ SubscriberEndpoint: "https://[YOUR HOSTNAME]/", HandshakePort: "9000", @@ -61,3 +71,16 @@ func Examples() eventgridMetadata { Scope: "/subscriptions/{subscriptionId}/", } } + +func (e *eventgridMetadata) Binding() metadataschema.Binding { + return metadataschema.Binding{ + Input: true, + Output: true, + Operations: []metadataschema.BindingOperation{ + { + Name: "create", + Description: "Create an event subscription", + }, + }, + } +} diff --git a/bindings/azure/eventhubs/eventhubs.go b/bindings/azure/eventhubs/eventhubs.go index 8cc19d8265..4c3e97a76b 100644 --- a/bindings/azure/eventhubs/eventhubs.go +++ b/bindings/azure/eventhubs/eventhubs.go @@ -1,3 +1,5 @@ +//go:generate echo TODO bindings/azure/eventhubs + /* Copyright 2021 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/bindings/azure/openai/metadata.go b/bindings/azure/openai/metadata.go index 096506f182..7aaaff6cd4 100644 --- a/bindings/azure/openai/metadata.go +++ b/bindings/azure/openai/metadata.go @@ -1,3 +1,5 @@ +//go:generate make -f ../../../Makefile component-metadata-manifest type=bindings builtinAuth="azuread" status=alpha version=v1 "direction=input,output" origin=$PWD "title=Azure OpenAI" + /* Copyright 2024 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +15,14 @@ limitations under the License. package openai +import ( + "github.com/dapr/components-contrib/build-tools/pkg/metadataschema" + "github.com/dapr/components-contrib/common/component" +) + +// implement MetadataBuilder so each component will be properly parsed for the ast to auto-generate metadata manifest. +var _ component.MetadataBuilder = &openaiMetadata{} + type openaiMetadata struct { // APIKey is the API key for the Azure OpenAI API. APIKey string `json:"apiKey" mapstructure:"apiKey" authenticationProfile:"APIKey" binding:"output"` @@ -24,14 +34,36 @@ type openaiMetadata struct { // This unifies the setup across all components, // and makes it easy for us to auto-generate the component metadata default values, // while also leveraging the default values for types thanks to Go. -func Defaults() openaiMetadata { +func (o *openaiMetadata) Defaults() any { return openaiMetadata{} } // Note: we do not include any mdignored field. -func Examples() openaiMetadata { +func (o *openaiMetadata) Examples() any { return openaiMetadata{ APIKey: "1234567890abcdef", Endpoint: "https://myopenai.openai.azure.com", } } + +func (o *openaiMetadata) Binding() metadataschema.Binding { + return metadataschema.Binding{ + Input: false, + Output: true, + Operations: []metadataschema.BindingOperation{ + { + Name: "completion", + Description: "Text completion", + }, + { + Name: "chat-completion", + Description: "Chat completion", + }, + // TODO: below pls confirm this is correct bc docs showed it but original yaml manifest did not + { + Name: "get-embedding", + Description: "Get embedding", + }, + }, + } +} diff --git a/bindings/azure/servicebusqueues/servicebusqueues.go b/bindings/azure/servicebusqueues/servicebusqueues.go index af2bc3b534..6e82226343 100644 --- a/bindings/azure/servicebusqueues/servicebusqueues.go +++ b/bindings/azure/servicebusqueues/servicebusqueues.go @@ -1,3 +1,5 @@ +//go:generate echo TODO bindings/azure/servicebusqueues + /* Copyright 2021 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/bindings/azure/signalr/signalr.go b/bindings/azure/signalr/signalr.go index c0de8dd358..6a726b861e 100644 --- a/bindings/azure/signalr/signalr.go +++ b/bindings/azure/signalr/signalr.go @@ -61,15 +61,6 @@ const ( ClientNegotiateOperation bindings.OperationKind = "clientNegotiate" ) -// Metadata keys. -// Azure AD credentials are parsed separately and not listed here. -type SignalRMetadata struct { - Endpoint string `mapstructure:"endpoint"` - AccessKey string `mapstructure:"accessKey"` - Hub string `mapstructure:"hub"` - ConnectionString string `mapstructure:"connectionString"` -} - // Global HTTP client var httpClient *http.Client @@ -130,7 +121,7 @@ func (s *SignalR) Init(_ context.Context, metadata bindings.Metadata) (err error } func (s *SignalR) parseMetadata(md map[string]string) (err error) { - m := SignalRMetadata{} + m := signalrMetadata{} err = kitmd.DecodeMetadata(md, &m) if err != nil { return err @@ -415,7 +406,7 @@ func (s *SignalR) getToken(ctx context.Context, url string, user string, expireM // GetComponentMetadata returns the metadata of the component. func (s *SignalR) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { - metadataStruct := SignalRMetadata{} + metadataStruct := signalrMetadata{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) return } diff --git a/bindings/azure/storagequeues/metadata.go b/bindings/azure/storagequeues/metadata.go index 9fc89def36..fb49c7f924 100644 --- a/bindings/azure/storagequeues/metadata.go +++ b/bindings/azure/storagequeues/metadata.go @@ -1,3 +1,5 @@ +//go:generate make -f ../../../Makefile component-metadata-manifest type=bindings builtinAuth="azuread" status=stable version=v1 direction=output origin=$PWD "title=Azure Storage Queues" + /* Copyright 2024 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +15,15 @@ limitations under the License. package storagequeues -import "time" +import ( + "time" + + "github.com/dapr/components-contrib/build-tools/pkg/metadataschema" + "github.com/dapr/components-contrib/common/component" +) + +// implement MetadataBuilder so each component will be properly parsed for the ast to auto-generate metadata manifest. +var _ component.MetadataBuilder = &storagequeuesMetadata{} type storagequeuesMetadata struct { // The storage account name. @@ -43,7 +53,7 @@ type storagequeuesMetadata struct { // This unifies the setup across all components, // and makes it easy for us to auto-generate the component metadata default values, // while also leveraging the default values for types thanks to Go. -func Defaults() storagequeuesMetadata { +func (s *storagequeuesMetadata) Defaults() any { ttl := 10 * time.Minute vis := 30 * time.Second return storagequeuesMetadata{ @@ -56,7 +66,7 @@ func Defaults() storagequeuesMetadata { } // Note: we do not include any mdignored field. -func Examples() storagequeuesMetadata { +func (s *storagequeuesMetadata) Examples() any { exampleDuration := 30 * time.Second return storagequeuesMetadata{ AccountName: "mystorageaccount", @@ -71,3 +81,16 @@ func Examples() storagequeuesMetadata { VisibilityTimeout: &exampleDuration, } } + +func (s *storagequeuesMetadata) Binding() metadataschema.Binding { + return metadataschema.Binding{ + Input: false, + Output: true, + Operations: []metadataschema.BindingOperation{ + { + Name: "create", + Description: "Publish a new message in the queue.", + }, + }, + } +} diff --git a/bindings/cloudflare/queues/cfqueues.go b/bindings/cloudflare/queues/cfqueues.go index bf539e86f3..0d767784fa 100644 --- a/bindings/cloudflare/queues/cfqueues.go +++ b/bindings/cloudflare/queues/cfqueues.go @@ -36,7 +36,7 @@ const componentDocsURL = "https://docs.dapr.io/reference/components-reference/su // CFQueues is a binding for publishing messages on Cloudflare Queues type CFQueues struct { *workers.Base - metadata componentMetadata + metadata queuesMetadata } // NewCFQueues returns a new CFQueues. @@ -137,7 +137,7 @@ func (q *CFQueues) Close() error { // GetComponentMetadata returns the metadata of the component. func (q *CFQueues) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { - metadataStruct := componentMetadata{} + metadataStruct := queuesMetadata{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) return } diff --git a/bindings/commercetools/commercetools.go b/bindings/commercetools/commercetools.go index 1da4183e63..29dd5dbcfc 100644 --- a/bindings/commercetools/commercetools.go +++ b/bindings/commercetools/commercetools.go @@ -39,15 +39,6 @@ type Data struct { Query string } -type commercetoolsMetadata struct { - Region string - Provider string - ProjectKey string - ClientID string - ClientSecret string - Scopes string -} - func NewCommercetools(logger logger.Logger) bindings.OutputBinding { return &Binding{logger: logger} } diff --git a/bindings/cron/cron.go b/bindings/cron/cron.go index dec1faa2ae..f018b0dd9f 100644 --- a/bindings/cron/cron.go +++ b/bindings/cron/cron.go @@ -43,10 +43,6 @@ type Binding struct { wg sync.WaitGroup } -type metadata struct { - Schedule string -} - // NewCron returns a new Cron event input binding. func NewCron(logger logger.Logger) bindings.InputBinding { return NewCronWithClock(logger, clock.RealClock{}) @@ -70,7 +66,7 @@ func NewCronWithClock(logger logger.Logger, clk clock.Clock) bindings.InputBindi // "0 30 * * * *" - Every 30 min func (b *Binding) Init(ctx context.Context, meta bindings.Metadata) error { b.name = meta.Name - m := metadata{} + m := cronMetadata{} err := kitmd.DecodeMetadata(meta.Properties, &m) if err != nil { return err @@ -134,7 +130,7 @@ func (b *Binding) Close() error { // GetComponentMetadata returns the metadata of the component. func (b *Binding) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { - metadataStruct := metadata{} + metadataStruct := cronMetadata{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) return } diff --git a/bindings/dubbo/context.go b/bindings/dubbo/context.go index d0d4d8506f..eda894d77b 100644 --- a/bindings/dubbo/context.go +++ b/bindings/dubbo/context.go @@ -24,6 +24,8 @@ import ( hessian "github.com/apache/dubbo-go-hessian2" ) +// TODO delete this and leverage json tags instead. +// Note: leaving for now since this is already a big PR. const ( metadataRPCGroup = "group" metadataRPCVersion = "version" @@ -33,31 +35,20 @@ const ( metadataRPCProviderPort = "providerPort" ) -type dubboContext struct { - group string - version string - interfaceName string - hostname string - port string - method string - - inited bool - client *generic.GenericService -} - -func newDubboContext(metadata map[string]string) *dubboContext { - dubboMetadata := &dubboContext{} - dubboMetadata.group = metadata[metadataRPCGroup] - dubboMetadata.interfaceName = metadata[metadataRPCInterface] - dubboMetadata.version = metadata[metadataRPCVersion] - dubboMetadata.method = metadata[metadataRPCMethodName] - dubboMetadata.hostname = metadata[metadataRPCProviderHostname] - dubboMetadata.port = metadata[metadataRPCProviderPort] +func newDubboContext(metadata map[string]string) *dubboMetadata { + dubboMetadata := &dubboMetadata{} + dubboMetadata.Group = metadata[metadataRPCGroup] + dubboMetadata.InterfaceName = metadata[metadataRPCInterface] + dubboMetadata.Version = metadata[metadataRPCVersion] + dubboMetadata.MethodName = metadata[metadataRPCMethodName] + dubboMetadata.ProviderHostname = metadata[metadataRPCProviderHostname] + dubboMetadata.ProviderPort = metadata[metadataRPCProviderPort] dubboMetadata.inited = false return dubboMetadata } -func (d *dubboContext) Init() error { +func (d *dubboMetadata) Init() error { + // TODO: eventually remove this inited field if d.inited { return nil } @@ -67,18 +58,18 @@ func (d *dubboContext) Init() error { SetConsumer(consumerConfig). Build() referenceConfig := config.NewReferenceConfigBuilder(). - SetInterface(d.interfaceName). + SetInterface(d.InterfaceName). SetProtocol(constant.Dubbo). Build() - referenceConfig.URL = fmt.Sprintf("%s://%s:%s", constant.Dubbo, d.hostname, d.port) - referenceConfig.Group = d.group - referenceConfig.Version = d.version + referenceConfig.URL = fmt.Sprintf("%s://%s:%s", constant.Dubbo, d.ProviderHostname, d.ProviderPort) + referenceConfig.Group = d.Group + referenceConfig.Version = d.Version if err := referenceConfig.Init(rootConfig); err != nil { return err } rootConfig.Start() - referenceConfig.GenericLoad(d.interfaceName) + referenceConfig.GenericLoad(d.InterfaceName) genericService, ok := referenceConfig.GetRPCService().(*generic.GenericService) if !ok { return errors.New("get gerneric service of dubbo failed") @@ -88,10 +79,10 @@ func (d *dubboContext) Init() error { return nil } -func (d *dubboContext) Invoke(ctx context.Context, body []byte) (interface{}, error) { - return d.client.Invoke(ctx, d.method, []string{}, []hessian.Object{body}) +func (d *dubboMetadata) Invoke(ctx context.Context, body []byte) (interface{}, error) { + return d.client.Invoke(ctx, d.MethodName, []string{}, []hessian.Object{body}) } -func (d *dubboContext) String() string { - return fmt.Sprintf("%s.%s.%s.%s.%s.%s", d.group, d.version, d.interfaceName, d.hostname, d.port, d.method) +func (d *dubboMetadata) String() string { + return fmt.Sprintf("%s.%s.%s.%s.%s.%s", d.Group, d.Version, d.InterfaceName, d.ProviderHostname, d.ProviderPort, d.MethodName) } diff --git a/bindings/dubbo/dubbo_output.go b/bindings/dubbo/dubbo_output.go index 3dde198514..82d7dece3f 100644 --- a/bindings/dubbo/dubbo_output.go +++ b/bindings/dubbo/dubbo_output.go @@ -32,7 +32,7 @@ import ( ) type DubboOutputBinding struct { - ctxCache map[string]*dubboContext + ctxCache map[string]*dubboMetadata cacheLock sync.RWMutex } @@ -41,7 +41,7 @@ var dubboBinding *DubboOutputBinding func NewDubboOutput(logger logger.Logger) bindings.OutputBinding { if dubboBinding == nil { dubboBinding = &DubboOutputBinding{ - ctxCache: make(map[string]*dubboContext), + ctxCache: make(map[string]*dubboMetadata), } } dubboLogger.SetLogger(logger) @@ -55,7 +55,7 @@ func (out *DubboOutputBinding) Init(_ context.Context, _ bindings.Metadata) erro func (out *DubboOutputBinding) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { var ( - cachedDubboCtx *dubboContext + cachedDubboCtx *dubboMetadata ok bool finalResult = &bindings.InvokeResponse{} ) diff --git a/bindings/gcp/bucket/bucket.go b/bindings/gcp/bucket/bucket.go index 2a8b5e1faa..35fd799db4 100644 --- a/bindings/gcp/bucket/bucket.go +++ b/bindings/gcp/bucket/bucket.go @@ -55,30 +55,11 @@ const ( // GCPStorage allows saving data to GCP bucket storage. type GCPStorage struct { - metadata *gcpMetadata + metadata *bucketMetadata client *storage.Client logger logger.Logger } -type gcpMetadata struct { - // Ignored by metadata parser because included in built-in authentication profile - Type string `json:"type" mapstructure:"type" mdignore:"true"` - ProjectID string `json:"project_id" mapstructure:"projectID" mdignore:"true" mapstructurealiases:"project_id"` - PrivateKeyID string `json:"private_key_id" mapstructure:"privateKeyID" mdignore:"true" mapstructurealiases:"private_key_id"` - PrivateKey string `json:"private_key" mapstructure:"privateKey" mdignore:"true" mapstructurealiases:"private_key"` - ClientEmail string `json:"client_email" mapstructure:"clientEmail" mdignore:"true" mapstructurealiases:"client_email"` - ClientID string `json:"client_id" mapstructure:"clientID" mdignore:"true" mapstructurealiases:"client_id"` - AuthURI string `json:"auth_uri" mapstructure:"authURI" mdignore:"true" mapstructurealiases:"auth_uri"` - TokenURI string `json:"token_uri" mapstructure:"tokenURI" mdignore:"true" mapstructurealiases:"token_uri"` - AuthProviderCertURL string `json:"auth_provider_x509_cert_url" mapstructure:"authProviderX509CertURL" mdignore:"true" mapstructurealiases:"auth_provider_x509_cert_url"` - ClientCertURL string `json:"client_x509_cert_url" mapstructure:"clientX509CertURL" mdignore:"true" mapstructurealiases:"client_x509_cert_url"` - - Bucket string `json:"bucket" mapstructure:"bucket"` - DecodeBase64 bool `json:"decodeBase64,string" mapstructure:"decodeBase64"` - EncodeBase64 bool `json:"encodeBase64,string" mapstructure:"encodeBase64"` - SignTTL string `json:"signTTL" mapstructure:"signTTL" mdignore:"true"` -} - type listPayload struct { Prefix string `json:"prefix"` MaxResults int32 `json:"maxResults"` @@ -121,8 +102,8 @@ func (g *GCPStorage) Init(ctx context.Context, metadata bindings.Metadata) error return nil } -func (g *GCPStorage) parseMetadata(meta bindings.Metadata) (*gcpMetadata, error) { - m := gcpMetadata{} +func (g *GCPStorage) parseMetadata(meta bindings.Metadata) (*bucketMetadata, error) { + m := bucketMetadata{} err := kitmd.DecodeMetadata(meta.Properties, &m) if err != nil { return nil, err @@ -312,7 +293,7 @@ func (g *GCPStorage) Close() error { } // Helper to merge config and request metadata. -func (metadata gcpMetadata) mergeWithRequestMetadata(req *bindings.InvokeRequest) (gcpMetadata, error) { +func (metadata bucketMetadata) mergeWithRequestMetadata(req *bindings.InvokeRequest) (bucketMetadata, error) { merged := metadata if val, ok := req.Metadata[metadataDecodeBase64]; ok && val != "" { @@ -340,7 +321,7 @@ func (g *GCPStorage) handleBackwardCompatibilityForMetadata(metadata map[string] // GetComponentMetadata returns the metadata of the component. func (g *GCPStorage) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { - metadataStruct := gcpMetadata{} + metadataStruct := bucketMetadata{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) return } diff --git a/bindings/gcp/bucket/bucket_test.go b/bindings/gcp/bucket/bucket_test.go index 6922050acb..bb46871d85 100644 --- a/bindings/gcp/bucket/bucket_test.go +++ b/bindings/gcp/bucket/bucket_test.go @@ -237,7 +237,7 @@ func TestMergeWithRequestMetadata(t *testing.T) { func TestGetOption(t *testing.T) { gs := GCPStorage{logger: logger.NewLogger("test")} - gs.metadata = &gcpMetadata{} + gs.metadata = &bucketMetadata{} t.Run("return error if key is missing", func(t *testing.T) { r := bindings.InvokeRequest{} _, err := gs.get(context.TODO(), &r) @@ -247,7 +247,7 @@ func TestGetOption(t *testing.T) { func TestDeleteOption(t *testing.T) { gs := GCPStorage{logger: logger.NewLogger("test")} - gs.metadata = &gcpMetadata{} + gs.metadata = &bucketMetadata{} t.Run("return error if key is missing", func(t *testing.T) { r := bindings.InvokeRequest{} diff --git a/bindings/gcp/pubsub/pubsub.go b/bindings/gcp/pubsub/pubsub.go index dfc8a69787..84954cec1a 100644 --- a/bindings/gcp/pubsub/pubsub.go +++ b/bindings/gcp/pubsub/pubsub.go @@ -39,28 +39,13 @@ const ( // GCPPubSub is an input/output binding for GCP Pub Sub. type GCPPubSub struct { client *pubsub.Client - metadata *pubSubMetadata + metadata *pubsubMetadata logger logger.Logger closed atomic.Bool closeCh chan struct{} wg sync.WaitGroup } -type pubSubMetadata struct { - Topic string `json:"topic"` - Subscription string `json:"subscription"` - Type string `json:"type"` - ProjectID string `json:"project_id"` - PrivateKeyID string `json:"private_key_id"` - PrivateKey string `json:"private_key"` - ClientEmail string `json:"client_email"` - ClientID string `json:"client_id"` - AuthURI string `json:"auth_uri"` - TokenURI string `json:"token_uri"` - AuthProviderCertURL string `json:"auth_provider_x509_cert_url"` - ClientCertURL string `json:"client_x509_cert_url"` -} - // NewGCPPubSub returns a new GCPPubSub instance. func NewGCPPubSub(logger logger.Logger) bindings.InputOutputBinding { return &GCPPubSub{ @@ -76,7 +61,7 @@ func (g *GCPPubSub) Init(ctx context.Context, metadata bindings.Metadata) error return err } - var pubsubMeta pubSubMetadata + var pubsubMeta pubsubMetadata err = json.Unmarshal(b, &pubsubMeta) if err != nil { return err @@ -152,7 +137,7 @@ func (g *GCPPubSub) Close() error { // GetComponentMetadata returns the metadata of the component. func (g *GCPPubSub) GetComponentMetadata() (metadataInfo contribMetadata.MetadataMap) { - metadataStruct := pubSubMetadata{} + metadataStruct := pubsubMetadata{} contribMetadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, contribMetadata.BindingType) return } diff --git a/bindings/gcp/pubsub/pubsub_test.go b/bindings/gcp/pubsub/pubsub_test.go index cd4d3f8171..1cd80371ef 100644 --- a/bindings/gcp/pubsub/pubsub_test.go +++ b/bindings/gcp/pubsub/pubsub_test.go @@ -34,7 +34,7 @@ func TestInit(t *testing.T) { b, err := ps.parseMetadata(m) require.NoError(t, err) - var pubsubMeta pubSubMetadata + var pubsubMeta pubsubMetadata err = json.Unmarshal(b, &pubsubMeta) require.NoError(t, err) diff --git a/bindings/graphql/graphql.go b/bindings/graphql/graphql.go index 55cf556e3d..87498ff1f0 100644 --- a/bindings/graphql/graphql.go +++ b/bindings/graphql/graphql.go @@ -47,13 +47,11 @@ const ( MutationOperation bindings.OperationKind = "mutation" ) -type graphQLMetadata struct { - Endpoint string `mapstructure:"endpoint"` -} - // GraphQL represents GraphQL output bindings. type GraphQL struct { client *graphql.Client + // TODO: the headers need to be tweaked on metadata input. + // Autogeneration of component manifest does not add this info for end users... header map[string]string logger logger.Logger } @@ -67,7 +65,7 @@ func NewGraphQL(logger logger.Logger) bindings.OutputBinding { func (gql *GraphQL) Init(_ context.Context, meta bindings.Metadata) error { gql.logger.Debug("GraphQL Error: Initializing GraphQL binding") - m := graphQLMetadata{} + m := graphqlMetadata{} err := kitmd.DecodeMetadata(meta.Properties, &m) if err != nil { return err @@ -189,7 +187,7 @@ func (gql *GraphQL) runRequest(ctx context.Context, requestKey string, req *bind // GetComponentMetadata returns the metadata of the component. func (gql *GraphQL) GetComponentMetadata() (metadataInfo metadata.MetadataMap) { - metadataStruct := graphQLMetadata{} + metadataStruct := graphqlMetadata{} metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.BindingType) return }