Skip to content

Commit 02c3274

Browse files
authored
Merge branch 'master' into master
2 parents 27333d9 + 0777a6a commit 02c3274

File tree

13 files changed

+97
-96
lines changed

13 files changed

+97
-96
lines changed

.github/workflows/conformance.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
- component: bindings.azure.storagequeues
8888
required-secrets: AzureBlobStorageAccessKey,AzureBlobStorageAccount,AzureBlobStorageQueue
8989
- component: secretstores.azure.keyvault
90-
required-secrets: AzureKeyVaultSecretStoreTenantId,AzureKeyVaultSecretStoreClientId
90+
required-secrets: AzureKeyVaultName,AzureKeyVaultSecretStoreTenantId,AzureKeyVaultSecretStoreClientId
9191
required-certs: AzureKeyVaultSecretStoreCert
9292
EOF
9393
)
@@ -104,12 +104,6 @@ jobs:
104104
shell: bash
105105
working-directory: ./src/github.com/dapr/components-contrib
106106
needs: generate-matrix
107-
env:
108-
# Set this to your keyvault.
109-
#
110-
# The KeyVault policy must be granted to your Service Principal using
111-
# az keyvault set-policy -n $AZURE_KEYVAULT --secret-permissions get list --spn $SPN_CLIENT_ID
112-
AZURE_KEYVAULT: dapr-conf-tests
113107

114108
strategy:
115109
fail-fast: false # Keep running even if one component fails
@@ -130,7 +124,9 @@ jobs:
130124
- name: Setup secrets
131125
uses: Azure/get-keyvault-secrets@v1
132126
with:
133-
keyvault: ${{ env.AZURE_KEYVAULT }}
127+
# Set this GitHub secret to your KeyVault, and grant the KeyVault policy to your Service Principal:
128+
# az keyvault set-policy -n $AZURE_KEYVAULT --secret-permissions get list --spn $SPN_CLIENT_ID
129+
keyvault: ${{ secrets.AZURE_KEYVAULT }}
134130
secrets: ${{ matrix.required-secrets }}
135131
id: get-azure-secrets
136132
if: matrix.required-secrets != ''
@@ -158,7 +154,7 @@ jobs:
158154
CERT_FILE=$(mktemp --suffix .pfx)
159155
echo "Downloading cert $CERT_NAME into file $CERT_FILE"
160156
rm $CERT_FILE && \
161-
az keyvault secret download --vault-name $AZURE_KEYVAULT --name $CERT_NAME --encoding base64 --file $CERT_FILE
157+
az keyvault secret download --vault-name ${{ secrets.AZURE_KEYVAULT }} --name $CERT_NAME --encoding base64 --file $CERT_FILE
162158
echo 'Setting $CERT_NAME to' "$CERT_FILE"
163159
echo "$CERT_NAME=$CERT_FILE" >> $GITHUB_ENV
164160
done

bindings/apns/authorization_builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/dapr/kit/logger"
13-
jwt "github.com/dgrijalva/jwt-go/v4"
13+
"github.com/golang-jwt/jwt"
1414
)
1515

1616
// The "issued at" timestamp in the JWT must be within one hour from the
@@ -57,7 +57,7 @@ func (a *authorizationBuilder) generateAuthorizationHeader() (string, error) {
5757

5858
now := time.Now()
5959
claims := jwt.StandardClaims{
60-
IssuedAt: jwt.Now(),
60+
IssuedAt: time.Now().Unix(),
6161
Issuer: a.teamID,
6262
}
6363
token := jwt.NewWithClaims(jwt.SigningMethodES256, claims)

bindings/azure/blobstorage/blobstorage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type blobStorageMetadata struct {
4545
StorageAccessKey string `json:"storageAccessKey"`
4646
Container string `json:"container"`
4747
DecodeBase64 string `json:"decodeBase64"`
48-
GetBlobRetryCount int `json:"getBlobRetryCount"`
48+
GetBlobRetryCount int `json:"getBlobRetryCount,string"`
4949
PublicAccessLevel string `json:"publicAccessLevel"`
5050
}
5151

bindings/azure/signalr/signalr.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
"github.com/dapr/components-contrib/bindings"
1818
"github.com/dapr/kit/logger"
19-
"github.com/dgrijalva/jwt-go/v4"
19+
"github.com/golang-jwt/jwt"
2020
"github.com/pkg/errors"
2121
)
2222

@@ -173,7 +173,7 @@ func (s *SignalR) Invoke(req *bindings.InvokeRequest) (*bindings.InvokeResponse,
173173
}
174174

175175
func (s *SignalR) ensureValidToken(url string) (string, error) {
176-
now := jwt.Now()
176+
now := time.Now()
177177

178178
if existing, ok := s.tokens[url]; ok {
179179
if existing.token != "" && now.Before(existing.expiration) {
@@ -182,16 +182,14 @@ func (s *SignalR) ensureValidToken(url string) (string, error) {
182182
}
183183

184184
expiration := now.Add(1 * time.Hour)
185-
audience, err := jwt.ParseClaimStrings(url)
186-
if err != nil {
187-
return "", err
188-
}
189185

190186
claims := &jwt.StandardClaims{
191-
ExpiresAt: &jwt.Time{
192-
Time: expiration,
193-
},
194-
Audience: audience,
187+
ExpiresAt: expiration.Unix(),
188+
Audience: url,
189+
}
190+
191+
if err := claims.Valid(); err != nil {
192+
return "", err
195193
}
196194

197195
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)

bindings/mysql/mysql.go

Lines changed: 38 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"crypto/tls"
1010
"crypto/x509"
1111
"database/sql"
12+
"database/sql/driver"
1213
"encoding/json"
1314
"fmt"
1415
"io/ioutil"
16+
"reflect"
1517
"strconv"
1618
"time"
1719

@@ -203,7 +205,7 @@ func (m *Mysql) query(s string) ([]byte, error) {
203205
_ = rows.Err()
204206
}()
205207

206-
result, err := jsonify(rows)
208+
result, err := m.jsonify(rows)
207209
if err != nil {
208210
return nil, errors.Wrapf(err, "error marshalling query result for %s", s)
209211
}
@@ -277,92 +279,66 @@ func initDB(url, pemPath string) (*sql.DB, error) {
277279
return db, nil
278280
}
279281

280-
func jsonify(rows *sql.Rows) ([]byte, error) {
282+
func (m *Mysql) jsonify(rows *sql.Rows) ([]byte, error) {
281283
columnTypes, err := rows.ColumnTypes()
282284
if err != nil {
283285
return nil, err
284286
}
285287

286288
var ret []interface{}
287289
for rows.Next() {
288-
scanArgs := prepareScanArgs(columnTypes)
289-
err := rows.Scan(scanArgs...)
290+
values := prepareValues(columnTypes)
291+
err := rows.Scan(values...)
290292
if err != nil {
291293
return nil, err
292294
}
293295

294-
r := convertScanArgs(columnTypes, scanArgs)
296+
r := m.convert(columnTypes, values)
295297
ret = append(ret, r)
296298
}
297299

298300
return json.Marshal(ret)
299301
}
300302

301-
func convertScanArgs(columnTypes []*sql.ColumnType, scanArgs []interface{}) map[string]interface{} {
302-
r := map[string]interface{}{}
303-
304-
for i, v := range columnTypes {
305-
if s, ok := (scanArgs[i]).(*sql.NullString); ok {
306-
r[v.Name()] = s.String
307-
308-
continue
309-
}
310-
311-
if s, ok := (scanArgs[i]).(*sql.NullBool); ok {
312-
r[v.Name()] = s.Bool
313-
314-
continue
315-
}
316-
317-
if s, ok := (scanArgs[i]).(*sql.NullInt32); ok {
318-
r[v.Name()] = s.Int32
319-
320-
continue
321-
}
303+
func prepareValues(columnTypes []*sql.ColumnType) []interface{} {
304+
types := make([]reflect.Type, len(columnTypes))
305+
for i, tp := range columnTypes {
306+
types[i] = tp.ScanType()
307+
}
322308

323-
if s, ok := (scanArgs[i]).(*sql.NullInt64); ok {
324-
r[v.Name()] = s.Int64
309+
values := make([]interface{}, len(columnTypes))
310+
for i := range values {
311+
values[i] = reflect.New(types[i]).Interface()
312+
}
325313

326-
continue
327-
}
314+
return values
315+
}
328316

329-
if s, ok := (scanArgs[i]).(*sql.NullFloat64); ok {
330-
r[v.Name()] = s.Float64
317+
func (m *Mysql) convert(columnTypes []*sql.ColumnType, values []interface{}) map[string]interface{} {
318+
r := map[string]interface{}{}
331319

332-
continue
320+
for i, ct := range columnTypes {
321+
value := values[i]
322+
323+
switch v := values[i].(type) {
324+
case driver.Valuer:
325+
if vv, err := v.Value(); err == nil {
326+
value = interface{}(vv)
327+
} else {
328+
m.logger.Warnf("error to convert value: %v", err)
329+
}
330+
case *sql.RawBytes:
331+
// special case for sql.RawBytes, see https://github.com/go-sql-driver/mysql/blob/master/fields.go#L178
332+
switch ct.DatabaseTypeName() {
333+
case "VARCHAR", "CHAR":
334+
value = string(*v)
335+
}
333336
}
334337

335-
if s, ok := (scanArgs[i]).(*sql.NullTime); ok {
336-
r[v.Name()] = s.Time
337-
338-
continue
338+
if value != nil {
339+
r[ct.Name()] = value
339340
}
340-
341-
// this won't happen since the default switch is sql.NullString
342-
r[v.Name()] = scanArgs[i]
343341
}
344342

345343
return r
346344
}
347-
348-
func prepareScanArgs(columnTypes []*sql.ColumnType) []interface{} {
349-
scanArgs := make([]interface{}, len(columnTypes))
350-
for i, v := range columnTypes {
351-
switch v.DatabaseTypeName() {
352-
case "BOOL":
353-
scanArgs[i] = new(sql.NullBool)
354-
case "INT", "MEDIUMINT", "SMALLINT", "CHAR", "TINYINT":
355-
scanArgs[i] = new(sql.NullInt32)
356-
case "BIGINT":
357-
scanArgs[i] = new(sql.NullInt64)
358-
case "DOUBLE", "FLOAT", "DECIMAL":
359-
scanArgs[i] = new(sql.NullFloat64)
360-
case "DATE", "TIME", "YEAR":
361-
scanArgs[i] = new(sql.NullTime)
362-
default:
363-
scanArgs[i] = new(sql.NullString)
364-
}
365-
}
366-
367-
return scanArgs
368-
}

bindings/mysql/mysql_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestMysqlIntegration(t *testing.T) {
121121
assert.True(t, ok)
122122
// have to use custom layout to parse timestamp, see this: https://github.com/dapr/components-contrib/pull/615
123123
var tt time.Time
124-
tt, err = time.Parse("2006-01-02 15:04:05", ts)
124+
tt, err = time.Parse("2006-01-02T15:04:05Z", ts)
125125
assert.Nil(t, err)
126126
t.Logf("time stamp is: %v", tt)
127127
})

bindings/mysql/mysql_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestQuery(t *testing.T) {
2626
ret, err := m.query(`SELECT * FROM foo WHERE id < 4`)
2727
assert.Nil(t, err)
2828
t.Logf("query result: %s", ret)
29-
assert.Contains(t, string(ret), "\"id\":\"1\"")
29+
assert.Contains(t, string(ret), "\"id\":1")
3030
var result []interface{}
3131
err = json.Unmarshal(ret, &result)
3232
assert.Nil(t, err)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ require (
4646
github.com/denisenkom/go-mssqldb v0.0.0-20191128021309-1d7a30a10f73
4747
github.com/dghubble/go-twitter v0.0.0-20190719072343-39e5462e111f
4848
github.com/dghubble/oauth1 v0.6.0
49-
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1
5049
github.com/didip/tollbooth v4.0.2+incompatible
5150
github.com/dnaeon/go-vcr v1.1.0 // indirect
5251
github.com/eapache/go-resiliency v1.2.0 // indirect
@@ -62,6 +61,7 @@ require (
6261
github.com/go-redis/redis/v8 v8.8.0
6362
github.com/go-sql-driver/mysql v1.5.0
6463
github.com/gocql/gocql v0.0.0-20210515062232-b7ef815b4556
64+
github.com/golang-jwt/jwt v3.2.1+incompatible
6565
github.com/golang/mock v1.5.0
6666
github.com/golang/protobuf v1.4.3
6767
github.com/golang/snappy v0.0.3 // indirect

go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,7 @@ github.com/dghubble/oauth1 v0.6.0 h1:m1yC01Ohc/eF38jwZ8JUjL1a+XHHXtGQgK+MxQbmSx0
282282
github.com/dghubble/oauth1 v0.6.0/go.mod h1:8pFdfPkv/jr8mkChVbNVuJ0suiHe278BtWI4Tk1ujxk=
283283
github.com/dghubble/sling v1.3.0 h1:pZHjCJq4zJvc6qVQ5wN1jo5oNZlNE0+8T/h0XeXBUKU=
284284
github.com/dghubble/sling v1.3.0/go.mod h1:XXShWaBWKzNLhu2OxikSNFrlsvowtz4kyRuXUG7oQKY=
285-
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
286285
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
287-
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 h1:CaO/zOnF8VvUfEbhRatPcwKVWamvbYd8tQGRWacE9kU=
288-
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1/go.mod h1:+hnT3ywWDTAFrW5aE+u2Sa/wT555ZqwoCS+pk3p6ry4=
289286
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
290287
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
291288
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
@@ -432,6 +429,8 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP
432429
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
433430
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
434431
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
432+
github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c=
433+
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
435434
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
436435
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
437436
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=

pubsub/envelope.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ func FromCloudEvent(cloudEvent []byte, topic, pubsub, traceID string) (map[strin
103103
m[TopicField] = topic
104104
m[PubsubField] = pubsub
105105

106+
// specify default value if it's unspecified from the original CloudEvent
107+
if m[SourceField] == nil {
108+
m[SourceField] = DefaultCloudEventSource
109+
}
110+
111+
if m[TypeField] == nil {
112+
m[TypeField] = DefaultCloudEventType
113+
}
114+
115+
if m[SpecVersionField] == nil {
116+
m[SpecVersionField] = CloudEventsSpecVersion
117+
}
118+
106119
return m, nil
107120
}
108121

0 commit comments

Comments
 (0)