Skip to content

Commit

Permalink
feat: add a bunch more bindings
Browse files Browse the repository at this point in the history
Signed-off-by: Samantha Coyle <[email protected]>
  • Loading branch information
sicoyle committed Dec 19, 2024
1 parent 8579012 commit 5d88b79
Show file tree
Hide file tree
Showing 24 changed files with 197 additions and 186 deletions.
10 changes: 0 additions & 10 deletions bindings/azure/cosmosdb/authentication-profiles.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions bindings/azure/cosmosdb/cosmosdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/azure/cosmosdb/cosmosdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
40 changes: 0 additions & 40 deletions bindings/azure/cosmosdb/cosmosdbgremlinapi/metadata.go

This file was deleted.

2 changes: 1 addition & 1 deletion bindings/azure/cosmosdb/gremlinapi/cosmosdbgremlinapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions bindings/azure/cosmosdb/gremlinapi/cosmosdbgremlinapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
37 changes: 30 additions & 7 deletions bindings/azure/cosmosdb/gremlinapi/metadata.go
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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/<database_name>/colls/<graph_name>",
URL: "wss://******.gremlin.cosmos.azure.com:443/",
MasterKey: "my-secret-key",
Username: "/dbs/<database_name>/colls/<graph_name>",
}
}

func (g *gremlinapiMetadata) Binding() metadataschema.Binding {
return metadataschema.Binding{
Input: false,
Output: true,
Operations: []metadataschema.BindingOperation{
{
Name: "query",
Description: "Perform a query",
},
},
}
}
31 changes: 27 additions & 4 deletions bindings/azure/cosmosdb/metadata.go
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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).
Expand All @@ -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",
},
},
}
}
27 changes: 25 additions & 2 deletions bindings/azure/eventgrid/metadata.go
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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:"-"`
Expand Down Expand Up @@ -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]/<path>",
HandshakePort: "9000",
Expand All @@ -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",
},
},
}
}
2 changes: 2 additions & 0 deletions bindings/azure/eventhubs/eventhubs.go
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
36 changes: 34 additions & 2 deletions bindings/azure/openai/metadata.go
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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"`
Expand All @@ -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",
},
},
}
}
2 changes: 2 additions & 0 deletions bindings/azure/servicebusqueues/servicebusqueues.go
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
13 changes: 2 additions & 11 deletions bindings/azure/signalr/signalr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 5d88b79

Please sign in to comment.