Skip to content

Commit

Permalink
Merge branch 'master' into sqlite-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
berndverst authored Sep 20, 2023
2 parents 63634f7 + e9911a1 commit 77cf89c
Show file tree
Hide file tree
Showing 31 changed files with 1,481 additions and 1,437 deletions.
6 changes: 6 additions & 0 deletions .github/holopin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
organization: dapr
defaultSticker: clmjkxscc122740fl0mkmb7egi
stickers:
-
id: clmjkxscc122740fl0mkmb7egi
alias: ghc2023
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ Before this module can be used on a project, you must ensure that the following
$ terraform init

$ terraform refresh -var="gh_repo=dapr/components-contrib" \
-var="project_id=dapr-tests" -var="service_account=comp-contrib-wif" \
-var="wif_pool_name=contrib-cert-tests"
-var="project_id=dapr-tests" -var="service_account=dapr-contrib-wif-sa" \
-var="wif_pool_name=dapr-contrib-cert-tests"

$ terraform plan -var="gh_repo=dapr/components-contrib" \
-var="project_id=dapr-tests" -var="service_account=comp-contrib-wif" \
-var="wif_pool_name=contrib-cert-tests"
-var="project_id=dapr-tests" -var="service_account=dapr-contrib-wif-sa" \
-var="wif_pool_name=dapr-contrib-cert-tests"

$ terraform apply --auto-approve -var="gh_repo=dapr/components-contrib" \
-var="project_id=dapr-tests" -var="service_account=comp-contrib-wif" \
-var="wif_pool_name=contrib-cert-tests"
-var="project_id=dapr-tests" -var="service_account=dapr-contrib-wif-sa" \
-var="wif_pool_name=dapr-contrib-cert-tests"
```
Expand All @@ -72,7 +72,7 @@ $ terraform apply --auto-approve -var="gh_repo=dapr/components-contrib" \
```
$ terraform output

pool_name = "projects/***/locations/global/workloadIdentityPools/contrib-cert-tests-gh-pool"
provider_name = "projects/***/locations/global/workloadIdentityPools/contrib-cert-tests-gh-pool/providers/contrib-cert-tests-gh-provider"
pool_name = "projects/***/locations/global/workloadIdentityPools/dapr-contrib-cert-tests-pool"
provider_name = "projects/***/locations/global/workloadIdentityPools/dapr-contrib-cert-tests-pool/providers/dapr-contrib-cert-tests-provider"
sa_email = "***"
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module "oidc" {
source = "terraform-google-modules/github-actions-runners/google//modules/gh-oidc"
version = "~> 3.1.1"
project_id = var.project_id
pool_id = "${var.wif_pool_name}-gh-pool"
provider_id = "${var.wif_pool_name}-gh-provider"
pool_id = "${var.wif_pool_name}-pool"
provider_id = "${var.wif_pool_name}-provider"
sa_mapping = {
(google_service_account.sa.account_id) = {
sa_name = google_service_account.sa.name
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (out *outputBinding) Init(ctx context.Context, metadata bindings.Metadata)
_ = out.runtime.Close(context.Background())
return fmt.Errorf("can not instantiate wasi-http with strict sandbox")
}
err = wasi_http.Instantiate(ctx, out.runtime)
err = wasi_http.MakeWasiHTTP().Instantiate(ctx, out.runtime)
}
if err != nil {
_ = out.runtime.Close(context.Background())
Expand Down
40 changes: 40 additions & 0 deletions bindings/wasm/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import (
"bytes"
"context"
_ "embed"
"fmt"
"io"
"net/http"
"net/http/httptest"
"sync"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -268,3 +270,41 @@ func Test_InvokeHttp(t *testing.T) {
})
}
}

func TestEnsureConcurrency(t *testing.T) {
l := logger.NewLogger(t.Name())
var buf bytes.Buffer
l.SetOutput(&buf)

s := httptest.NewServer(&handler{})
defer s.Close()

meta := metadata.Base{Properties: map[string]string{"url": urlHTTPFile}}

output := NewWasmOutput(l)
defer output.(io.Closer).Close()

ctx := context.Background()

err := output.Init(ctx, bindings.Metadata{Base: meta})
require.NoError(t, err)

// Wasm is running in goroutine, use wait group to ensure all goroutines are finished
wg := sync.WaitGroup{}
// 100 is enough to trigger concurrency, and wasm should be executed run fast enough to not consuming too much time
for i := 0; i < 100; i++ {
wg.Add(1)
go func(i int) {
request := &bindings.InvokeRequest{
Metadata: map[string]string{"args": fmt.Sprintf("%s/%d", s.URL, i)},
Operation: ExecuteOperation,
}
expectedResp := fmt.Sprintf("Status: 200\nBody: \n/%d\n", i)
resp, err := output.Invoke(ctx, request)
require.NoError(t, err)
require.Equal(t, expectedResp, string(resp.Data))
wg.Done()
}(i)
}
wg.Wait()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ require (
github.com/sendgrid/sendgrid-go v3.13.0+incompatible
github.com/sijms/go-ora/v2 v2.7.17
github.com/spf13/cast v1.5.1
github.com/stealthrocket/wasi-go v0.7.6-0.20230718231108-c3d30af59057
github.com/stealthrocket/wasi-go v0.8.1-0.20230912180546-8efbab50fb58
github.com/stretchr/testify v1.8.4
github.com/supplyon/gremcos v0.1.40
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.732
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1852,8 +1852,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/spf13/viper v1.15.0 h1:js3yy885G8xwJa6iOISGFwd+qlUo5AvyXb7CiihdtiU=
github.com/stealthrocket/wasi-go v0.7.6-0.20230718231108-c3d30af59057 h1:BaBBX206PM1+qF5WQx7Ug7mbKqzizBONDMv4ST5EVNg=
github.com/stealthrocket/wasi-go v0.7.6-0.20230718231108-c3d30af59057/go.mod h1:PJ5oVs2E1ciOJnsTnav4nvTtEcJ4D1jUZAewS9pzuZg=
github.com/stealthrocket/wasi-go v0.8.1-0.20230912180546-8efbab50fb58 h1:mTC4gyv3lcJ1XpzZMAckqkvWUqeT5Bva4RAT1IoHAAA=
github.com/stealthrocket/wasi-go v0.8.1-0.20230912180546-8efbab50fb58/go.mod h1:ZAYCOqLJkc9P6fcq14TV4cf+gJ2fHthp9kCGxBViagE=
github.com/stealthrocket/wazergo v0.19.1 h1:BPrITETPgSFwiytwmToO0MbUC/+RGC39JScz1JmmG6c=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,30 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package postgresql
package pginterfaces

import (
"context"

"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"

"github.com/dapr/components-contrib/state"
)

// dbAccess is a private interface which enables unit testing of PostgreSQL.
type dbAccess interface {
Init(ctx context.Context, metadata state.Metadata) error
Set(ctx context.Context, req *state.SetRequest) error
Get(ctx context.Context, req *state.GetRequest) (*state.GetResponse, error)
BulkGet(ctx context.Context, req []state.GetRequest) ([]state.BulkGetResponse, error)
Delete(ctx context.Context, req *state.DeleteRequest) error
ExecuteMulti(ctx context.Context, req *state.TransactionalStateRequest) error
Query(ctx context.Context, req *state.QueryRequest) (*state.QueryResponse, error)
Close() error // io.Closer
}

// Interface that contains methods for querying.
// Applies to *pgx.Conn, *pgxpool.Pool, and pgx.Tx
type dbquerier interface {
type DBQuerier interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}

// Interface that applies to *pgxpool.Pool.
// We need this to be able to mock the connection in tests.
type PGXPoolConn interface {
DBQuerier

Begin(context.Context) (pgx.Tx, error)
BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
Ping(context.Context) error
Close()
}
4 changes: 2 additions & 2 deletions internal/component/postgresql/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
defaultTimeout = 20 // Default timeout for network requests, in seconds
)

type postgresMetadataStruct struct {
type pgMetadata struct {
pgauth.PostgresAuthMetadata `mapstructure:",squash"`

TableName string `mapstructure:"tableName"` // Could be in the format "schema.table" or just "table"
Expand All @@ -42,7 +42,7 @@ type postgresMetadataStruct struct {
CleanupInterval *time.Duration `mapstructure:"cleanupIntervalInSeconds"`
}

func (m *postgresMetadataStruct) InitWithMetadata(meta state.Metadata, azureADEnabled bool) error {
func (m *pgMetadata) InitWithMetadata(meta state.Metadata, azureADEnabled bool) error {
// Reset the object
m.PostgresAuthMetadata.Reset()
m.TableName = defaultTableName
Expand Down
24 changes: 12 additions & 12 deletions internal/component/postgresql/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func TestMetadata(t *testing.T) {
t.Run("missing connection string", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{}

err := m.InitWithMetadata(state.Metadata{Base: metadata.Base{Properties: props}}, false)
Expand All @@ -34,7 +34,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("has connection string", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
}
Expand All @@ -44,7 +44,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("default table name", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
}
Expand All @@ -55,7 +55,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("custom table name", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
"tableName": "mytable",
Expand All @@ -67,7 +67,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("default timeout", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
}
Expand All @@ -78,7 +78,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("invalid timeout", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
"timeoutInSeconds": "NaN",
Expand All @@ -89,7 +89,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("positive timeout", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
"timeoutInSeconds": "42",
Expand All @@ -101,7 +101,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("zero timeout", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
"timeoutInSeconds": "0",
Expand All @@ -112,7 +112,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("default cleanupIntervalInSeconds", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
}
Expand All @@ -124,7 +124,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("invalid cleanupIntervalInSeconds", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
"cleanupIntervalInSeconds": "NaN",
Expand All @@ -135,7 +135,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("positive cleanupIntervalInSeconds", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
"cleanupIntervalInSeconds": "42",
Expand All @@ -148,7 +148,7 @@ func TestMetadata(t *testing.T) {
})

t.Run("zero cleanupIntervalInSeconds", func(t *testing.T) {
m := postgresMetadataStruct{}
m := pgMetadata{}
props := map[string]string{
"connectionString": "foo",
"cleanupIntervalInSeconds": "0",
Expand Down
Loading

0 comments on commit 77cf89c

Please sign in to comment.