Merge branch 'master' into master

This commit is contained in:
Bernd Verst 2022-09-22 12:15:30 -07:00 committed by GitHub
commit f4fa64b0f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 122 additions and 26 deletions

View File

@ -255,6 +255,7 @@ jobs:
fi
- name: Prepare Cert Coverage Info
if: github.event_name == 'schedule'
run: |
mkdir -p tmp/cov_files
SOURCE_PATH_LINEAR=$(echo ${{ env.SOURCE_PATH }} |sed 's#/#\.#g') # converts slashes to dots in this string, so that it doesn't consider them sub-folders
@ -262,12 +263,14 @@ jobs:
- name: Upload Cert Coverage Artifact
uses: actions/upload-artifact@v3
if: github.event_name == 'schedule'
with:
name: certtest_cov
path: tmp/cov_files
retention-days: 1
- name: Component Coverage Discord Notification
- name: Component Coverage Discord Notification
if: github.event_name == 'schedule'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_MONITORING_WEBHOOK_URL }}
uses: Ilshidur/action-discord@0c4b27844ba47cb1c7bee539c8eead5284ce9fa9

View File

@ -24,7 +24,6 @@ import (
"strconv"
"strings"
"time"
"unicode"
"github.com/Azure/azure-storage-blob-go/azblob"
"github.com/google/uuid"
@ -466,28 +465,37 @@ func (a *AzureBlobStorage) isValidDeleteSnapshotsOptionType(accessType azblob.De
func (a *AzureBlobStorage) sanitizeMetadata(metadata map[string]string) map[string]string {
for key, val := range metadata {
oldkey := key
// Keep only letters and digits
key = strings.Map(func(r rune) rune {
if unicode.IsLetter(r) || unicode.IsDigit(r) {
return r
n := 0
newKey := make([]byte, len(key))
for i := 0; i < len(key); i++ {
if (key[i] >= 'A' && key[i] <= 'Z') ||
(key[i] >= 'a' && key[i] <= 'z') ||
(key[i] >= '0' && key[i] <= '9') {
newKey[n] = key[i]
n++
}
return -1
}, key)
}
if oldkey != key {
a.logger.Warnf("metadata key %s contains disallowed characters, sanitized to %s", oldkey, key)
delete(metadata, oldkey)
metadata[key] = val
if n != len(key) {
nks := string(newKey[:n])
a.logger.Warnf("metadata key %s contains disallowed characters, sanitized to %s", key, nks)
delete(metadata, key)
metadata[nks] = val
key = nks
}
// Remove all non-ascii characters
metadata[key] = strings.Map(func(r rune) rune {
if r > unicode.MaxASCII {
return -1
n = 0
newVal := make([]byte, len(val))
for i := 0; i < len(val); i++ {
if val[i] > 127 {
continue
}
return r
}, val)
newVal[n] = val[i]
n++
}
metadata[key] = string(newVal[:n])
}
return metadata

View File

@ -21,6 +21,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig"
@ -41,9 +42,14 @@ const (
defaultMaxRetryDelay = time.Second * 120
)
type azAppConfigClient interface {
GetSetting(ctx context.Context, key string, options *azappconfig.GetSettingOptions) (azappconfig.GetSettingResponse, error)
NewListSettingsPager(selector azappconfig.SettingSelector, options *azappconfig.ListSettingsOptions) *runtime.Pager[azappconfig.ListSettingsPage]
}
// ConfigurationStore is a Azure App Configuration store.
type ConfigurationStore struct {
client *azappconfig.Client
client azAppConfigClient
metadata metadata
logger logger.Logger
@ -205,7 +211,7 @@ func (r *ConfigurationStore) getAll(ctx context.Context, req *configuration.GetR
labelFilter = to.Ptr("*")
}
revPgr := r.client.NewListRevisionsPager(
allSettingsPgr := r.client.NewListSettingsPager(
azappconfig.SettingSelector{
KeyFilter: to.Ptr("*"),
LabelFilter: labelFilter,
@ -213,8 +219,8 @@ func (r *ConfigurationStore) getAll(ctx context.Context, req *configuration.GetR
},
nil)
for revPgr.More() {
if revResp, err := revPgr.NextPage(ctx); err == nil {
for allSettingsPgr.More() {
if revResp, err := allSettingsPgr.NextPage(ctx); err == nil {
for _, setting := range revResp.Settings {
item := &configuration.Item{
Metadata: map[string]string{},
@ -230,7 +236,6 @@ func (r *ConfigurationStore) getAll(ctx context.Context, req *configuration.GetR
return nil, fmt.Errorf("failed to load all keys, error is %s", err)
}
}
return items, nil
}

View File

@ -14,11 +14,15 @@ limitations under the License.
package appconfig
import (
"context"
"fmt"
"reflect"
"testing"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig"
"github.com/Azure/go-autorest/autorest/to"
"github.com/stretchr/testify/assert"
"github.com/dapr/components-contrib/configuration"
@ -26,6 +30,50 @@ import (
"github.com/dapr/kit/logger"
)
type MockConfigurationStore struct {
azAppConfigClient
}
func (m *MockConfigurationStore) GetSetting(ctx context.Context, key string, options *azappconfig.GetSettingOptions) (azappconfig.GetSettingResponse, error) {
if key == "testKey" {
settings := azappconfig.Setting{}
settings.Key = to.StringPtr("testKey")
settings.Value = to.StringPtr("testValue")
resp := azappconfig.GetSettingResponse{}
resp.Setting = settings
return resp, nil
}
resp := azappconfig.GetSettingResponse{}
return resp, nil
}
func (m *MockConfigurationStore) NewListSettingsPager(selector azappconfig.SettingSelector, options *azappconfig.ListSettingsOptions) *runtime.Pager[azappconfig.ListSettingsPage] {
settings := make([]azappconfig.Setting, 2)
setting1 := azappconfig.Setting{}
setting1.Key = to.StringPtr("testKey-1")
setting1.Value = to.StringPtr("testValue-1")
setting2 := azappconfig.Setting{}
setting2.Key = to.StringPtr("testKey-2")
setting2.Value = to.StringPtr("testValue-2")
settings[0] = setting1
settings[1] = setting2
return runtime.NewPager(runtime.PagingHandler[azappconfig.ListSettingsPage]{
More: func(azappconfig.ListSettingsPage) bool {
return false
},
Fetcher: func(ctx context.Context, cur *azappconfig.ListSettingsPage) (azappconfig.ListSettingsPage, error) {
listSettingPage := azappconfig.ListSettingsPage{}
listSettingPage.Settings = settings
return listSettingPage, nil
},
})
}
func TestNewAzureAppConfigurationStore(t *testing.T) {
type args struct {
logger logger.Logger
@ -49,6 +97,38 @@ func TestNewAzureAppConfigurationStore(t *testing.T) {
}
}
func Test_getConfigurationWithProvidedKeys(t *testing.T) {
s := NewAzureAppConfigurationStore(logger.NewLogger("test")).(*ConfigurationStore)
s.client = &MockConfigurationStore{}
t.Run("call getConfiguration for provided keys", func(t *testing.T) {
req := configuration.GetRequest{
Keys: []string{"testKey"},
Metadata: map[string]string{},
}
res, err := s.Get(context.Background(), &req)
assert.Nil(t, err)
assert.True(t, len(res.Items) == 1)
})
}
func Test_getConfigurationWithNoProvidedKeys(t *testing.T) {
s := NewAzureAppConfigurationStore(logger.NewLogger("test")).(*ConfigurationStore)
s.client = &MockConfigurationStore{}
t.Run("call getConfiguration for provided keys", func(t *testing.T) {
req := configuration.GetRequest{
Keys: []string{},
Metadata: map[string]string{},
}
res, err := s.Get(context.Background(), &req)
assert.Nil(t, err)
assert.True(t, len(res.Items) == 2)
})
}
func TestInit(t *testing.T) {
s := NewAzureAppConfigurationStore(logger.NewLogger("test"))
t.Run("Init with valid appConfigHost metadata", func(t *testing.T) {

4
go.mod
View File

@ -155,7 +155,7 @@ require (
require (
cloud.google.com/go/secretmanager v1.4.0
dubbo.apache.org/dubbo-go/v3 v3.0.3-0.20220610080020-48691a404537
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig v0.4.0
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig v0.4.1-0.20220914204640-4d445978fe75
github.com/aliyun/aliyun-log-go-sdk v0.1.37
github.com/apache/dubbo-go-hessian2 v1.11.0
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.12+incompatible
@ -409,7 +409,7 @@ require (
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect

4
go.sum
View File

@ -108,8 +108,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.3 h1:8LoU8N2lIUzkmstvwXvVfniMZ
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.3/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0 h1:QkAcEIAKbNL4KoFr4SathZPhDhF4mVwpBMFlYjyAqy8=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0/go.mod h1:bhXu1AjYL+wutSL/kpSq6s7733q2Rb0yuot9Zgfqa/0=
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig v0.4.0 h1:h/72OERa/5hgnKEOyQJ8gtJoTVX3uwHCavsraGadTZM=
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig v0.4.0/go.mod h1:p74+tP95m8830ypJk53L93+BEsjTKY4SKQ75J2NmS5U=
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig v0.4.1-0.20220914204640-4d445978fe75 h1:fXg1PuTP8+xhOnxrPtteHGbreNsTRFvu+NsbLCqQrWg=
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig v0.4.1-0.20220914204640-4d445978fe75/go.mod h1:p74+tP95m8830ypJk53L93+BEsjTKY4SKQ75J2NmS5U=
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v0.3.2 h1:yJegJqjhrMJ3Oe5s43jOTGL2AsE7pJyx+7Yqls/65tw=
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v0.3.2/go.mod h1:Fy3bbChFm4cZn6oIxYYqKB2FG3rBDxk3NZDLDJCHl+Q=
github.com/Azure/azure-sdk-for-go/sdk/data/aztables v1.0.1 h1:bFa9IcjvrCber6gGgDAUZ+I2bO8J7s8JxXmu9fhi2ss=