Skip to content

Commit ae3c152

Browse files
authored
Merge pull request #2 from berndverst/pr2215
Update PR 2215 with Upstream
2 parents 0e783e5 + 4b490ad commit ae3c152

File tree

156 files changed

+2516
-2179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+2516
-2179
lines changed

.github/workflows/certification.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ jobs:
245245
working-directory: ${{ env.TEST_PATH }}
246246
run: |
247247
echo "Running certification tests for ${{ matrix.component }} ... "
248-
export GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn
248+
export GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore
249249
set +e
250250
gotestsum --jsonfile ${{ env.TEST_OUTPUT_FILE_PREFIX }}_certification.json \
251251
--junitfile ${{ env.TEST_OUTPUT_FILE_PREFIX }}_certification.xml --format standard-quiet -- \

.golangci.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,14 @@ linters-settings:
116116
# minimal occurrences count to trigger, 3 by default
117117
min-occurrences: 5
118118
depguard:
119-
list-type: blacklist
119+
list-type: denylist
120120
include-go-root: false
121-
packages:
122-
- github.com/Sirupsen/logrus
123-
packages-with-error-messages:
124-
# specify an error message to output when a blacklisted package is used
125-
github.com/Sirupsen/logrus: "must use github.com/dapr/kit/logger"
121+
packages-with-error-message:
122+
- "github.com/Sirupsen/logrus": "must use github.com/dapr/kit/logger"
123+
- "github.com/agrea/ptr": "must use github.com/dapr/kit/ptr"
124+
- "github.com/cenkalti/backoff": "must use github.com/cenkalti/backoff/v4"
125+
- "github.com/cenkalti/backoff/v2": "must use github.com/cenkalti/backoff/v4"
126+
- "github.com/cenkalti/backoff/v3": "must use github.com/cenkalti/backoff/v4"
126127
misspell:
127128
# Correct spellings using locale preferences for US or UK.
128129
# Default is to use a neutral variety of English.

bindings/mysql/mysql.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import (
2020
"database/sql"
2121
"database/sql/driver"
2222
"encoding/json"
23+
"errors"
2324
"fmt"
2425
"os"
2526
"reflect"
2627
"strconv"
2728
"time"
2829

2930
"github.com/go-sql-driver/mysql"
30-
"github.com/pkg/errors"
3131

3232
"github.com/dapr/components-contrib/bindings"
3333
"github.com/dapr/kit/logger"
@@ -117,7 +117,7 @@ func (m *Mysql) Init(metadata bindings.Metadata) error {
117117

118118
err = db.Ping()
119119
if err != nil {
120-
return errors.Wrap(err, "unable to ping the DB")
120+
return fmt.Errorf("unable to ping the DB: %w", err)
121121
}
122122

123123
m.db = db
@@ -128,21 +128,21 @@ func (m *Mysql) Init(metadata bindings.Metadata) error {
128128
// Invoke handles all invoke operations.
129129
func (m *Mysql) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) {
130130
if req == nil {
131-
return nil, errors.Errorf("invoke request required")
131+
return nil, errors.New("invoke request required")
132132
}
133133

134134
if req.Operation == closeOperation {
135135
return nil, m.db.Close()
136136
}
137137

138138
if req.Metadata == nil {
139-
return nil, errors.Errorf("metadata required")
139+
return nil, errors.New("metadata required")
140140
}
141141
m.logger.Debugf("operation: %v", req.Operation)
142142

143143
s, ok := req.Metadata[commandSQLKey]
144144
if !ok || s == "" {
145-
return nil, errors.Errorf("required metadata not set: %s", commandSQLKey)
145+
return nil, fmt.Errorf("required metadata not set: %s", commandSQLKey)
146146
}
147147

148148
startTime := time.Now()
@@ -171,7 +171,7 @@ func (m *Mysql) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bindi
171171
resp.Data = d
172172

173173
default:
174-
return nil, errors.Errorf("invalid operation type: %s. Expected %s, %s, or %s",
174+
return nil, fmt.Errorf("invalid operation type: %s. Expected %s, %s, or %s",
175175
req.Operation, execOperation, queryOperation, closeOperation)
176176
}
177177

@@ -201,11 +201,9 @@ func (m *Mysql) Close() error {
201201
}
202202

203203
func (m *Mysql) query(ctx context.Context, sql string) ([]byte, error) {
204-
m.logger.Debugf("query: %s", sql)
205-
206204
rows, err := m.db.QueryContext(ctx, sql)
207205
if err != nil {
208-
return nil, errors.Wrapf(err, "error executing %s", sql)
206+
return nil, fmt.Errorf("error executing query: %w", err)
209207
}
210208

211209
defer func() {
@@ -215,7 +213,7 @@ func (m *Mysql) query(ctx context.Context, sql string) ([]byte, error) {
215213

216214
result, err := m.jsonify(rows)
217215
if err != nil {
218-
return nil, errors.Wrapf(err, "error marshalling query result for %s", sql)
216+
return nil, fmt.Errorf("error marshalling query result for query: %w", err)
219217
}
220218

221219
return result, nil
@@ -226,7 +224,7 @@ func (m *Mysql) exec(ctx context.Context, sql string) (int64, error) {
226224

227225
res, err := m.db.ExecContext(ctx, sql)
228226
if err != nil {
229-
return 0, errors.Wrapf(err, "error executing %s", sql)
227+
return 0, fmt.Errorf("error executing query: %w", err)
230228
}
231229

232230
return res.RowsAffected()
@@ -237,7 +235,7 @@ func propertyToInt(props map[string]string, key string, setter func(int)) error
237235
if i, err := strconv.Atoi(v); err == nil {
238236
setter(i)
239237
} else {
240-
return errors.Wrapf(err, "error converitng %s:%s to int", key, v)
238+
return fmt.Errorf("error converting %s:%s to int: %w", key, v, err)
241239
}
242240
}
243241

@@ -249,7 +247,7 @@ func propertyToDuration(props map[string]string, key string, setter func(time.Du
249247
if d, err := time.ParseDuration(v); err == nil {
250248
setter(d)
251249
} else {
252-
return errors.Wrapf(err, "error converitng %s:%s to time duration", key, v)
250+
return fmt.Errorf("error converting %s:%s to duration: %w", key, v, err)
253251
}
254252
}
255253

@@ -258,14 +256,14 @@ func propertyToDuration(props map[string]string, key string, setter func(time.Du
258256

259257
func initDB(url, pemPath string) (*sql.DB, error) {
260258
if _, err := mysql.ParseDSN(url); err != nil {
261-
return nil, errors.Wrapf(err, "illegal Data Source Name (DNS) specified by %s", connectionURLKey)
259+
return nil, fmt.Errorf("illegal Data Source Name (DSN) specified by %s", connectionURLKey)
262260
}
263261

264262
if pemPath != "" {
265263
rootCertPool := x509.NewCertPool()
266264
pem, err := os.ReadFile(pemPath)
267265
if err != nil {
268-
return nil, errors.Wrapf(err, "Error reading PEM file from %s", pemPath)
266+
return nil, fmt.Errorf("error reading PEM file from %s: %w", pemPath, err)
269267
}
270268

271269
ok := rootCertPool.AppendCertsFromPEM(pem)
@@ -275,13 +273,13 @@ func initDB(url, pemPath string) (*sql.DB, error) {
275273

276274
err = mysql.RegisterTLSConfig("custom", &tls.Config{RootCAs: rootCertPool, MinVersion: tls.VersionTLS12})
277275
if err != nil {
278-
return nil, errors.Wrap(err, "Error register TLS config")
276+
return nil, fmt.Errorf("error register TLS config: %w", err)
279277
}
280278
}
281279

282280
db, err := sql.Open("mysql", url)
283281
if err != nil {
284-
return nil, errors.Wrap(err, "error opening DB connection")
282+
return nil, fmt.Errorf("error opening DB connection: %w", err)
285283
}
286284

287285
return db, nil

configuration/redis/metadata.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ package redis
1616
import "time"
1717

1818
type metadata struct {
19-
host string
20-
password string
21-
sentinelMasterName string
22-
maxRetries int
23-
maxRetryBackoff time.Duration
24-
enableTLS bool
25-
failover bool
19+
Host string
20+
Password string
21+
SentinelMasterName string
22+
MaxRetries int
23+
MaxRetryBackoff time.Duration
24+
EnableTLS bool
25+
Failover bool
2626
}

configuration/redis/redis.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,54 +78,54 @@ func parseRedisMetadata(meta configuration.Metadata) (metadata, error) {
7878
m := metadata{}
7979

8080
if val, ok := meta.Properties[host]; ok && val != "" {
81-
m.host = val
81+
m.Host = val
8282
} else {
8383
return m, errors.New("redis store error: missing host address")
8484
}
8585

8686
if val, ok := meta.Properties[password]; ok && val != "" {
87-
m.password = val
87+
m.Password = val
8888
}
8989

90-
m.enableTLS = defaultEnableTLS
90+
m.EnableTLS = defaultEnableTLS
9191
if val, ok := meta.Properties[enableTLS]; ok && val != "" {
9292
tls, err := strconv.ParseBool(val)
9393
if err != nil {
9494
return m, fmt.Errorf("redis store error: can't parse enableTLS field: %s", err)
9595
}
96-
m.enableTLS = tls
96+
m.EnableTLS = tls
9797
}
9898

99-
m.maxRetries = defaultMaxRetries
99+
m.MaxRetries = defaultMaxRetries
100100
if val, ok := meta.Properties[maxRetries]; ok && val != "" {
101101
parsedVal, err := strconv.ParseInt(val, defaultBase, defaultBitSize)
102102
if err != nil {
103103
return m, fmt.Errorf("redis store error: can't parse maxRetries field: %s", err)
104104
}
105-
m.maxRetries = int(parsedVal)
105+
m.MaxRetries = int(parsedVal)
106106
}
107107

108-
m.maxRetryBackoff = defaultMaxRetryBackoff
108+
m.MaxRetryBackoff = defaultMaxRetryBackoff
109109
if val, ok := meta.Properties[maxRetryBackoff]; ok && val != "" {
110110
parsedVal, err := strconv.ParseInt(val, defaultBase, defaultBitSize)
111111
if err != nil {
112112
return m, fmt.Errorf("redis store error: can't parse maxRetryBackoff field: %s", err)
113113
}
114-
m.maxRetryBackoff = time.Duration(parsedVal)
114+
m.MaxRetryBackoff = time.Duration(parsedVal)
115115
}
116116

117117
if val, ok := meta.Properties[failover]; ok && val != "" {
118118
failover, err := strconv.ParseBool(val)
119119
if err != nil {
120120
return m, fmt.Errorf("redis store error: can't parse failover field: %s", err)
121121
}
122-
m.failover = failover
122+
m.Failover = failover
123123
}
124124

125125
// set the sentinelMasterName only with failover == true.
126-
if m.failover {
126+
if m.Failover {
127127
if val, ok := meta.Properties[sentinelMasterName]; ok && val != "" {
128-
m.sentinelMasterName = val
128+
m.SentinelMasterName = val
129129
} else {
130130
return m, errors.New("redis store error: missing sentinelMasterName")
131131
}
@@ -142,14 +142,14 @@ func (r *ConfigurationStore) Init(metadata configuration.Metadata) error {
142142
}
143143
r.metadata = m
144144

145-
if r.metadata.failover {
145+
if r.metadata.Failover {
146146
r.client = r.newFailoverClient(m)
147147
} else {
148148
r.client = r.newClient(m)
149149
}
150150

151151
if _, err = r.client.Ping(context.TODO()).Result(); err != nil {
152-
return fmt.Errorf("redis store: error connecting to redis at %s: %s", m.host, err)
152+
return fmt.Errorf("redis store: error connecting to redis at %s: %s", m.Host, err)
153153
}
154154

155155
r.replicas, err = r.getConnectedSlaves()
@@ -159,18 +159,18 @@ func (r *ConfigurationStore) Init(metadata configuration.Metadata) error {
159159

160160
func (r *ConfigurationStore) newClient(m metadata) *redis.Client {
161161
opts := &redis.Options{
162-
Addr: m.host,
163-
Password: m.password,
162+
Addr: m.Host,
163+
Password: m.Password,
164164
DB: defaultDB,
165-
MaxRetries: m.maxRetries,
166-
MaxRetryBackoff: m.maxRetryBackoff,
165+
MaxRetries: m.MaxRetries,
166+
MaxRetryBackoff: m.MaxRetryBackoff,
167167
}
168168

169169
// tell the linter to skip a check here.
170170
/* #nosec */
171-
if m.enableTLS {
171+
if m.EnableTLS {
172172
opts.TLSConfig = &tls.Config{
173-
InsecureSkipVerify: m.enableTLS,
173+
InsecureSkipVerify: m.EnableTLS,
174174
}
175175
}
176176

@@ -179,17 +179,17 @@ func (r *ConfigurationStore) newClient(m metadata) *redis.Client {
179179

180180
func (r *ConfigurationStore) newFailoverClient(m metadata) *redis.Client {
181181
opts := &redis.FailoverOptions{
182-
MasterName: r.metadata.sentinelMasterName,
183-
SentinelAddrs: []string{r.metadata.host},
182+
MasterName: r.metadata.SentinelMasterName,
183+
SentinelAddrs: []string{r.metadata.Host},
184184
DB: defaultDB,
185-
MaxRetries: m.maxRetries,
186-
MaxRetryBackoff: m.maxRetryBackoff,
185+
MaxRetries: m.MaxRetries,
186+
MaxRetryBackoff: m.MaxRetryBackoff,
187187
}
188188

189189
/* #nosec */
190-
if m.enableTLS {
190+
if m.EnableTLS {
191191
opts.TLSConfig = &tls.Config{
192-
InsecureSkipVerify: m.enableTLS,
192+
InsecureSkipVerify: m.EnableTLS,
193193
}
194194
}
195195

configuration/redis/redis_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ func Test_parseRedisMetadata(t *testing.T) {
264264
}},
265265
},
266266
want: metadata{
267-
host: "testHost",
268-
password: "testPassword",
269-
enableTLS: true,
270-
maxRetries: 10,
271-
maxRetryBackoff: time.Second,
272-
failover: true,
273-
sentinelMasterName: "tesSentinelMasterName",
267+
Host: "testHost",
268+
Password: "testPassword",
269+
EnableTLS: true,
270+
MaxRetries: 10,
271+
MaxRetryBackoff: time.Second,
272+
Failover: true,
273+
SentinelMasterName: "tesSentinelMasterName",
274274
},
275275
},
276276
}

0 commit comments

Comments
 (0)