Skip to content

Commit

Permalink
Chore: use a single package for all Feature structs (dapr#3278)
Browse files Browse the repository at this point in the history
Signed-off-by: ItalyPaleAle <[email protected]>
Co-authored-by: Bernd Verst <[email protected]>
  • Loading branch information
2 people authored and eunicecompra committed Jan 9, 2024
1 parent de6fd33 commit 229f6f8
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 48 deletions.
1 change: 0 additions & 1 deletion .build-tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/invopop/jsonschema v0.6.0
github.com/spf13/cobra v1.6.1
github.com/xeipuuv/gojsonschema v1.2.1-0.20201027075954-b076d39a02e5
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
gopkg.in/yaml.v3 v3.0.1
sigs.k8s.io/yaml v1.4.0
)
Expand Down
2 changes: 0 additions & 2 deletions .build-tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.1-0.20201027075954-b076d39a02e5 h1:ImnGIsrcG8vwbovhYvvSY8fagVV6QhCWSWXfzwGDLVs=
github.com/xeipuuv/gojsonschema v1.2.1-0.20201027075954-b076d39a02e5/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
3 changes: 1 addition & 2 deletions .build-tools/pkg/metadataschema/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ package metadataschema
import (
"errors"
"fmt"
"slices"
"strings"

"golang.org/x/exp/slices"

mdutils "github.com/dapr/components-contrib/metadata"
)

Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ linters-settings:
desc: "must use context"
- pkg: "github.com/pkg/errors"
desc: "must use standard library (errors package and/or fmt.Errorf)"
- pkg: "golang.org/x/exp/slices"
desc: "must use slices from standard library"
- pkg: "github.com/go-chi/chi$"
desc: "must use github.com/go-chi/chi/v5"
- pkg: "github.com/cenkalti/backoff$"
Expand Down
3 changes: 1 addition & 2 deletions bindings/cloudflare/queues/cfqueues.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import (
"io"
"net/http"
"reflect"
"slices"
"strconv"

"golang.org/x/exp/slices"

"github.com/dapr/components-contrib/bindings"
"github.com/dapr/components-contrib/common/component/cloudflare/workers"
contribMetadata "github.com/dapr/components-contrib/metadata"
Expand Down
26 changes: 26 additions & 0 deletions common/features/feature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2023 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 features

import (
"slices"
)

// Feature is a generic type for features supported by components.
type Feature[T any] string

// IsPresent checks if a given feature is present in the list.
func (f Feature[T]) IsPresent(features []Feature[T]) bool {
return slices.Contains(features, f)
}
2 changes: 1 addition & 1 deletion configuration/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"reflect"
"regexp"
"slices"
"strconv"
"strings"
"sync"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
"golang.org/x/exp/slices"

"github.com/dapr/components-contrib/configuration"
contribMetadata "github.com/dapr/components-contrib/metadata"
Expand Down
9 changes: 2 additions & 7 deletions crypto/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ limitations under the License.
package crypto

import (
"golang.org/x/exp/slices"
"github.com/dapr/components-contrib/common/features"
)

// Feature names a feature that can be implemented by the crypto provider components.
type Feature string

// IsPresent checks if a given feature is present in the list.
func (f Feature) IsPresent(features []Feature) bool {
return slices.Contains(features, f)
}
type Feature = features.Feature[SubtleCrypto]
2 changes: 1 addition & 1 deletion crypto/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ package crypto

import (
"encoding/json"
"slices"
"time"

"github.com/lestrrat-go/jwx/v2/jwk"
"golang.org/x/exp/slices"
)

// Key extends jwk.Key adding optional properties for determining if the key is valid (time bounds) or can be used for certain purposes.
Expand Down
2 changes: 1 addition & 1 deletion middleware/http/opa/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"net/http"
"net/textproto"
"reflect"
"slices"
"strconv"
"strings"
"time"

"github.com/open-policy-agent/opa/rego"
"golang.org/x/exp/slices"

"github.com/dapr/components-contrib/common/httputils"
contribMetadata "github.com/dapr/components-contrib/metadata"
Expand Down
9 changes: 2 additions & 7 deletions pubsub/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
package pubsub

import (
"golang.org/x/exp/slices"
"github.com/dapr/components-contrib/common/features"
)

const (
Expand All @@ -26,9 +26,4 @@ const (
)

// Feature names a feature that can be implemented by PubSub components.
type Feature string

// IsPresent checks if a given feature is present in the list.
func (f Feature) IsPresent(features []Feature) bool {
return slices.Contains(features, f)
}
type Feature = features.Feature[PubSub]
10 changes: 2 additions & 8 deletions secretstores/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ limitations under the License.
package secretstores

import (
"golang.org/x/exp/slices"
"github.com/dapr/components-contrib/common/features"
)

// Feature names a feature that can be implemented by Secret Store components.
type Feature string

const (
// FeatureMultipleKeyValuesPerSecret advertises that this SecretStore supports multiple keys-values under a single secret.
FeatureMultipleKeyValuesPerSecret Feature = "MULTIPLE_KEY_VALUES_PER_SECRET"
)

// IsPresent checks if a given feature is present in the list.
func (f Feature) IsPresent(features []Feature) bool {
return slices.Contains(features, f)
}
type Feature = features.Feature[SecretStore]
2 changes: 1 addition & 1 deletion state/cloudflare/workerskv/workerskv.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"net/http"
"net/url"
"reflect"
"slices"
"strconv"

"github.com/mitchellh/mapstructure"
"golang.org/x/exp/slices"

"github.com/dapr/components-contrib/common/component/cloudflare/workers"
"github.com/dapr/components-contrib/metadata"
Expand Down
9 changes: 2 additions & 7 deletions state/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
package state

import (
"golang.org/x/exp/slices"
"github.com/dapr/components-contrib/common/features"
)

const (
Expand All @@ -31,9 +31,4 @@ const (
)

// Feature names a feature that can be implemented by state store components.
type Feature string

// IsPresent checks if a given feature is present in the list.
func (f Feature) IsPresent(features []Feature) bool {
return slices.Contains(features, f)
}
type Feature = features.Feature[BaseStore]
2 changes: 1 addition & 1 deletion tests/certification/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ require (
go.mongodb.org/mongo-driver v1.12.1
go.uber.org/multierr v1.11.0
go.uber.org/ratelimit v0.3.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
modernc.org/sqlite v1.27.0
)
Expand Down Expand Up @@ -298,6 +297,7 @@ require (
go.uber.org/zap v1.24.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion tests/certification/middleware/http/bearer/bearer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"net/http"
"slices"
"strconv"
"sync/atomic"
"testing"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/lestrrat-go/jwx/v2/jwt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

// Import the embed package.
_ "embed"
Expand Down
2 changes: 1 addition & 1 deletion tests/certification/state/azure/cosmosdb/cosmosdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ package cosmosDBStorage_test

import (
"os"
"slices"
"strconv"
"strings"
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/dapr/components-contrib/metadata"
secretstore_env "github.com/dapr/components-contrib/secretstores/local/env"
Expand Down
2 changes: 1 addition & 1 deletion tests/conformance/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
"bytes"
"context"
"encoding/json"
"slices"
"strings"
"testing"
"time"

"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

contribCrypto "github.com/dapr/components-contrib/crypto"
"github.com/dapr/components-contrib/metadata"
Expand Down
2 changes: 1 addition & 1 deletion tests/conformance/crypto/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"hash"
"io"
"log"
"slices"
"strings"
"testing"

"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

type keybag struct {
Expand Down
2 changes: 1 addition & 1 deletion tests/conformance/pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"reflect"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/dapr/components-contrib/metadata"
"github.com/dapr/components-contrib/pubsub"
Expand Down
2 changes: 1 addition & 1 deletion tests/conformance/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"encoding/json"
"fmt"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -26,7 +27,6 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/dapr/components-contrib/contenttype"
"github.com/dapr/components-contrib/metadata"
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/pubsub/jetstream/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cast v1.5.1 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sys v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down

0 comments on commit 229f6f8

Please sign in to comment.