From da7f3088d432e144cbcb4ca8b2a3ea0562600d7f Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Tue, 6 Jul 2021 15:19:05 -0400 Subject: [PATCH 01/39] adding conn str parser --- sdk/tables/aztable/table_client.go | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/sdk/tables/aztable/table_client.go b/sdk/tables/aztable/table_client.go index 3a5fc2d9de22..ee2f0785458d 100644 --- a/sdk/tables/aztable/table_client.go +++ b/sdk/tables/aztable/table_client.go @@ -6,6 +6,8 @@ package aztable import ( "context" "errors" + "fmt" + "strings" "github.com/Azure/azure-sdk-for-go/sdk/azcore" ) @@ -31,6 +33,80 @@ func NewTableClient(tableName string, serviceURL string, cred azcore.Credential, return s.NewTableClient(tableName), err } +func parseConnectionString(connStr string) (string, azcore.Credential, error) { + var serviceURL string + var cred azcore.Credential + splitString := strings.Split(connStr, ";") + var pairs [][]string + for _, splitPair := range splitString { + temp := strings.Split(splitPair, "=") + if len(temp) != 2 { + return serviceURL, cred, errors.New("Connection string is either blank or malformed") + } + pairs = append(pairs, temp) + } + + pairsMap := make(map[string]string) + for _, pair := range pairs { + pairsMap[pair[0]] = pair[1] + } + + var accountName string + var accountKey string + if value, ok := pairsMap["accountname"]; ok { + accountName = value + } + if value, ok := pairsMap["accountkey"]; ok { + accountKey = value + } + + if accountName == "" || accountKey == "" { + // Try sharedaccesssignature + sharedAccessSignature, ok := pairsMap["sharedaccesssignature"] + if !ok { + return serviceURL, cred, errors.New("Connection string missing required connection details") + } + cred = azcore.SharedAccessSignature(sharedAccessSignature) + } + + cred = &SharedKeyCredential{ + accountName: accountName, + accountKey: accountKey, + } + + primary, okPrimary := pairsMap["tableendpoint"] + secondary, okSecondary := pairsMap["tablesecondaryendpoint"] + if !okPrimary { + if okSecondary { + return serviceURL, cred, errors.New("Connection string specifies only secondary connection") + } + if endpointsProtocol, ok := pairsMap["defaultendpointsprotocol"]; ok { + if accountName, ok := pairsMap["accountname"]; ok { + if endpointSuffix, ok := pairsMap["endpointsuffix"]; ok { + primary = fmt.Sprintf("%v://%v.table.%v", endpointsProtocol, accountName, endpointSuffix) + secondary = fmt.Sprintf("%v-secondary.table.%v", accountName, endpointSuffix) + okPrimary = true + okSecondary = true + } + } + } + } + + if !okPrimary { + + } + + if serviceURL, ok = pairsMap["tableendpoint"]; !ok { + return serviceURL, cred, errors.New("Connection string does not specify") + } + + return serviceURL, cred, nil +} + +func NewTableClientFromConnectionString(tableName string, connectionString string, options *TableClientOptions) (*TableClient, error) { + endpoint, credential := parseConnectionString(connectionString) +} + // Create creates the table with the tableName specified when NewTableClient was called. func (t *TableClient) Create(ctx context.Context) (TableResponseResponse, error) { return t.service.Create(ctx, t.Name) From 4f2de5f4131bf8d9051fd0aaec6f618be6d6744d Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 29 Jul 2021 12:07:47 -0400 Subject: [PATCH 02/39] Basic conn str parser --- sdk/tables/aztable/connection_string.go | 119 +++++++++++++++++++ sdk/tables/aztable/connection_string_test.go | 40 +++++++ sdk/tables/aztable/table_client.go | 76 ------------ 3 files changed, 159 insertions(+), 76 deletions(-) create mode 100644 sdk/tables/aztable/connection_string.go create mode 100644 sdk/tables/aztable/connection_string_test.go diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go new file mode 100644 index 000000000000..d2cf2ac5570f --- /dev/null +++ b/sdk/tables/aztable/connection_string.go @@ -0,0 +1,119 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package aztable + +import ( + "errors" + "fmt" + "strings" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" +) + +var ErrConnectionString = errors.New("connection string is either blank or malformed") + +func NewTableClientFromConnectionString(tableName string, connectionString string, options *TableClientOptions) (*TableClient, error) { + endpoint, credential, err := parseConnectionString(connectionString) + if err != nil { + return nil, err + } + return NewTableClient(tableName, endpoint, *credential, options) +} + +func NewTableServiceClientFrommConnectionString(connectionString string, options *TableClientOptions) (*TableServiceClient, error) { + endpoint, credential, err := parseConnectionString(connectionString) + if err != nil { + return nil, err + } + return NewTableServiceClient(endpoint, *credential, options) +} + +func convertConnStrToMap(connStr string) (map[string]string, error) { + ret := make(map[string]string) + + splitString := strings.Split(connStr, ";") + if len(splitString) == 0 { + return ret, ErrConnectionString + } + for _, stringPart := range splitString { + parts := strings.Split(stringPart, "=") + if len(parts) != 2 { + return ret, ErrConnectionString + } + ret[parts[0]] = parts[1] + } + return ret, nil +} + +func parseConnectionString(connStr string) (string, *azcore.Credential, error) { + var serviceURL string + var cred azcore.Credential + + connStrMap, err := convertConnStrToMap(connStr) + if err != nil { + return "", nil, err + } + + accountName, ok := connStrMap["AccountName"] + if !ok { + return "", nil, ErrConnectionString + } + accountKey, ok := connStrMap["AccountKey"] + if !ok { + return "", nil, ErrConnectionString + } + + if accountName == "" || accountKey == "" { + // Try sharedaccesssignature + sharedAccessSignature, ok := connStrMap["sharedaccesssignature"] + if !ok { + return serviceURL, nil, ErrConnectionString + } + return sharedAccessSignature, nil, errors.New("there is not support for SharedAccessSignature yet") + // cred = azcore.SharedAccessSignature(sharedAccessSignature) + } + defaultProtocol, ok := connStrMap["DefaultEndpointsProtocol"] + if !ok { + defaultProtocol = "https" + } + + endpointSuffix, ok := connStrMap["EndpointSuffix"] + if !ok { + endpointSuffix = "core.windows.net" + } + serviceURL = fmt.Sprintf("%v://%v.table.%v", defaultProtocol, accountName, endpointSuffix) + + cred, err = NewSharedKeyCredential(accountName, accountKey) + if err != nil { + return "", nil, err + } + + // primary, okPrimary := pairsMap["tableendpoint"] + // secondary, okSecondary := pairsMap["tablesecondaryendpoint"] + // if !okPrimary { + // if okSecondary { + // return serviceURL, cred, errors.New("Connection string specifies only secondary connection") + // } + // if endpointsProtocol, ok := pairsMap["defaultendpointsprotocol"]; ok { + // if accountName, ok := pairsMap["accountname"]; ok { + // if endpointSuffix, ok := pairsMap["endpointsuffix"]; ok { + // primary = fmt.Sprintf("%v://%v.table.%v", endpointsProtocol, accountName, endpointSuffix) + // secondary = fmt.Sprintf("%v-secondary.table.%v", accountName, endpointSuffix) + // okPrimary = true + // okSecondary = true + // } + // } + // } + // } + + // if !okPrimary { + + // } + + // if serviceURL, ok = pairsMap["tableendpoint"]; !ok { + // return serviceURL, cred, errors.New("Connection string does not specify") + // } + + return serviceURL, &cred, nil +} diff --git a/sdk/tables/aztable/connection_string_test.go b/sdk/tables/aztable/connection_string_test.go new file mode 100644 index 000000000000..93cd50d460c3 --- /dev/null +++ b/sdk/tables/aztable/connection_string_test.go @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package aztable + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestConnectionStringParser(t *testing.T) { + require := require.New(t) + + connStr := "DefaultEndpointsProtocol=https;AccountName=dummyaccount;AccountKey=secretkeykey;EndpointSuffix=core.windows.net" + serviceURL, cred, err := parseConnectionString(connStr) + require.NoError(err) + require.Equal(serviceURL, "https://dummyaccount.table.core.windows.net") + require.NotNil(cred) +} + +func TestConnectionStringParserHTTP(t *testing.T) { + require := require.New(t) + + connStr := "DefaultEndpointsProtocol=http;AccountName=dummyaccount;AccountKey=secretkeykey;EndpointSuffix=core.windows.net" + serviceURL, cred, err := parseConnectionString(connStr) + require.NoError(err) + require.Equal(serviceURL, "http://dummyaccount.table.core.windows.net") + require.NotNil(cred) +} + +func TestConnectionStringParserBasic(t *testing.T) { + require := require.New(t) + + connStr := "AccountName=dummyaccount;AccountKey=secretkeykey" + serviceURL, cred, err := parseConnectionString(connStr) + require.NoError(err) + require.Equal(serviceURL, "https://dummyaccount.table.core.windows.net") + require.NotNil(cred) +} diff --git a/sdk/tables/aztable/table_client.go b/sdk/tables/aztable/table_client.go index ee2f0785458d..3a5fc2d9de22 100644 --- a/sdk/tables/aztable/table_client.go +++ b/sdk/tables/aztable/table_client.go @@ -6,8 +6,6 @@ package aztable import ( "context" "errors" - "fmt" - "strings" "github.com/Azure/azure-sdk-for-go/sdk/azcore" ) @@ -33,80 +31,6 @@ func NewTableClient(tableName string, serviceURL string, cred azcore.Credential, return s.NewTableClient(tableName), err } -func parseConnectionString(connStr string) (string, azcore.Credential, error) { - var serviceURL string - var cred azcore.Credential - splitString := strings.Split(connStr, ";") - var pairs [][]string - for _, splitPair := range splitString { - temp := strings.Split(splitPair, "=") - if len(temp) != 2 { - return serviceURL, cred, errors.New("Connection string is either blank or malformed") - } - pairs = append(pairs, temp) - } - - pairsMap := make(map[string]string) - for _, pair := range pairs { - pairsMap[pair[0]] = pair[1] - } - - var accountName string - var accountKey string - if value, ok := pairsMap["accountname"]; ok { - accountName = value - } - if value, ok := pairsMap["accountkey"]; ok { - accountKey = value - } - - if accountName == "" || accountKey == "" { - // Try sharedaccesssignature - sharedAccessSignature, ok := pairsMap["sharedaccesssignature"] - if !ok { - return serviceURL, cred, errors.New("Connection string missing required connection details") - } - cred = azcore.SharedAccessSignature(sharedAccessSignature) - } - - cred = &SharedKeyCredential{ - accountName: accountName, - accountKey: accountKey, - } - - primary, okPrimary := pairsMap["tableendpoint"] - secondary, okSecondary := pairsMap["tablesecondaryendpoint"] - if !okPrimary { - if okSecondary { - return serviceURL, cred, errors.New("Connection string specifies only secondary connection") - } - if endpointsProtocol, ok := pairsMap["defaultendpointsprotocol"]; ok { - if accountName, ok := pairsMap["accountname"]; ok { - if endpointSuffix, ok := pairsMap["endpointsuffix"]; ok { - primary = fmt.Sprintf("%v://%v.table.%v", endpointsProtocol, accountName, endpointSuffix) - secondary = fmt.Sprintf("%v-secondary.table.%v", accountName, endpointSuffix) - okPrimary = true - okSecondary = true - } - } - } - } - - if !okPrimary { - - } - - if serviceURL, ok = pairsMap["tableendpoint"]; !ok { - return serviceURL, cred, errors.New("Connection string does not specify") - } - - return serviceURL, cred, nil -} - -func NewTableClientFromConnectionString(tableName string, connectionString string, options *TableClientOptions) (*TableClient, error) { - endpoint, credential := parseConnectionString(connectionString) -} - // Create creates the table with the tableName specified when NewTableClient was called. func (t *TableClient) Create(ctx context.Context) (TableResponseResponse, error) { return t.service.Create(ctx, t.Name) From c94e1ce9b0d194f76fa088098a80b0048dd126fa Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 29 Jul 2021 12:36:12 -0400 Subject: [PATCH 03/39] adding support for custom domains --- sdk/tables/aztable/connection_string.go | 7 +++++++ sdk/tables/aztable/connection_string_test.go | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index d2cf2ac5570f..86e86ef164b3 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -31,6 +31,7 @@ func NewTableServiceClientFrommConnectionString(connectionString string, options func convertConnStrToMap(connStr string) (map[string]string, error) { ret := make(map[string]string) + connStr = strings.TrimRight(connStr, ";") splitString := strings.Split(connStr, ";") if len(splitString) == 0 { @@ -82,6 +83,12 @@ func parseConnectionString(connStr string) (string, *azcore.Credential, error) { if !ok { endpointSuffix = "core.windows.net" } + + tableEndpoint, ok := connStrMap["TableEndpoint"] + if ok { + cred, err = NewSharedKeyCredential(accountName, accountKey) + return tableEndpoint, &cred, err + } serviceURL = fmt.Sprintf("%v://%v.table.%v", defaultProtocol, accountName, endpointSuffix) cred, err = NewSharedKeyCredential(accountName, accountKey) diff --git a/sdk/tables/aztable/connection_string_test.go b/sdk/tables/aztable/connection_string_test.go index 93cd50d460c3..57508326ec4c 100644 --- a/sdk/tables/aztable/connection_string_test.go +++ b/sdk/tables/aztable/connection_string_test.go @@ -38,3 +38,13 @@ func TestConnectionStringParserBasic(t *testing.T) { require.Equal(serviceURL, "https://dummyaccount.table.core.windows.net") require.NotNil(cred) } + +func TestConnectionStringParserCustomDomain(t *testing.T) { + require := require.New(t) + + connStr := "AccountName=dummyaccount;AccountKey=secretkeykey;TableEndpoint=www.mydomain.com;" + serviceURL, cred, err := parseConnectionString(connStr) + require.NoError(err) + require.Equal(serviceURL, "www.mydomain.com") + require.NotNil(cred) +} From bbe00cdb66e41c7db6f525f5f4a06298d2af3cd6 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 29 Jul 2021 12:53:36 -0400 Subject: [PATCH 04/39] invalid tests --- sdk/tables/aztable/connection_string_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sdk/tables/aztable/connection_string_test.go b/sdk/tables/aztable/connection_string_test.go index 57508326ec4c..78065ad16612 100644 --- a/sdk/tables/aztable/connection_string_test.go +++ b/sdk/tables/aztable/connection_string_test.go @@ -48,3 +48,23 @@ func TestConnectionStringParserCustomDomain(t *testing.T) { require.Equal(serviceURL, "www.mydomain.com") require.NotNil(cred) } + +func TestConnectionStringParserInvalid(t *testing.T) { + badConnectionStrings := []string{ + "", + "foobar", + "foo;bar;baz", + "foo=;bar=;", + "=", + ";", + "=;==", + "foobar=baz=foo" + } + require := require.New(t) + + for _, badConnStr := range badConnectionStrings { + _, _, err := parseConnectionString(badConnStr) + require.Error(err) + require.Contains(err.Error(), ErrConnectionString.Error()) + } +} From d967e57dc91928e1c545632e7d6ab1d21bb2afa8 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 29 Jul 2021 12:57:02 -0400 Subject: [PATCH 05/39] adding self note --- sdk/tables/aztable/connection_string.go | 27 +------------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index 86e86ef164b3..c1e12704f4f6 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -73,6 +73,7 @@ func parseConnectionString(connStr string) (string, *azcore.Credential, error) { } return sharedAccessSignature, nil, errors.New("there is not support for SharedAccessSignature yet") // cred = azcore.SharedAccessSignature(sharedAccessSignature) + // TODO: fix this when shared access signatures are added. } defaultProtocol, ok := connStrMap["DefaultEndpointsProtocol"] if !ok { @@ -96,31 +97,5 @@ func parseConnectionString(connStr string) (string, *azcore.Credential, error) { return "", nil, err } - // primary, okPrimary := pairsMap["tableendpoint"] - // secondary, okSecondary := pairsMap["tablesecondaryendpoint"] - // if !okPrimary { - // if okSecondary { - // return serviceURL, cred, errors.New("Connection string specifies only secondary connection") - // } - // if endpointsProtocol, ok := pairsMap["defaultendpointsprotocol"]; ok { - // if accountName, ok := pairsMap["accountname"]; ok { - // if endpointSuffix, ok := pairsMap["endpointsuffix"]; ok { - // primary = fmt.Sprintf("%v://%v.table.%v", endpointsProtocol, accountName, endpointSuffix) - // secondary = fmt.Sprintf("%v-secondary.table.%v", accountName, endpointSuffix) - // okPrimary = true - // okSecondary = true - // } - // } - // } - // } - - // if !okPrimary { - - // } - - // if serviceURL, ok = pairsMap["tableendpoint"]; !ok { - // return serviceURL, cred, errors.New("Connection string does not specify") - // } - return serviceURL, &cred, nil } From c7da82f1ac6396367a7520a47204895752aa5a6a Mon Sep 17 00:00:00 2001 From: Sean Kane <68240067+seankane-msft@users.noreply.github.com> Date: Thu, 29 Jul 2021 13:48:45 -0400 Subject: [PATCH 06/39] Update sdk/tables/aztable/connection_string.go Co-authored-by: Richard Park <51494936+richardpark-msft@users.noreply.github.com> --- sdk/tables/aztable/connection_string.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index c1e12704f4f6..b86065a88f5b 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -21,7 +21,7 @@ func NewTableClientFromConnectionString(tableName string, connectionString strin return NewTableClient(tableName, endpoint, *credential, options) } -func NewTableServiceClientFrommConnectionString(connectionString string, options *TableClientOptions) (*TableServiceClient, error) { +func NewTableServiceClientFromConnectionString(connectionString string, options *TableClientOptions) (*TableServiceClient, error) { endpoint, credential, err := parseConnectionString(connectionString) if err != nil { return nil, err From 4621f6c240d00c27da5b44f0ef9bb94d270fbe59 Mon Sep 17 00:00:00 2001 From: Sean Kane <68240067+seankane-msft@users.noreply.github.com> Date: Thu, 29 Jul 2021 13:53:09 -0400 Subject: [PATCH 07/39] Update sdk/tables/aztable/connection_string.go Co-authored-by: Richard Park <51494936+richardpark-msft@users.noreply.github.com> --- sdk/tables/aztable/connection_string.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index b86065a88f5b..6336f6282f51 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -71,7 +71,7 @@ func parseConnectionString(connStr string) (string, *azcore.Credential, error) { if !ok { return serviceURL, nil, ErrConnectionString } - return sharedAccessSignature, nil, errors.New("there is not support for SharedAccessSignature yet") + return sharedAccessSignature, nil, errors.New("a SharedAccessSignature are not supported") // cred = azcore.SharedAccessSignature(sharedAccessSignature) // TODO: fix this when shared access signatures are added. } From 3842a4d9975648a4d050f19348cfcf432075f618 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 11 Aug 2021 15:34:28 -0400 Subject: [PATCH 08/39] improving testing --- sdk/tables/aztable/connection_string.go | 40 +++++--- sdk/tables/aztable/connection_string_test.go | 97 +++++++++++++++----- 2 files changed, 98 insertions(+), 39 deletions(-) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index 6336f6282f51..d39d07a7e850 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -13,20 +13,27 @@ import ( var ErrConnectionString = errors.New("connection string is either blank or malformed") +// NewTableClientFromConnectionString creates a new TableClient struct from a connection string. The connection +// string must contain either an account name and account key or an account name and a shared access signature. func NewTableClientFromConnectionString(tableName string, connectionString string, options *TableClientOptions) (*TableClient, error) { + if options == nil { + options = &TableClientOptions{} + } endpoint, credential, err := parseConnectionString(connectionString) if err != nil { return nil, err } - return NewTableClient(tableName, endpoint, *credential, options) + return NewTableClient(tableName, endpoint, credential, options) } +// NewTableServiceClientFromConnectionString creates a new TableServiceClient struct from a connection string. The connection +// string must contain either an account name and account key or an account name and a shared access signature. func NewTableServiceClientFromConnectionString(connectionString string, options *TableClientOptions) (*TableServiceClient, error) { endpoint, credential, err := parseConnectionString(connectionString) if err != nil { return nil, err } - return NewTableServiceClient(endpoint, *credential, options) + return NewTableServiceClient(endpoint, credential, options) } func convertConnStrToMap(connStr string) (map[string]string, error) { @@ -47,10 +54,15 @@ func convertConnStrToMap(connStr string) (map[string]string, error) { return ret, nil } -func parseConnectionString(connStr string) (string, *azcore.Credential, error) { +// parseConnectionString parses a connection string into a service URL and a SharedKeyCredential or a service url with the +// SharedAccessSignature combined. +func parseConnectionString(connStr string) (string, azcore.Credential, error) { var serviceURL string var cred azcore.Credential + defaultScheme := "https" + defaultSuffix := "core.windows.net" + connStrMap, err := convertConnStrToMap(connStr) if err != nil { return "", nil, err @@ -67,35 +79,33 @@ func parseConnectionString(connStr string) (string, *azcore.Credential, error) { if accountName == "" || accountKey == "" { // Try sharedaccesssignature - sharedAccessSignature, ok := connStrMap["sharedaccesssignature"] + sharedAccessSignature, ok := connStrMap["SharedAccessSignature"] if !ok { - return serviceURL, nil, ErrConnectionString + return "", nil, ErrConnectionString } - return sharedAccessSignature, nil, errors.New("a SharedAccessSignature are not supported") - // cred = azcore.SharedAccessSignature(sharedAccessSignature) - // TODO: fix this when shared access signatures are added. + return fmt.Sprintf("%v://%v.table.%v/?%v", defaultScheme, accountName, defaultSuffix, sharedAccessSignature), nil, nil } - defaultProtocol, ok := connStrMap["DefaultEndpointsProtocol"] + protocol, ok := connStrMap["DefaultEndpointsProtocol"] if !ok { - defaultProtocol = "https" + protocol = defaultScheme } - endpointSuffix, ok := connStrMap["EndpointSuffix"] + suffix, ok := connStrMap["EndpointSuffix"] if !ok { - endpointSuffix = "core.windows.net" + suffix = defaultSuffix } tableEndpoint, ok := connStrMap["TableEndpoint"] if ok { cred, err = NewSharedKeyCredential(accountName, accountKey) - return tableEndpoint, &cred, err + return tableEndpoint, cred, err } - serviceURL = fmt.Sprintf("%v://%v.table.%v", defaultProtocol, accountName, endpointSuffix) + serviceURL = fmt.Sprintf("%v://%v.table.%v", protocol, accountName, suffix) cred, err = NewSharedKeyCredential(accountName, accountKey) if err != nil { return "", nil, err } - return serviceURL, &cred, nil + return serviceURL, cred, nil } diff --git a/sdk/tables/aztable/connection_string_test.go b/sdk/tables/aztable/connection_string_test.go index 78065ad16612..3b6485629ab9 100644 --- a/sdk/tables/aztable/connection_string_test.go +++ b/sdk/tables/aztable/connection_string_test.go @@ -4,49 +4,99 @@ package aztable import ( + "encoding/base64" + "strings" "testing" "github.com/stretchr/testify/require" ) -func TestConnectionStringParser(t *testing.T) { - require := require.New(t) +func getAccountKey(cred *SharedKeyCredential) string { + return base64.StdEncoding.EncodeToString(cred.accountKey.Load().([]byte)) +} +func TestConnectionStringParser(t *testing.T) { connStr := "DefaultEndpointsProtocol=https;AccountName=dummyaccount;AccountKey=secretkeykey;EndpointSuffix=core.windows.net" serviceURL, cred, err := parseConnectionString(connStr) - require.NoError(err) - require.Equal(serviceURL, "https://dummyaccount.table.core.windows.net") - require.NotNil(cred) + require.NoError(t, err) + require.Equal(t, serviceURL, "https://dummyaccount.table.core.windows.net") + require.NotNil(t, cred) + + sharedKeyCred, ok := cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKeyCred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(sharedKeyCred), "secretkeykey") + + client, err := NewTableClientFromConnectionString("tableName", connStr, nil) + require.NoError(t, err) + require.NotNil(t, client) + require.Equal(t, client.cred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(&client.cred), "secretkeykey") + require.True(t, strings.HasPrefix(client.client.con.u, "https://")) + require.True(t, strings.Contains(client.client.con.u, "core.windows.net")) } func TestConnectionStringParserHTTP(t *testing.T) { - require := require.New(t) - connStr := "DefaultEndpointsProtocol=http;AccountName=dummyaccount;AccountKey=secretkeykey;EndpointSuffix=core.windows.net" serviceURL, cred, err := parseConnectionString(connStr) - require.NoError(err) - require.Equal(serviceURL, "http://dummyaccount.table.core.windows.net") - require.NotNil(cred) + require.NoError(t, err) + require.Equal(t, serviceURL, "http://dummyaccount.table.core.windows.net") + require.NotNil(t, cred) + + sharedKeyCred, ok := cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKeyCred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(sharedKeyCred), "secretkeykey") + + client, err := NewTableClientFromConnectionString("tableName", connStr, nil) + require.NoError(t, err) + require.NotNil(t, client) + require.Equal(t, client.cred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(&client.cred), "secretkeykey") + require.True(t, strings.HasPrefix(client.client.con.u, "http://")) + require.True(t, strings.Contains(client.client.con.u, "core.windows.net")) } func TestConnectionStringParserBasic(t *testing.T) { - require := require.New(t) - connStr := "AccountName=dummyaccount;AccountKey=secretkeykey" serviceURL, cred, err := parseConnectionString(connStr) - require.NoError(err) - require.Equal(serviceURL, "https://dummyaccount.table.core.windows.net") - require.NotNil(cred) + require.NoError(t, err) + require.Equal(t, serviceURL, "https://dummyaccount.table.core.windows.net") + require.NotNil(t, cred) + + sharedKeyCred, ok := cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKeyCred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(sharedKeyCred), "secretkeykey") + + client, err := NewTableClientFromConnectionString("tableName", connStr, nil) + require.NoError(t, err) + require.NotNil(t, client) + require.Equal(t, client.cred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(&client.cred), "secretkeykey") + require.True(t, strings.HasPrefix(client.client.con.u, "https://")) + require.True(t, strings.Contains(client.client.con.u, "core.windows.net")) } func TestConnectionStringParserCustomDomain(t *testing.T) { - require := require.New(t) - connStr := "AccountName=dummyaccount;AccountKey=secretkeykey;TableEndpoint=www.mydomain.com;" serviceURL, cred, err := parseConnectionString(connStr) - require.NoError(err) - require.Equal(serviceURL, "www.mydomain.com") - require.NotNil(cred) + require.NoError(t, err) + require.Equal(t, serviceURL, "www.mydomain.com") + require.NotNil(t, cred) + + sharedKeyCred, ok := cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKeyCred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(sharedKeyCred), "secretkeykey") + + client, err := NewTableClientFromConnectionString("tableName", connStr, nil) + require.NoError(t, err) + require.NotNil(t, client) + require.Equal(t, client.cred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(&client.cred), "secretkeykey") + require.True(t, strings.HasPrefix(client.client.con.u, "www.")) + require.True(t, strings.Contains(client.client.con.u, "mydomain.com")) } func TestConnectionStringParserInvalid(t *testing.T) { @@ -58,13 +108,12 @@ func TestConnectionStringParserInvalid(t *testing.T) { "=", ";", "=;==", - "foobar=baz=foo" + "foobar=baz=foo", } - require := require.New(t) for _, badConnStr := range badConnectionStrings { _, _, err := parseConnectionString(badConnStr) - require.Error(err) - require.Contains(err.Error(), ErrConnectionString.Error()) + require.Error(t, err) + require.Contains(t, err.Error(), ErrConnectionString.Error()) } } From 20ef73468b06cf36199b0b943d5884bcae92fb9b Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 11 Aug 2021 16:06:57 -0400 Subject: [PATCH 09/39] finishing connection string portion --- sdk/tables/aztable/connection_string.go | 14 ++- sdk/tables/aztable/connection_string_test.go | 96 ++++++++++++++++++-- sdk/tables/aztable/table_client.go | 5 +- sdk/tables/aztable/table_service_client.go | 7 +- 4 files changed, 108 insertions(+), 14 deletions(-) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index d39d07a7e850..d2087bd6dfbb 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -23,6 +23,9 @@ func NewTableClientFromConnectionString(tableName string, connectionString strin if err != nil { return nil, err } + if credential == nil { + return NewTableClient(tableName, endpoint, azcore.AnonymousCredential(), nil) + } return NewTableClient(tableName, endpoint, credential, options) } @@ -33,6 +36,9 @@ func NewTableServiceClientFromConnectionString(connectionString string, options if err != nil { return nil, err } + if credential == nil { + return NewTableServiceClient(endpoint, azcore.AnonymousCredential(), nil) + } return NewTableServiceClient(endpoint, credential, options) } @@ -74,17 +80,19 @@ func parseConnectionString(connStr string) (string, azcore.Credential, error) { } accountKey, ok := connStrMap["AccountKey"] if !ok { - return "", nil, ErrConnectionString - } - if accountName == "" || accountKey == "" { + // if accountName == "" || accountKey == "" { // Try sharedaccesssignature sharedAccessSignature, ok := connStrMap["SharedAccessSignature"] if !ok { return "", nil, ErrConnectionString } return fmt.Sprintf("%v://%v.table.%v/?%v", defaultScheme, accountName, defaultSuffix, sharedAccessSignature), nil, nil + // } + + // return "", nil, ErrConnectionString } + protocol, ok := connStrMap["DefaultEndpointsProtocol"] if !ok { protocol = defaultScheme diff --git a/sdk/tables/aztable/connection_string_test.go b/sdk/tables/aztable/connection_string_test.go index 3b6485629ab9..879246f74000 100644 --- a/sdk/tables/aztable/connection_string_test.go +++ b/sdk/tables/aztable/connection_string_test.go @@ -30,8 +30,10 @@ func TestConnectionStringParser(t *testing.T) { client, err := NewTableClientFromConnectionString("tableName", connStr, nil) require.NoError(t, err) require.NotNil(t, client) - require.Equal(t, client.cred.accountName, "dummyaccount") - require.Equal(t, getAccountKey(&client.cred), "secretkeykey") + sharedKeyCred, ok = client.cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKeyCred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(sharedKeyCred), "secretkeykey") require.True(t, strings.HasPrefix(client.client.con.u, "https://")) require.True(t, strings.Contains(client.client.con.u, "core.windows.net")) } @@ -51,8 +53,10 @@ func TestConnectionStringParserHTTP(t *testing.T) { client, err := NewTableClientFromConnectionString("tableName", connStr, nil) require.NoError(t, err) require.NotNil(t, client) - require.Equal(t, client.cred.accountName, "dummyaccount") - require.Equal(t, getAccountKey(&client.cred), "secretkeykey") + sharedKeyCred, ok = client.cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKeyCred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(sharedKeyCred), "secretkeykey") require.True(t, strings.HasPrefix(client.client.con.u, "http://")) require.True(t, strings.Contains(client.client.con.u, "core.windows.net")) } @@ -72,8 +76,10 @@ func TestConnectionStringParserBasic(t *testing.T) { client, err := NewTableClientFromConnectionString("tableName", connStr, nil) require.NoError(t, err) require.NotNil(t, client) - require.Equal(t, client.cred.accountName, "dummyaccount") - require.Equal(t, getAccountKey(&client.cred), "secretkeykey") + sharedKeyCred, ok = client.cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKeyCred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(sharedKeyCred), "secretkeykey") require.True(t, strings.HasPrefix(client.client.con.u, "https://")) require.True(t, strings.Contains(client.client.con.u, "core.windows.net")) } @@ -93,8 +99,10 @@ func TestConnectionStringParserCustomDomain(t *testing.T) { client, err := NewTableClientFromConnectionString("tableName", connStr, nil) require.NoError(t, err) require.NotNil(t, client) - require.Equal(t, client.cred.accountName, "dummyaccount") - require.Equal(t, getAccountKey(&client.cred), "secretkeykey") + sharedKeyCred, ok = client.cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKeyCred.accountName, "dummyaccount") + require.Equal(t, getAccountKey(sharedKeyCred), "secretkeykey") require.True(t, strings.HasPrefix(client.client.con.u, "www.")) require.True(t, strings.Contains(client.client.con.u, "mydomain.com")) } @@ -117,3 +125,75 @@ func TestConnectionStringParserInvalid(t *testing.T) { require.Contains(t, err.Error(), ErrConnectionString.Error()) } } + +func TestConnectionStringSAS(t *testing.T) { + connStr := "AccountName=dummyaccount;SharedAccessSignature=fakesharedaccesssignature;" + serviceURL, cred, err := parseConnectionString(connStr) + require.NoError(t, err) + require.Equal(t, serviceURL, "https://dummyaccount.table.core.windows.net/?fakesharedaccesssignature") + require.Nil(t, cred) + + client, err := NewTableClientFromConnectionString("tableName", connStr, nil) + require.NoError(t, err) + require.NotNil(t, client) + require.True(t, strings.HasPrefix(client.client.con.u, "https://")) + require.True(t, strings.Contains(client.client.con.u, "core.windows.net")) +} + +func TestConnectionStringCosmos(t *testing.T) { + connStr := "DefaultEndpointsProtocol=https;AccountName=dummyaccountname;AccountKey=secretkeykey;TableEndpoint=https://dummyaccountname.table.cosmos.azure.com:443/;" + serviceURL, cred, err := parseConnectionString(connStr) + require.NoError(t, err) + require.Equal(t, serviceURL, "https://dummyaccountname.table.cosmos.azure.com:443/") + require.NotNil(t, cred) + + client, err := NewTableClientFromConnectionString("tableName", connStr, nil) + require.NoError(t, err) + require.NotNil(t, client) + require.True(t, strings.HasPrefix(client.client.con.u, "https://")) + require.True(t, strings.Contains(client.client.con.u, "cosmos.azure.com:443")) + + sharedKey, ok := client.cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKey.accountName, "dummyaccountname") + require.Equal(t, getAccountKey(sharedKey), "secretkeykey") +} + + +func TestConnectionStringChinaCloud(t *testing.T) { + connStr := "AccountName=dummyaccountname;AccountKey=secretkeykey;DefaultEndpointsProtocol=http;EndpointSuffix=core.chinacloudapi.cn;" + serviceURL, cred, err := parseConnectionString(connStr) + require.NoError(t, err) + require.Equal(t, serviceURL, "http://dummyaccountname.table.core.chinacloudapi.cn") + require.NotNil(t, cred) + + client, err := NewTableClientFromConnectionString("tableName", connStr, nil) + require.NoError(t, err) + require.NotNil(t, client) + require.True(t, strings.HasPrefix(client.client.con.u, "http://")) + require.True(t, strings.Contains(client.client.con.u, "core.chinacloudapi.cn")) + + sharedKey, ok := client.cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKey.accountName, "dummyaccountname") + require.Equal(t, getAccountKey(sharedKey), "secretkeykey") +} + +func TestConnectionStringAzurite(t *testing.T) { + connStr := "DefaultEndpointsProtocol=http;AccountName=dummyaccountname;AccountKey=secretkeykey;TableEndpoint=http://local-machine:11002/custom/account/path/faketokensignature;" + serviceURL, cred, err := parseConnectionString(connStr) + require.NoError(t, err) + require.Equal(t, serviceURL, "http://local-machine:11002/custom/account/path/faketokensignature") + require.NotNil(t, cred) + + client, err := NewTableClientFromConnectionString("tableName", connStr, nil) + require.NoError(t, err) + require.NotNil(t, client) + require.True(t, strings.HasPrefix(client.client.con.u, "http://")) + require.True(t, strings.Contains(client.client.con.u, "http://local-machine:11002/custom/account/path/faketokensignature")) + + sharedKey, ok := client.cred.(*SharedKeyCredential) + require.True(t, ok) + require.Equal(t, sharedKey.accountName, "dummyaccountname") + require.Equal(t, getAccountKey(sharedKey), "secretkeykey") +} diff --git a/sdk/tables/aztable/table_client.go b/sdk/tables/aztable/table_client.go index ec4c6ab7af10..7f697f732dcd 100644 --- a/sdk/tables/aztable/table_client.go +++ b/sdk/tables/aztable/table_client.go @@ -15,7 +15,7 @@ import ( type TableClient struct { client *tableClient service *TableServiceClient - cred SharedKeyCredential + cred azcore.Credential Name string } @@ -28,6 +28,9 @@ const ( // NewTableClient creates a TableClient struct in the context of the table specified in tableName, using the specified serviceURL, credential, and options. func NewTableClient(tableName string, serviceURL string, cred azcore.Credential, options *TableClientOptions) (*TableClient, error) { + if options == nil { + options = &TableClientOptions{} + } s, err := NewTableServiceClient(serviceURL, cred, options) return s.NewTableClient(tableName), err } diff --git a/sdk/tables/aztable/table_service_client.go b/sdk/tables/aztable/table_service_client.go index 78d2f4453c96..03e53a18f462 100644 --- a/sdk/tables/aztable/table_service_client.go +++ b/sdk/tables/aztable/table_service_client.go @@ -19,11 +19,14 @@ const ( type TableServiceClient struct { client *tableClient service *serviceClient - cred SharedKeyCredential + cred azcore.Credential } // NewTableServiceClient creates a TableServiceClient struct using the specified serviceURL, credential, and options. func NewTableServiceClient(serviceURL string, cred azcore.Credential, options *TableClientOptions) (*TableServiceClient, error) { + if options == nil { + options = &TableClientOptions{} + } conOptions := options.getConnectionOptions() if isCosmosEndpoint(serviceURL) { conOptions.PerCallPolicies = []azcore.Policy{CosmosPatchTransformPolicy{}} @@ -31,7 +34,7 @@ func NewTableServiceClient(serviceURL string, cred azcore.Credential, options *T conOptions.PerCallPolicies = append(conOptions.PerCallPolicies, cred.AuthenticationPolicy(azcore.AuthenticationPolicyOptions{Options: azcore.TokenRequestOptions{Scopes: []string{"none"}}})) con := newConnection(serviceURL, conOptions) c, _ := cred.(*SharedKeyCredential) - return &TableServiceClient{client: &tableClient{con}, service: &serviceClient{con}, cred: *c}, nil + return &TableServiceClient{client: &tableClient{con}, service: &serviceClient{con}, cred: c}, nil } // NewTableClient returns a pointer to a TableClient affinitzed to the specified table name and initialized with the same serviceURL and credentials as this TableServiceClient From 0d288059cde30e390d56172a20a625b3ba88d005 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 11 Aug 2021 16:21:45 -0400 Subject: [PATCH 10/39] formatting and improved error handling --- sdk/tables/aztable/connection_string.go | 2 +- sdk/tables/aztable/connection_string_test.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index d2087bd6dfbb..3e14d3835c2c 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -11,7 +11,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore" ) -var ErrConnectionString = errors.New("connection string is either blank or malformed") +var ErrConnectionString = errors.New("connection string is either blank or malformed. The expected connection string should contain key value pairs separated by semicolons. For example 'DefaultEndpointsProtocol=https;AccountName=;AccountKey=;EndpointSuffix=core.windows.net'") // NewTableClientFromConnectionString creates a new TableClient struct from a connection string. The connection // string must contain either an account name and account key or an account name and a shared access signature. diff --git a/sdk/tables/aztable/connection_string_test.go b/sdk/tables/aztable/connection_string_test.go index 879246f74000..3fa0ef77fc9f 100644 --- a/sdk/tables/aztable/connection_string_test.go +++ b/sdk/tables/aztable/connection_string_test.go @@ -159,7 +159,6 @@ func TestConnectionStringCosmos(t *testing.T) { require.Equal(t, getAccountKey(sharedKey), "secretkeykey") } - func TestConnectionStringChinaCloud(t *testing.T) { connStr := "AccountName=dummyaccountname;AccountKey=secretkeykey;DefaultEndpointsProtocol=http;EndpointSuffix=core.chinacloudapi.cn;" serviceURL, cred, err := parseConnectionString(connStr) @@ -179,7 +178,7 @@ func TestConnectionStringChinaCloud(t *testing.T) { require.Equal(t, getAccountKey(sharedKey), "secretkeykey") } -func TestConnectionStringAzurite(t *testing.T) { +func TestConnectionStringAzurite(t *testing.T) { connStr := "DefaultEndpointsProtocol=http;AccountName=dummyaccountname;AccountKey=secretkeykey;TableEndpoint=http://local-machine:11002/custom/account/path/faketokensignature;" serviceURL, cred, err := parseConnectionString(connStr) require.NoError(t, err) From fdac8d694e7c924cbaaa262175ef34ce413c28ce Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 11 Aug 2021 16:23:12 -0400 Subject: [PATCH 11/39] docstring addition for private method --- sdk/tables/aztable/connection_string.go | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index 3e14d3835c2c..3e37df8cd2c0 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -42,6 +42,7 @@ func NewTableServiceClientFromConnectionString(connectionString string, options return NewTableServiceClient(endpoint, credential, options) } +// convertConnStrToMap converts a connection string (in format key1=value1;key2=value2;key3=value3;) into a map of key-value pairs func convertConnStrToMap(connStr string) (map[string]string, error) { ret := make(map[string]string) connStr = strings.TrimRight(connStr, ";") From 044733c32b9c46dd8d9f90360c77b4327c2b2425 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Thu, 12 Aug 2021 16:53:57 -0400 Subject: [PATCH 12/39] connection string error --- sdk/tables/aztable/connection_string.go | 13 +++++-------- sdk/tables/aztable/connection_string_test.go | 2 +- sdk/tables/aztable/errors.go | 4 ++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index 3e37df8cd2c0..124511be2a10 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -4,15 +4,12 @@ package aztable import ( - "errors" "fmt" "strings" "github.com/Azure/azure-sdk-for-go/sdk/azcore" ) -var ErrConnectionString = errors.New("connection string is either blank or malformed. The expected connection string should contain key value pairs separated by semicolons. For example 'DefaultEndpointsProtocol=https;AccountName=;AccountKey=;EndpointSuffix=core.windows.net'") - // NewTableClientFromConnectionString creates a new TableClient struct from a connection string. The connection // string must contain either an account name and account key or an account name and a shared access signature. func NewTableClientFromConnectionString(tableName string, connectionString string, options *TableClientOptions) (*TableClient, error) { @@ -49,12 +46,12 @@ func convertConnStrToMap(connStr string) (map[string]string, error) { splitString := strings.Split(connStr, ";") if len(splitString) == 0 { - return ret, ErrConnectionString + return ret, errConnectionString } for _, stringPart := range splitString { parts := strings.Split(stringPart, "=") if len(parts) != 2 { - return ret, ErrConnectionString + return ret, errConnectionString } ret[parts[0]] = parts[1] } @@ -77,7 +74,7 @@ func parseConnectionString(connStr string) (string, azcore.Credential, error) { accountName, ok := connStrMap["AccountName"] if !ok { - return "", nil, ErrConnectionString + return "", nil, errConnectionString } accountKey, ok := connStrMap["AccountKey"] if !ok { @@ -86,12 +83,12 @@ func parseConnectionString(connStr string) (string, azcore.Credential, error) { // Try sharedaccesssignature sharedAccessSignature, ok := connStrMap["SharedAccessSignature"] if !ok { - return "", nil, ErrConnectionString + return "", nil, errConnectionString } return fmt.Sprintf("%v://%v.table.%v/?%v", defaultScheme, accountName, defaultSuffix, sharedAccessSignature), nil, nil // } - // return "", nil, ErrConnectionString + // return "", nil, errConnectionString } protocol, ok := connStrMap["DefaultEndpointsProtocol"] diff --git a/sdk/tables/aztable/connection_string_test.go b/sdk/tables/aztable/connection_string_test.go index 3fa0ef77fc9f..93937e0d3fb6 100644 --- a/sdk/tables/aztable/connection_string_test.go +++ b/sdk/tables/aztable/connection_string_test.go @@ -122,7 +122,7 @@ func TestConnectionStringParserInvalid(t *testing.T) { for _, badConnStr := range badConnectionStrings { _, _, err := parseConnectionString(badConnStr) require.Error(t, err) - require.Contains(t, err.Error(), ErrConnectionString.Error()) + require.Contains(t, err.Error(), errConnectionString.Error()) } } diff --git a/sdk/tables/aztable/errors.go b/sdk/tables/aztable/errors.go index 17aeabca6d8f..d948fb59f962 100644 --- a/sdk/tables/aztable/errors.go +++ b/sdk/tables/aztable/errors.go @@ -3,6 +3,10 @@ package aztable +import "errors" + +var errConnectionString = errors.New("connection string is either blank or malformed. The expected connection string should contain key value pairs separated by semicolons. For example 'DefaultEndpointsProtocol=https;AccountName=;AccountKey=;EndpointSuffix=core.windows.net'") + func checkEntityForPkRk(entity *map[string]interface{}, err error) error { if _, ok := (*entity)[partitionKey]; !ok { return partitionKeyRowKeyError From 99de9b08d8ab2fc111d16a42d4cdc6d9f557c413 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Tue, 17 Aug 2021 15:17:38 -0400 Subject: [PATCH 13/39] splitn instead of split --- sdk/tables/aztable/connection_string.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index 124511be2a10..fcb03cf6950f 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -49,7 +49,7 @@ func convertConnStrToMap(connStr string) (map[string]string, error) { return ret, errConnectionString } for _, stringPart := range splitString { - parts := strings.Split(stringPart, "=") + parts := strings.SplitN(stringPart, "=", 2) if len(parts) != 2 { return ret, errConnectionString } From f28e3f6bbd5e9d08f09eeea162fc681427f3af5a Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Tue, 17 Aug 2021 15:18:48 -0400 Subject: [PATCH 14/39] sas comment --- sdk/tables/aztable/connection_string.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index fcb03cf6950f..b595df34c65c 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -80,7 +80,7 @@ func parseConnectionString(connStr string) (string, azcore.Credential, error) { if !ok { // if accountName == "" || accountKey == "" { - // Try sharedaccesssignature + // Try SharedAccessSignature sharedAccessSignature, ok := connStrMap["SharedAccessSignature"] if !ok { return "", nil, errConnectionString From 3f4cc579761f06d5783858626bec5c9479da0f9b Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 11:32:24 -0400 Subject: [PATCH 15/39] updating proxy-server script --- eng/scripts/proxy-server.ps1 | 51 ++++++++++++++++--------- sdk/tables/aztable/connection_string.go | 14 +------ 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/eng/scripts/proxy-server.ps1 b/eng/scripts/proxy-server.ps1 index 75f0b376712f..5432630e97ed 100644 --- a/eng/scripts/proxy-server.ps1 +++ b/eng/scripts/proxy-server.ps1 @@ -1,9 +1,20 @@ + #!/usr/bin/env pwsh -c + +<# +.DESCRIPTION +Start the docker proxy container. If it is already running, quietly exit. Any other error should fail. +.PARAMETER Mode +"start" or "stop" to start up or stop the test-proxy instance. +.PARAMETER TargetFolder +The folder in which context the test proxy will be started. Defaults to current working directory. +#> +[CmdletBinding(SupportsShouldProcess = $true)] param( [ValidateSet("start", "stop")] [String] - $mode, + $Mode, [String] - $targetFolder = "." + $TargetFolder = "." ) try { @@ -14,17 +25,11 @@ catch { Write-Error "Please check your docker invocation and try running the script again." } -$repoRoot = (Resolve-Path $targetFolder).Path.Replace("`\", "/") -Write-Host $repoRoot - +$SELECTED_IMAGE_TAG = "1037115" $CONTAINER_NAME = "ambitious_azsdk_test_proxy" -$IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-lin:1037115" -$Initial = "" - -if ($IsWindows -and $env:TF_BUILD){ - $IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-win:1037115" - $Initial = "C:" -} +$LINUX_IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-lin:${SELECTED_IMAGE_TAG}" +$WINDOWS_IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-win:${SELECTED_IMAGE_TAG}" +$root = (Resolve-Path $TargetFolder).Path.Replace("`\", "/") function Get-Proxy-Container(){ return (docker container ls -a --format "{{ json . }}" --filter "name=$CONTAINER_NAME" ` @@ -32,7 +37,19 @@ function Get-Proxy-Container(){ | Select-Object -First 1) } -if ($mode -eq "start"){ + +$SelectedImage = $LINUX_IMAGE_SOURCE +$Initial = "" + +# most of the time, running this script on a windows machine will work just fine, as docker defaults to linux containers +# however, in CI, windows images default to _windows_ containers. We cannot swap them. We can tell if we're in a CI build by +# checking for the environment variable TF_BUILD. +if ($IsWindows -and $env:TF_BUILD){ + $SelectedImage = $WINDOWS_IMAGE_SOURCE + $Initial = "C:" +} + +if ($Mode -eq "start"){ $proxyContainer = Get-Proxy-Container # if we already have one, we just need to check the state @@ -46,15 +63,15 @@ if ($mode -eq "start"){ # else we need to create it else { Write-Host "Attempting creation of Docker host $CONTAINER_NAME" - Write-Host "docker container create -v `"${repoRoot}:${Initial}/etc/testproxy`" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $IMAGE_SOURCE" - docker container create -v "${repoRoot}:${Initial}/etc/testproxy" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $IMAGE_SOURCE + Write-Host "docker container create -v `"${root}:${Initial}/etc/testproxy`" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage" + docker container create -v "${root}:${Initial}/etc/testproxy" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage } Write-Host "Attempting start of Docker host $CONTAINER_NAME" docker container start $CONTAINER_NAME } -if ($mode -eq "stop"){ +if ($Mode -eq "stop"){ $proxyContainer = Get-Proxy-Container if($proxyContainer){ @@ -63,4 +80,4 @@ if ($mode -eq "stop"){ docker container stop $CONTAINER_NAME } } -} +} \ No newline at end of file diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index b595df34c65c..ecdd26d81433 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -20,9 +20,6 @@ func NewTableClientFromConnectionString(tableName string, connectionString strin if err != nil { return nil, err } - if credential == nil { - return NewTableClient(tableName, endpoint, azcore.AnonymousCredential(), nil) - } return NewTableClient(tableName, endpoint, credential, options) } @@ -33,9 +30,6 @@ func NewTableServiceClientFromConnectionString(connectionString string, options if err != nil { return nil, err } - if credential == nil { - return NewTableServiceClient(endpoint, azcore.AnonymousCredential(), nil) - } return NewTableServiceClient(endpoint, credential, options) } @@ -78,17 +72,11 @@ func parseConnectionString(connStr string) (string, azcore.Credential, error) { } accountKey, ok := connStrMap["AccountKey"] if !ok { - - // if accountName == "" || accountKey == "" { - // Try SharedAccessSignature sharedAccessSignature, ok := connStrMap["SharedAccessSignature"] if !ok { return "", nil, errConnectionString } - return fmt.Sprintf("%v://%v.table.%v/?%v", defaultScheme, accountName, defaultSuffix, sharedAccessSignature), nil, nil - // } - - // return "", nil, errConnectionString + return fmt.Sprintf("%v://%v.table.%v/?%v", defaultScheme, accountName, defaultSuffix, sharedAccessSignature), azcore.AnonymousCredential(), nil } protocol, ok := connStrMap["DefaultEndpointsProtocol"] From 2a3d5e5ee3a1de313b640455cb9b3e9393070e17 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 11:42:01 -0400 Subject: [PATCH 16/39] configure proxy with hash of file, correct file location --- eng/pipelines/templates/steps/configure-proxy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/templates/steps/configure-proxy.yml b/eng/pipelines/templates/steps/configure-proxy.yml index c7308e930c69..e4eaadd5db02 100644 --- a/eng/pipelines/templates/steps/configure-proxy.yml +++ b/eng/pipelines/templates/steps/configure-proxy.yml @@ -3,8 +3,8 @@ parameters: steps: - pwsh: | - $certUriPfx = "https://github.com/Azure/azure-sdk-tools/raw/main/tools/test-proxy/docker/dev_certificate/dotnet-devcert.pfx" - $certUriCrt = "https://github.com/Azure/azure-sdk-tools/raw/main/tools/test-proxy/docker/dev_certificate/dotnet-devcert.crt" + $certUriPfx = "https://github.com/Azure/azure-sdk-tools/blob/c0d142ae047f0d561a31f9989c63896cc5ffc70e/eng/common/testproxy/dotnet-devcert.pfx" + $certUriCrt = "https://github.com/Azure/azure-sdk-tools/blob/c0d142ae047f0d561a31f9989c63896cc5ffc70e/eng/common/testproxy/dotnet-devcert.crt" $certLocationPfx = "$(Build.SourcesDirectory)/dotnet-devcert.pfx" $certLocationCrt = "$(Build.SourcesDirectory)/dotnet-devcert.crt" From 48204fcc39ad13dca3ceb9eb8db48440d1063e08 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 11:48:33 -0400 Subject: [PATCH 17/39] using certs in main --- eng/pipelines/templates/steps/configure-proxy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/templates/steps/configure-proxy.yml b/eng/pipelines/templates/steps/configure-proxy.yml index e4eaadd5db02..d1e233e63f03 100644 --- a/eng/pipelines/templates/steps/configure-proxy.yml +++ b/eng/pipelines/templates/steps/configure-proxy.yml @@ -3,8 +3,8 @@ parameters: steps: - pwsh: | - $certUriPfx = "https://github.com/Azure/azure-sdk-tools/blob/c0d142ae047f0d561a31f9989c63896cc5ffc70e/eng/common/testproxy/dotnet-devcert.pfx" - $certUriCrt = "https://github.com/Azure/azure-sdk-tools/blob/c0d142ae047f0d561a31f9989c63896cc5ffc70e/eng/common/testproxy/dotnet-devcert.crt" + $certUriPfx = "https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/testproxy/dotnet-devcert.pfx" + $certUriCrt = "https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/testproxy/dotnet-devcert.crt" $certLocationPfx = "$(Build.SourcesDirectory)/dotnet-devcert.pfx" $certLocationCrt = "$(Build.SourcesDirectory)/dotnet-devcert.crt" From bb276fb53966311de22d6dfebc8bcf7ebea932f8 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 12:15:54 -0400 Subject: [PATCH 18/39] trying download with no password --- eng/pipelines/templates/steps/configure-proxy.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/configure-proxy.yml b/eng/pipelines/templates/steps/configure-proxy.yml index d1e233e63f03..a3029969dbb8 100644 --- a/eng/pipelines/templates/steps/configure-proxy.yml +++ b/eng/pipelines/templates/steps/configure-proxy.yml @@ -16,7 +16,9 @@ steps: -Uri $certUriCrt ` -OutFile $certLocationCrt -UseBasicParsing - dotnet dev-certs https --clean --import $certLocationPfx -p "password" + Write-Host "Successfully downloaded crt and pfx files." + + dotnet dev-certs https --clean --import $certLocationPfx # -p "password" Write-Host "##vso[task.setvariable variable=PROXY_CERT]$certLocationCrt" displayName: 'Download and Trust Certificate' From 34871e693fbf14f0b0a17243b2774dec2b36f271 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 12:22:16 -0400 Subject: [PATCH 19/39] trying without the pfx file altogether --- eng/pipelines/templates/steps/configure-proxy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/configure-proxy.yml b/eng/pipelines/templates/steps/configure-proxy.yml index a3029969dbb8..28618ec62d20 100644 --- a/eng/pipelines/templates/steps/configure-proxy.yml +++ b/eng/pipelines/templates/steps/configure-proxy.yml @@ -18,7 +18,7 @@ steps: Write-Host "Successfully downloaded crt and pfx files." - dotnet dev-certs https --clean --import $certLocationPfx # -p "password" + # dotnet dev-certs https --clean --import $certLocationPfx -p "password" Write-Host "##vso[task.setvariable variable=PROXY_CERT]$certLocationCrt" displayName: 'Download and Trust Certificate' From cc7a769c30b2273d02b8450d6f7edde084ebe797 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 12:36:32 -0400 Subject: [PATCH 20/39] adding pfx portion back --- eng/pipelines/templates/steps/configure-proxy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/configure-proxy.yml b/eng/pipelines/templates/steps/configure-proxy.yml index 28618ec62d20..6db2c10973e3 100644 --- a/eng/pipelines/templates/steps/configure-proxy.yml +++ b/eng/pipelines/templates/steps/configure-proxy.yml @@ -18,7 +18,7 @@ steps: Write-Host "Successfully downloaded crt and pfx files." - # dotnet dev-certs https --clean --import $certLocationPfx -p "password" + dotnet dev-certs https --clean --import $certLocationPfx -p "password" Write-Host "##vso[task.setvariable variable=PROXY_CERT]$certLocationCrt" displayName: 'Download and Trust Certificate' From 7357bbf5360c973e707ec09e797f347b50b920e6 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 12:50:37 -0400 Subject: [PATCH 21/39] manual copy of testproxy to common --- eng/common/testproxy/apply-dev-cert.sh | 31 ++++++++ eng/common/testproxy/docker-start-proxy.ps1 | 83 ++++++++++++++++++++ eng/common/testproxy/dotnet-devcert.crt | 20 +++++ eng/common/testproxy/dotnet-devcert.pfx | Bin 0 -> 2445 bytes eng/common/testproxy/localhost.conf | 23 ++++++ eng/common/testproxy/test-proxy-docker.yml | 15 ++++ eng/common/testproxy/test-proxy-tool.yml | 47 +++++++++++ 7 files changed, 219 insertions(+) create mode 100644 eng/common/testproxy/apply-dev-cert.sh create mode 100644 eng/common/testproxy/docker-start-proxy.ps1 create mode 100644 eng/common/testproxy/dotnet-devcert.crt create mode 100644 eng/common/testproxy/dotnet-devcert.pfx create mode 100644 eng/common/testproxy/localhost.conf create mode 100644 eng/common/testproxy/test-proxy-docker.yml create mode 100644 eng/common/testproxy/test-proxy-tool.yml diff --git a/eng/common/testproxy/apply-dev-cert.sh b/eng/common/testproxy/apply-dev-cert.sh new file mode 100644 index 000000000000..444a6c600564 --- /dev/null +++ b/eng/common/testproxy/apply-dev-cert.sh @@ -0,0 +1,31 @@ +#!/bin/bash +TMP_PATH=$CERT_FOLDER +PFXFILE=$CERT_FOLDER/dotnet-devcert.pfx +CRTFILE=$CERT_FOLDER/dotnet-devcert.crt + +NSSDB_PATHS=( + "$HOME/.pki/nssdb" + "$HOME/snap/chromium/current/.pki/nssdb" + "$HOME/snap/postman/current/.pki/nssdb" +) + +function configure_nssdb() { + echo "Configuring nssdb for $1" + certutil -d sql:$1 -D -n dotnet-devcert + certutil -d sql:$1 -A -t "CP,," -n dotnet-devcert -i $CRTFILE +} + +for NSSDB in ${NSSDB_PATHS[@]}; do + if [ -d "$NSSDB" ]; then + configure_nssdb $NSSDB + fi +done + +if [ $(id -u) -ne 0 ]; then + SUDO='sudo' +fi + +$SUDO cp $CRTFILE "/usr/local/share/ca-certificates" +$SUDO update-ca-certificates + +dotnet dev-certs https --clean --import $PFXFILE -p "password" \ No newline at end of file diff --git a/eng/common/testproxy/docker-start-proxy.ps1 b/eng/common/testproxy/docker-start-proxy.ps1 new file mode 100644 index 000000000000..5432630e97ed --- /dev/null +++ b/eng/common/testproxy/docker-start-proxy.ps1 @@ -0,0 +1,83 @@ + #!/usr/bin/env pwsh -c + +<# +.DESCRIPTION +Start the docker proxy container. If it is already running, quietly exit. Any other error should fail. +.PARAMETER Mode +"start" or "stop" to start up or stop the test-proxy instance. +.PARAMETER TargetFolder +The folder in which context the test proxy will be started. Defaults to current working directory. +#> +[CmdletBinding(SupportsShouldProcess = $true)] +param( + [ValidateSet("start", "stop")] + [String] + $Mode, + [String] + $TargetFolder = "." +) + +try { + docker --version | Out-Null +} +catch { + Write-Error "A invocation of docker --version failed. This indicates that docker is not properly installed or running." + Write-Error "Please check your docker invocation and try running the script again." +} + +$SELECTED_IMAGE_TAG = "1037115" +$CONTAINER_NAME = "ambitious_azsdk_test_proxy" +$LINUX_IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-lin:${SELECTED_IMAGE_TAG}" +$WINDOWS_IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-win:${SELECTED_IMAGE_TAG}" +$root = (Resolve-Path $TargetFolder).Path.Replace("`\", "/") + +function Get-Proxy-Container(){ + return (docker container ls -a --format "{{ json . }}" --filter "name=$CONTAINER_NAME" ` + | ConvertFrom-Json ` + | Select-Object -First 1) +} + + +$SelectedImage = $LINUX_IMAGE_SOURCE +$Initial = "" + +# most of the time, running this script on a windows machine will work just fine, as docker defaults to linux containers +# however, in CI, windows images default to _windows_ containers. We cannot swap them. We can tell if we're in a CI build by +# checking for the environment variable TF_BUILD. +if ($IsWindows -and $env:TF_BUILD){ + $SelectedImage = $WINDOWS_IMAGE_SOURCE + $Initial = "C:" +} + +if ($Mode -eq "start"){ + $proxyContainer = Get-Proxy-Container + + # if we already have one, we just need to check the state + if($proxyContainer){ + if ($proxyContainer.State -eq "running") + { + Write-Host "Discovered an already running instance of the test-proxy!. Exiting" + exit(0) + } + } + # else we need to create it + else { + Write-Host "Attempting creation of Docker host $CONTAINER_NAME" + Write-Host "docker container create -v `"${root}:${Initial}/etc/testproxy`" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage" + docker container create -v "${root}:${Initial}/etc/testproxy" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage + } + + Write-Host "Attempting start of Docker host $CONTAINER_NAME" + docker container start $CONTAINER_NAME +} + +if ($Mode -eq "stop"){ + $proxyContainer = Get-Proxy-Container + + if($proxyContainer){ + if($proxyContainer.State -eq "running"){ + Write-Host "Found a running instance of $CONTAINER_NAME, shutting it down." + docker container stop $CONTAINER_NAME + } + } +} \ No newline at end of file diff --git a/eng/common/testproxy/dotnet-devcert.crt b/eng/common/testproxy/dotnet-devcert.crt new file mode 100644 index 000000000000..bbd969092780 --- /dev/null +++ b/eng/common/testproxy/dotnet-devcert.crt @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDSDCCAjCgAwIBAgIUPMKpJ/j10eQrcQBNnkImIaOYHakwDQYJKoZIhvcNAQEL +BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIxMDgwNTAwMzU1NloXDTIyMDgw +NTAwMzU1NlowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEAxe/ZseXgOTVoF7uTjX5Leknk95jIoyGc+VlxA8BhzGOr +r4u6VNQZRCMq+svHY36tW4+u/xHNe2kvbwy2mnS8cFFLfst+94qBZVJDBxSGZ9I/ +wekErNsjFsik4UrMvcC+ZlGPh7hb3f7tSx29tn1DIkAUXVnbZ6TT5s+mYRQpZ6fW +6kR3RNfc0A1IUM7Zs9yfNEr0O2H41P2HcLKoOPtvd7GvTQm9Ofh3srKvII+sZn/J +WH7r76oRQMX904mOMdryQwZLObsqX4dXIEbafKVSecB3PBVIhv8gVtJhcZbQP1pI +mMiWd6PHv46ZhGf7+cKnYUSa8Ia2t/wetK1wd00dFwIDAQABo4GRMIGOMA8GA1Ud +EwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGmMBYGA1UdJQEB/wQMMAoGCCsGAQUF +BwMBMBcGA1UdEQEB/wQNMAuCCWxvY2FsaG9zdDA6BgorBgEEAYI3VAEBBCwMKkFT +UC5ORVQgQ29yZSBIVFRQUyBkZXZlbG9wbWVudCBjZXJ0aWZpY2F0ZTANBgkqhkiG +9w0BAQsFAAOCAQEAIj2VlBVcXGSly6KCBg6lgwFi+henWfSox77iuGAaAxDjN3jd +9lZahW4MPNLHKSrPRb4YNSLZ2jh7zdcttQrqd4qH65o1q56q5JrCmli99iIzY9Y8 +RdYyxK4Zzr31wjpsyFiWQfqJTuSFUUg9uDDj0negwEZLIGlt7nr12wflt2+QOJtD +byMeSZLbB5dPzn341DK0qfJEJMMgL0XsPEVZ3TQ6Alc9zq5wI608C/mXnz3xJE05 +UTYD8pRJJ/DyG0empvOVE8Sg93msHPquAbgqO9aqCpykgg/a8CFvI4wRdfvGEFlv +8XJKL8Y/PFsmFeO3axq3zUYKFVdc9Un4dFIaag== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/eng/common/testproxy/dotnet-devcert.pfx b/eng/common/testproxy/dotnet-devcert.pfx new file mode 100644 index 0000000000000000000000000000000000000000..28058ae4ce30e7a413e8f872d930fa2cf5c2107c GIT binary patch literal 2445 zcmY+Ec{me}AIEKGOw3W1T%&R;L(Z@fa?O=93FS=q=BQl7a-{|M|6Xqd27(0wI1w0#Ef}JdY@Ym$AHWSL zz(7zS3`GAI)K?F!Tb zfjk`X7|v1{OYWP-ZccVCBTB-xZYA4g%!tC;_FsW8vbMzZGh3`8ogVrPMR>ljPU4#- z`G@P4g@lf03(hTENs)vkx^jBoGHwj2avv-Dpe_DO>@3jk<%U$iX9rZd`=jP! zsg>})<%?TyfZg|Y*>jhF5Sk^W#Xi;Zf992<-1wem2j0S$iBLn3j~5NK^GDtfIXo`5 zEs4Sf`)CEeP0j%@`i~ke|2fh@=L=@SIJ}`Y+kWWchubBzbXCRXNLitiiMY3dmu!a( zFZPEvT^=8TlPT8*{GH8Y<-2>g>eDZprB2Z+>uP-Z?YAXY9h_{s@4_XehsU4Id_iyC zJ+N--k7cI{U3Bi+p2UKd+buQ)=Z*I*(W5Hw)&cuE;drYzBT8WE$tY9^^4o53%-qi5 z=n{`d!C!c+~BNXhVHGYMn+(JJ0#LCDfvOFPO#fMYz)uYiLDW|Co z(JGTK!;W~b1WLVc_OQ;;y-e`1>Itds$%e}1YQK|Ze#ae*l3sb6q>JipNOI#XV=WLu zsiaZOG)Y@E9Hc?8IGLp#_fdMEJxgwAltLxG(ZXfxQMhi>=<_k}P;!U4_5&K0su_n9 zQ&wnVaA_R&m2zs__fZs>G)%_NW)SfLFgowbEDRqBT^z zJMo)_(u@dc8+TU{Xdrq5=H(TjX}T`cCNE>>pH3;Ad}l6&(NCGu#)3`Gm)tWnFX*fWw>iusH-DeXc-0_K%B?cPcYb`dW?L5*s2f4hp zKeP|&@yDS&;8*PpQw~cQEhAf!7vf#A2DL4a-dY3E@O)XZKK~Y*%(FLu`*?(Zen_F2 zPxvUY0RHLI{s$pqq*$-r#fUBwfZo(KCs%hX?u@6-^jp@|GJ(4$>d|yLeaX7K7qf1N25=t-MWP)nc}xHt_coMNUZF&!y2dObegcrn^uF-D>4qs;DA=zqU?bmyx|I zx{YWUS(>xDdPsmyh{Z*-lg^&5RYzXkyVj#%Jjao_N!q@F2y*i=D;iN=%^8j1li)|W zO$Tp!3PT4fpfxfDq zUhF8y%X|XI1;l*cygss_+G?*f_ik^z=Ke5}=A~KOvHxYg)!i}dxwR25Xf+f!SPifN zK_Y9AKWpP+oI@T^$XT5`{_B4e3fD|c@Q}89T*QQwyld*zXZCAD4>GC}9;NG;RG0(5 znCLlG-=@yqe0I($$p5%?wp-oxY5FwGxwa%0!TBYiZX~;QPV~q@A%SXMowq=`bW3rT zPIq&knIrEPBS8(i=47qf){UF!GGy&r0Z;BbJc~h^^*-$0zZUMj%x?59QtrM0%^JKZ$4FPS{j?Ut<*pX!#dB%!EbOGU5*$5VFUa)Y@$M;Z z4sl8Ns(swP-zX*T#^Q9`@)Sed>bf4v-3@?4?C!~cisATi`B3dvT1mth0W%(+%O^(X)3 zB7ad%T0XtsUdE>o28`a;_iQtx4RfXR|6{`h;drtDABlWO*H zgT|>(isc2UO4D+-y-(X5*;PMlIb6=BB$EqoGaR;5T|(3cEW!exbkWR0 zKSxCTZ>!9^nIMV@rXZp3&~tT3_6(~U@dzr@{&LObWzJXp+%8Ugw8q*?g_nMorpp7&E#Ztx{^h3z}&B?D+fl@MlU+)b>qDi^1L1WD%$SyN(bMH5llaAfgwMN+(1yb)GL# zB644QI=;pr)DSWV2$)M5$_W(X;s71nM&EriZMXu9q4}jIu`Zb2ZMe}2;=yh6dp0e8 JEc(5Y{{n}~oSOgu literal 0 HcmV?d00001 diff --git a/eng/common/testproxy/localhost.conf b/eng/common/testproxy/localhost.conf new file mode 100644 index 000000000000..306ff88f924d --- /dev/null +++ b/eng/common/testproxy/localhost.conf @@ -0,0 +1,23 @@ +[req] +prompt = no +default_bits = 2048 +distinguished_name = subject +req_extensions = req_ext +x509_extensions = x509_ext + +[ subject ] +commonName = localhost + +[req_ext] +basicConstraints = critical, CA:true +subjectAltName = @alt_names + +[x509_ext] +basicConstraints = critical, CA:true +keyUsage = critical, keyCertSign, cRLSign, digitalSignature,keyEncipherment +extendedKeyUsage = critical, serverAuth +subjectAltName = critical, @alt_names +1.3.6.1.4.1.311.84.1.1 = ASN1:UTF8String:ASP.NET Core HTTPS development certificate # Needed to get it imported by dotnet dev-certs + +[alt_names] +DNS.1 = localhost \ No newline at end of file diff --git a/eng/common/testproxy/test-proxy-docker.yml b/eng/common/testproxy/test-proxy-docker.yml new file mode 100644 index 000000000000..97617b6fd08a --- /dev/null +++ b/eng/common/testproxy/test-proxy-docker.yml @@ -0,0 +1,15 @@ +parameters: + rootFolder: '$(Build.SourcesDirectory)' + +steps: + - pwsh: | + $(Build.SourcesDirectory)/eng/common/scripts/trust-proxy-certificate.ps1 + displayName: 'Language Specific Certificate Trust' + + - pwsh: | + $(Build.SourcesDirectory)/eng/common/testproxy/docker-start-proxy.ps1 -Mode start -TargetFolder "${{ parameters.rootFolder }}" + displayName: 'Run the docker container' + + - pwsh: | + docker container ls -a + displayName: Check running container \ No newline at end of file diff --git a/eng/common/testproxy/test-proxy-tool.yml b/eng/common/testproxy/test-proxy-tool.yml new file mode 100644 index 000000000000..9f24b0f0d527 --- /dev/null +++ b/eng/common/testproxy/test-proxy-tool.yml @@ -0,0 +1,47 @@ +parameters: + rootFolder: '$(Build.SourcesDirectory)' + +steps: + - pwsh: | + $(Build.SourcesDirectory)/eng/common/scripts/trust-proxy-certificate.ps1 + displayName: 'Language Specific Certificate Trust' + + - pwsh: | + Write-Host "##vso[task.setvariable variable=OriginalPath]$env:PATH" + displayName: 'Store Path Value' + + - pwsh: | + Write-Host "##vso[task.setvariable variable=ASPNETCORE_Kestrel__Certificates__Default__Path]$(Build.SourcesDirectory)/eng/common/testproxy/dotnet-devcert.pfx" + Write-Host "##vso[task.setvariable variable=ASPNETCORE_Kestrel__Certificates__Default__Password]password" + displayName: 'Configure Kestrel Environment Variables' + + - task: UseDotNet@2 + displayName: "Use .NET Core SDK" + inputs: + packageType: sdk + version: 5.0.205 + + - pwsh: | + dotnet tool install azure.sdk.tools.testproxy ` + --tool-path $(Build.BinariesDirectory)/test-proxy ` + --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json ` + --version 1.0.0-dev.20210811.2 + displayName: "Install test-proxy" + + - pwsh: | + Start-Process $(Build.BinariesDirectory)/test-proxy/test-proxy.exe ` + -ArgumentList "--storage-location '${{ parameters.rootFolder }}'" ` + -NoNewWindow -PassThru + displayName: 'Run the testproxy - windows' + condition: and(succeeded(), eq(variables['Agent.OS'],'Windows_NT')) + + # nohup does NOT continue beyond the current session if you use it within powershell + - bash: | + sudo nohup $(Build.BinariesDirectory)/test-proxy/test-proxy & + displayName: "Run the testproxy - linux/mac" + condition: and(succeeded(), ne(variables['Agent.OS'],'Windows_NT')) + workingDirectory: "${{ parameters.rootFolder }}" + + - pwsh: | + Write-Host "##vso[task.setvariable variable=PATH]$(OriginalPath)" + displayName: 'Restore .NET version by resetting path' \ No newline at end of file From 1a40990e7f044695ce8b9c6852e91ef4b5a3e7c6 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 12:52:23 -0400 Subject: [PATCH 22/39] using common --- eng/pipelines/templates/steps/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 669faba92a1b..460baa1e438d 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -28,7 +28,7 @@ steps: env: GO111MODULE: 'on' - - template: configure-proxy.yml + - template: ./eng/common/testproxy/test-proxy-docker.yml #configure-proxy.yml parameters: ServiceDirectory: ${{ parameters.ServiceDirectory }} From c88ae4369c54ef00939e5a1a20de38c463898baa Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 12:57:15 -0400 Subject: [PATCH 23/39] fixing path --- eng/pipelines/templates/steps/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 460baa1e438d..cf64c97550e4 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -28,7 +28,7 @@ steps: env: GO111MODULE: 'on' - - template: ./eng/common/testproxy/test-proxy-docker.yml #configure-proxy.yml + - template: /eng/common/testproxy/test-proxy-docker.yml #configure-proxy.yml parameters: ServiceDirectory: ${{ parameters.ServiceDirectory }} From 25fdd9038633c0a022168f22dbd6ec912d8fc0f2 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 13:03:24 -0400 Subject: [PATCH 24/39] adding trust ps1 script --- eng/common/scripts/trust-proxy-certificate.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 eng/common/scripts/trust-proxy-certificate.ps1 diff --git a/eng/common/scripts/trust-proxy-certificate.ps1 b/eng/common/scripts/trust-proxy-certificate.ps1 new file mode 100644 index 000000000000..144d304cfd18 --- /dev/null +++ b/eng/common/scripts/trust-proxy-certificate.ps1 @@ -0,0 +1,6 @@ +. $PSScriptRoot/common.ps1 + +if ($TestProxyTrustCertFn -and (Test-Path "Function:$TestProxyTrustCertFn")) +{ + &$TestProxyTrustCertFn +} \ No newline at end of file From fbf1d9a6ee3a72d9909735125839b96d87b29451 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 14:03:03 -0400 Subject: [PATCH 25/39] adding step to run proxy --- eng/pipelines/templates/steps/build-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 3fb124547094..3c5de34ce81c 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -30,6 +30,8 @@ steps: displayName: "Install Coverage and Junit Dependencies" workingDirectory: '${{parameters.GoWorkspace}}' + - template: $(Build.SourcesDirectory)/eng/common/testproxy/trust-proxy-docker.ps1 + - pwsh: | $testDirs = (./eng/scripts/get_test_dirs.ps1 -serviceDir $(SCOPE)) foreach ($td in $testDirs) { From 7c16a4816c77534c145bdcab12cff7af563e09ed Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 14:35:33 -0400 Subject: [PATCH 26/39] formatting and go mod x/net --- sdk/tables/aztable/cosmos_patch_transform_policy.go | 1 + sdk/tables/aztable/go.mod | 7 ++++--- sdk/tables/aztable/go.sum | 2 ++ sdk/tables/aztable/zz_generated_connection.go | 1 + sdk/tables/aztable/zz_generated_constants.go | 1 + sdk/tables/aztable/zz_generated_models.go | 1 + sdk/tables/aztable/zz_generated_response_types.go | 1 + sdk/tables/aztable/zz_generated_service_client.go | 1 + sdk/tables/aztable/zz_generated_table_client.go | 1 + sdk/tables/aztable/zz_generated_time_rfc1123.go | 1 + sdk/tables/aztable/zz_generated_time_rfc3339.go | 1 + 11 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sdk/tables/aztable/cosmos_patch_transform_policy.go b/sdk/tables/aztable/cosmos_patch_transform_policy.go index 8403a0893e67..100917521ccd 100644 --- a/sdk/tables/aztable/cosmos_patch_transform_policy.go +++ b/sdk/tables/aztable/cosmos_patch_transform_policy.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/go.mod b/sdk/tables/aztable/go.mod index d221fb14275b..121bbb67ad97 100644 --- a/sdk/tables/aztable/go.mod +++ b/sdk/tables/aztable/go.mod @@ -3,15 +3,16 @@ module github.com/Azure/azure-sdk-for-go/sdk/tables/aztable go 1.13 replace github.com/Azure/azure-sdk-for-go/sdk/internal => ../../internal + replace github.com/Azure/azure-sdk-for-go/sdk/azidentity => ../../azidentity + replace github.com/Azure/azure-sdk-for-go/sdk/azcore => ../../azcore require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v0.16.2 + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.17.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.9.2 // indirect - github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1 + github.com/Azure/azure-sdk-for-go/sdk/internal v0.6.0 github.com/Azure/azure-sdk-for-go/sdk/to v0.1.4 // indirect github.com/stretchr/testify v1.7.0 - golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/sdk/tables/aztable/go.sum b/sdk/tables/aztable/go.sum index 011ec80c81be..d5ba6f6614bf 100644 --- a/sdk/tables/aztable/go.sum +++ b/sdk/tables/aztable/go.sum @@ -31,6 +31,8 @@ golang.org/x/net v0.0.0-20210510120150-4163338589ed h1:p9UgmWI9wKpfYmgaV/IZKGdXc golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/sdk/tables/aztable/zz_generated_connection.go b/sdk/tables/aztable/zz_generated_connection.go index 6aa8ad00d8b3..d752f7e3b28d 100644 --- a/sdk/tables/aztable/zz_generated_connection.go +++ b/sdk/tables/aztable/zz_generated_connection.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_constants.go b/sdk/tables/aztable/zz_generated_constants.go index 3e7b261c70c7..a1ff9041bd71 100644 --- a/sdk/tables/aztable/zz_generated_constants.go +++ b/sdk/tables/aztable/zz_generated_constants.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_models.go b/sdk/tables/aztable/zz_generated_models.go index 7094e996e262..2a31433b5e0c 100644 --- a/sdk/tables/aztable/zz_generated_models.go +++ b/sdk/tables/aztable/zz_generated_models.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_response_types.go b/sdk/tables/aztable/zz_generated_response_types.go index e962b27b4774..70aa81764405 100644 --- a/sdk/tables/aztable/zz_generated_response_types.go +++ b/sdk/tables/aztable/zz_generated_response_types.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_service_client.go b/sdk/tables/aztable/zz_generated_service_client.go index afa44c086aee..caf623d7594b 100644 --- a/sdk/tables/aztable/zz_generated_service_client.go +++ b/sdk/tables/aztable/zz_generated_service_client.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_table_client.go b/sdk/tables/aztable/zz_generated_table_client.go index 13645c322257..10dc7a80a45e 100644 --- a/sdk/tables/aztable/zz_generated_table_client.go +++ b/sdk/tables/aztable/zz_generated_table_client.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_time_rfc1123.go b/sdk/tables/aztable/zz_generated_time_rfc1123.go index e8cd4d9053de..f1ea29aa7efe 100644 --- a/sdk/tables/aztable/zz_generated_time_rfc1123.go +++ b/sdk/tables/aztable/zz_generated_time_rfc1123.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. diff --git a/sdk/tables/aztable/zz_generated_time_rfc3339.go b/sdk/tables/aztable/zz_generated_time_rfc3339.go index dadfddb3cbd3..1388ade6d691 100644 --- a/sdk/tables/aztable/zz_generated_time_rfc3339.go +++ b/sdk/tables/aztable/zz_generated_time_rfc3339.go @@ -1,3 +1,4 @@ +//go:build go1.13 // +build go1.13 // Copyright (c) Microsoft Corporation. All rights reserved. From 542360baf33beeec0342554d6c0ae281502f52df Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 14:48:51 -0400 Subject: [PATCH 27/39] fixing for latest azcore --- .../aztable/cosmos_patch_transform_policy.go | 2 +- sdk/tables/aztable/go.mod | 2 + sdk/tables/aztable/proxy_test.go | 7 +-- .../shared_policy_shared_key_credential.go | 4 +- sdk/tables/aztable/table_service_client.go | 2 +- .../aztable/table_transactional_batch.go | 2 +- .../aztable/zz_generated_service_client.go | 15 +++--- .../aztable/zz_generated_table_client.go | 47 ++++++++++--------- 8 files changed, 43 insertions(+), 38 deletions(-) diff --git a/sdk/tables/aztable/cosmos_patch_transform_policy.go b/sdk/tables/aztable/cosmos_patch_transform_policy.go index 100917521ccd..8c7447a304e8 100644 --- a/sdk/tables/aztable/cosmos_patch_transform_policy.go +++ b/sdk/tables/aztable/cosmos_patch_transform_policy.go @@ -15,7 +15,7 @@ import ( // cosmosPatchTransformPolicy transforms PATCH requests into POST requests with the "X-HTTP-Method":"MERGE" header set. type cosmosPatchTransformPolicy struct{} -func (p cosmosPatchTransformPolicy) Do(req *azcore.Request) (*azcore.Response, error) { +func (p cosmosPatchTransformPolicy) Do(req *azcore.Request) (*http.Response, error) { transformPatchToCosmosPost(req) return req.Next() } diff --git a/sdk/tables/aztable/go.mod b/sdk/tables/aztable/go.mod index 121bbb67ad97..69836ebb3b4d 100644 --- a/sdk/tables/aztable/go.mod +++ b/sdk/tables/aztable/go.mod @@ -8,6 +8,8 @@ replace github.com/Azure/azure-sdk-for-go/sdk/azidentity => ../../azidentity replace github.com/Azure/azure-sdk-for-go/sdk/azcore => ../../azcore +replace github.com/Azure/azure-sdk-for-go/sdk/azcore => ../../azidentity + require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v0.17.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.9.2 // indirect diff --git a/sdk/tables/aztable/proxy_test.go b/sdk/tables/aztable/proxy_test.go index d79f395a4e11..4eeb2bafffad 100644 --- a/sdk/tables/aztable/proxy_test.go +++ b/sdk/tables/aztable/proxy_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "hash/fnv" + "net/http" "strings" "testing" @@ -31,7 +32,7 @@ func NewRecordingPolicy(o *recording.RecordingOptions) azcore.Policy { return p } -func (p *recordingPolicy) Do(req *azcore.Request) (resp *azcore.Response, err error) { +func (p *recordingPolicy) Do(req *azcore.Request) (resp *http.Response, err error) { originalURLHost := req.URL.Host req.URL.Scheme = "https" req.URL.Host = p.options.Host @@ -56,8 +57,8 @@ func NewFakeCredential(accountName, accountKey string) *FakeCredential { } } -func (f *FakeCredential) AuthenticationPolicy(azcore.AuthenticationPolicyOptions) azcore.Policy { - return azcore.PolicyFunc(func(req *azcore.Request) (*azcore.Response, error) { +func (f *FakeCredential) NewAuthenticationPolicy(azcore.AuthenticationOptions) azcore.Policy { + return azcore.PolicyFunc(func(req *azcore.Request) (*http.Response, error) { authHeader := strings.Join([]string{"Authorization ", f.accountName, ":", f.accountKey}, "") req.Request.Header.Set(azcore.HeaderAuthorization, authHeader) return req.Next() diff --git a/sdk/tables/aztable/shared_policy_shared_key_credential.go b/sdk/tables/aztable/shared_policy_shared_key_credential.go index ca011f0b5240..f0e8a7b84487 100644 --- a/sdk/tables/aztable/shared_policy_shared_key_credential.go +++ b/sdk/tables/aztable/shared_policy_shared_key_credential.go @@ -134,8 +134,8 @@ func (c *SharedKeyCredential) buildCanonicalizedResource(u *url.URL) (string, er } // AuthenticationPolicy implements the Credential interface on SharedKeyCredential. -func (c *SharedKeyCredential) AuthenticationPolicy(azcore.AuthenticationPolicyOptions) azcore.Policy { - return azcore.PolicyFunc(func(req *azcore.Request) (*azcore.Response, error) { +func (c *SharedKeyCredential) AuthenticationPolicy(azcore.AuthenticationOptions) azcore.Policy { + return azcore.PolicyFunc(func(req *azcore.Request) (*http.Response, error) { // Add a x-ms-date header if it doesn't already exist if d := req.Request.Header.Get(azcore.HeaderXmsDate); d == "" { req.Request.Header.Set(azcore.HeaderXmsDate, time.Now().UTC().Format(http.TimeFormat)) diff --git a/sdk/tables/aztable/table_service_client.go b/sdk/tables/aztable/table_service_client.go index 7f25d84229cb..0c2a3e873c38 100644 --- a/sdk/tables/aztable/table_service_client.go +++ b/sdk/tables/aztable/table_service_client.go @@ -32,7 +32,7 @@ func NewTableServiceClient(serviceURL string, cred azcore.Credential, options *T if isCosmosEndpoint(serviceURL) { conOptions.PerCallPolicies = []azcore.Policy{cosmosPatchTransformPolicy{}} } - conOptions.PerCallPolicies = append(conOptions.PerCallPolicies, cred.AuthenticationPolicy(azcore.AuthenticationPolicyOptions{Options: azcore.TokenRequestOptions{Scopes: options.Scopes}})) + conOptions.PerCallPolicies = append(conOptions.PerCallPolicies, cred.AuthenticationPolicy(azcore.AuthenticationOptions{Options: azcore.TokenRequestOptions{Scopes: options.Scopes}})) conOptions.PerCallPolicies = append(conOptions.PerCallPolicies, options.PerCallOptions...) con := newConnection(serviceURL, conOptions) return &TableServiceClient{client: &tableClient{con}, service: &serviceClient{con}, cred: cred}, nil diff --git a/sdk/tables/aztable/table_transactional_batch.go b/sdk/tables/aztable/table_transactional_batch.go index d4e7b6ff5d11..069a2ff0a01e 100644 --- a/sdk/tables/aztable/table_transactional_batch.go +++ b/sdk/tables/aztable/table_transactional_batch.go @@ -162,7 +162,7 @@ func (t *TableClient) submitTransactionInternal(ctx context.Context, transaction return transactionResponse, nil } -func buildTransactionResponse(req *azcore.Request, resp *azcore.Response, itemCount int) (TableTransactionResponse, error) { +func buildTransactionResponse(req *azcore.Request, resp *http.Response, itemCount int) (TableTransactionResponse, error) { innerResponses := make([]azcore.Response, itemCount) result := TableTransactionResponse{RawResponse: resp.Response, TransactionResponses: &innerResponses} diff --git a/sdk/tables/aztable/zz_generated_service_client.go b/sdk/tables/aztable/zz_generated_service_client.go index caf623d7594b..2a432505ec71 100644 --- a/sdk/tables/aztable/zz_generated_service_client.go +++ b/sdk/tables/aztable/zz_generated_service_client.go @@ -11,10 +11,11 @@ package aztable import ( "context" "fmt" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" "net/http" "strconv" "time" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" ) type serviceClient struct { @@ -61,7 +62,7 @@ func (client *serviceClient) getPropertiesCreateRequest(ctx context.Context, opt } // getPropertiesHandleResponse handles the GetProperties response. -func (client *serviceClient) getPropertiesHandleResponse(resp *azcore.Response) (TableServicePropertiesResponse, error) { +func (client *serviceClient) getPropertiesHandleResponse(resp *http.Response) (TableServicePropertiesResponse, error) { var val *TableServiceProperties if err := resp.UnmarshalAsXML(&val); err != nil { return TableServicePropertiesResponse{}, err @@ -80,7 +81,7 @@ func (client *serviceClient) getPropertiesHandleResponse(resp *azcore.Response) } // getPropertiesHandleError handles the GetProperties error response. -func (client *serviceClient) getPropertiesHandleError(resp *azcore.Response) error { +func (client *serviceClient) getPropertiesHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -133,7 +134,7 @@ func (client *serviceClient) getStatisticsCreateRequest(ctx context.Context, opt } // getStatisticsHandleResponse handles the GetStatistics response. -func (client *serviceClient) getStatisticsHandleResponse(resp *azcore.Response) (TableServiceStatsResponse, error) { +func (client *serviceClient) getStatisticsHandleResponse(resp *http.Response) (TableServiceStatsResponse, error) { var val *TableServiceStats if err := resp.UnmarshalAsXML(&val); err != nil { return TableServiceStatsResponse{}, err @@ -159,7 +160,7 @@ func (client *serviceClient) getStatisticsHandleResponse(resp *azcore.Response) } // getStatisticsHandleError handles the GetStatistics error response. -func (client *serviceClient) getStatisticsHandleError(resp *azcore.Response) error { +func (client *serviceClient) getStatisticsHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -212,7 +213,7 @@ func (client *serviceClient) setPropertiesCreateRequest(ctx context.Context, tab } // setPropertiesHandleResponse handles the SetProperties response. -func (client *serviceClient) setPropertiesHandleResponse(resp *azcore.Response) (ServiceSetPropertiesResponse, error) { +func (client *serviceClient) setPropertiesHandleResponse(resp *http.Response) (ServiceSetPropertiesResponse, error) { result := ServiceSetPropertiesResponse{RawResponse: resp.Response} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val @@ -227,7 +228,7 @@ func (client *serviceClient) setPropertiesHandleResponse(resp *azcore.Response) } // setPropertiesHandleError handles the SetProperties error response. -func (client *serviceClient) setPropertiesHandleError(resp *azcore.Response) error { +func (client *serviceClient) setPropertiesHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) diff --git a/sdk/tables/aztable/zz_generated_table_client.go b/sdk/tables/aztable/zz_generated_table_client.go index 10dc7a80a45e..262496171480 100644 --- a/sdk/tables/aztable/zz_generated_table_client.go +++ b/sdk/tables/aztable/zz_generated_table_client.go @@ -13,12 +13,13 @@ import ( "encoding/xml" "errors" "fmt" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" "net/http" "net/url" "strconv" "strings" "time" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" ) type tableClient struct { @@ -69,7 +70,7 @@ func (client *tableClient) createCreateRequest(ctx context.Context, tablePropert } // createHandleResponse handles the Create response. -func (client *tableClient) createHandleResponse(resp *azcore.Response) (interface{}, error) { +func (client *tableClient) createHandleResponse(resp *http.Response) (interface{}, error) { switch resp.StatusCode { case http.StatusCreated: var val *TableResponse @@ -125,7 +126,7 @@ func (client *tableClient) createHandleResponse(resp *azcore.Response) (interfac } // createHandleError handles the Create error response. -func (client *tableClient) createHandleError(resp *azcore.Response) error { +func (client *tableClient) createHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -175,7 +176,7 @@ func (client *tableClient) deleteCreateRequest(ctx context.Context, table string } // deleteHandleResponse handles the Delete response. -func (client *tableClient) deleteHandleResponse(resp *azcore.Response) (TableDeleteResponse, error) { +func (client *tableClient) deleteHandleResponse(resp *http.Response) (TableDeleteResponse, error) { result := TableDeleteResponse{RawResponse: resp.Response} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val @@ -197,7 +198,7 @@ func (client *tableClient) deleteHandleResponse(resp *azcore.Response) (TableDel } // deleteHandleError handles the Delete error response. -func (client *tableClient) deleteHandleError(resp *azcore.Response) error { +func (client *tableClient) deleteHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -265,7 +266,7 @@ func (client *tableClient) deleteEntityCreateRequest(ctx context.Context, table } // deleteEntityHandleResponse handles the DeleteEntity response. -func (client *tableClient) deleteEntityHandleResponse(resp *azcore.Response) (TableDeleteEntityResponse, error) { +func (client *tableClient) deleteEntityHandleResponse(resp *http.Response) (TableDeleteEntityResponse, error) { result := TableDeleteEntityResponse{RawResponse: resp.Response} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val @@ -287,7 +288,7 @@ func (client *tableClient) deleteEntityHandleResponse(resp *azcore.Response) (Ta } // deleteEntityHandleError handles the DeleteEntity error response. -func (client *tableClient) deleteEntityHandleError(resp *azcore.Response) error { +func (client *tableClient) deleteEntityHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -343,7 +344,7 @@ func (client *tableClient) getAccessPolicyCreateRequest(ctx context.Context, tab } // getAccessPolicyHandleResponse handles the GetAccessPolicy response. -func (client *tableClient) getAccessPolicyHandleResponse(resp *azcore.Response) (SignedIdentifierArrayResponse, error) { +func (client *tableClient) getAccessPolicyHandleResponse(resp *http.Response) (SignedIdentifierArrayResponse, error) { result := SignedIdentifierArrayResponse{RawResponse: resp.Response} if err := resp.UnmarshalAsXML(&result); err != nil { return SignedIdentifierArrayResponse{}, err @@ -368,7 +369,7 @@ func (client *tableClient) getAccessPolicyHandleResponse(resp *azcore.Response) } // getAccessPolicyHandleError handles the GetAccessPolicy error response. -func (client *tableClient) getAccessPolicyHandleError(resp *azcore.Response) error { +func (client *tableClient) getAccessPolicyHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -434,7 +435,7 @@ func (client *tableClient) insertEntityCreateRequest(ctx context.Context, table } // insertEntityHandleResponse handles the InsertEntity response. -func (client *tableClient) insertEntityHandleResponse(resp *azcore.Response) (interface{}, error) { +func (client *tableClient) insertEntityHandleResponse(resp *http.Response) (interface{}, error) { switch resp.StatusCode { case http.StatusCreated: var val map[string]interface{} @@ -508,7 +509,7 @@ func (client *tableClient) insertEntityHandleResponse(resp *azcore.Response) (in } // insertEntityHandleError handles the InsertEntity error response. -func (client *tableClient) insertEntityHandleError(resp *azcore.Response) error { +func (client *tableClient) insertEntityHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -581,7 +582,7 @@ func (client *tableClient) mergeEntityCreateRequest(ctx context.Context, table s } // mergeEntityHandleResponse handles the MergeEntity response. -func (client *tableClient) mergeEntityHandleResponse(resp *azcore.Response) (TableMergeEntityResponse, error) { +func (client *tableClient) mergeEntityHandleResponse(resp *http.Response) (TableMergeEntityResponse, error) { result := TableMergeEntityResponse{RawResponse: resp.Response} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val @@ -606,7 +607,7 @@ func (client *tableClient) mergeEntityHandleResponse(resp *azcore.Response) (Tab } // mergeEntityHandleError handles the MergeEntity error response. -func (client *tableClient) mergeEntityHandleError(resp *azcore.Response) error { +func (client *tableClient) mergeEntityHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -670,7 +671,7 @@ func (client *tableClient) queryCreateRequest(ctx context.Context, tableQueryOpt } // queryHandleResponse handles the Query response. -func (client *tableClient) queryHandleResponse(resp *azcore.Response) (TableQueryResponseResponse, error) { +func (client *tableClient) queryHandleResponse(resp *http.Response) (TableQueryResponseResponse, error) { var val *TableQueryResponse if err := resp.UnmarshalAsJSON(&val); err != nil { return TableQueryResponseResponse{}, err @@ -699,7 +700,7 @@ func (client *tableClient) queryHandleResponse(resp *azcore.Response) (TableQuer } // queryHandleError handles the Query error response. -func (client *tableClient) queryHandleError(resp *azcore.Response) error { +func (client *tableClient) queryHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -772,7 +773,7 @@ func (client *tableClient) queryEntitiesCreateRequest(ctx context.Context, table } // queryEntitiesHandleResponse handles the QueryEntities response. -func (client *tableClient) queryEntitiesHandleResponse(resp *azcore.Response) (TableEntityQueryResponseResponse, error) { +func (client *tableClient) queryEntitiesHandleResponse(resp *http.Response) (TableEntityQueryResponseResponse, error) { var val *TableEntityQueryResponse if err := resp.UnmarshalAsJSON(&val); err != nil { return TableEntityQueryResponseResponse{}, err @@ -804,7 +805,7 @@ func (client *tableClient) queryEntitiesHandleResponse(resp *azcore.Response) (T } // queryEntitiesHandleError handles the QueryEntities error response. -func (client *tableClient) queryEntitiesHandleError(resp *azcore.Response) error { +func (client *tableClient) queryEntitiesHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -877,7 +878,7 @@ func (client *tableClient) queryEntityWithPartitionAndRowKeyCreateRequest(ctx co } // queryEntityWithPartitionAndRowKeyHandleResponse handles the QueryEntityWithPartitionAndRowKey response. -func (client *tableClient) queryEntityWithPartitionAndRowKeyHandleResponse(resp *azcore.Response) (MapOfInterfaceResponse, error) { +func (client *tableClient) queryEntityWithPartitionAndRowKeyHandleResponse(resp *http.Response) (MapOfInterfaceResponse, error) { var val map[string]interface{} if err := resp.UnmarshalAsJSON(&val); err != nil { return MapOfInterfaceResponse{}, err @@ -918,7 +919,7 @@ func (client *tableClient) queryEntityWithPartitionAndRowKeyHandleResponse(resp } // queryEntityWithPartitionAndRowKeyHandleError handles the QueryEntityWithPartitionAndRowKey error response. -func (client *tableClient) queryEntityWithPartitionAndRowKeyHandleError(resp *azcore.Response) error { +func (client *tableClient) queryEntityWithPartitionAndRowKeyHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -981,7 +982,7 @@ func (client *tableClient) setAccessPolicyCreateRequest(ctx context.Context, tab } // setAccessPolicyHandleResponse handles the SetAccessPolicy response. -func (client *tableClient) setAccessPolicyHandleResponse(resp *azcore.Response) (TableSetAccessPolicyResponse, error) { +func (client *tableClient) setAccessPolicyHandleResponse(resp *http.Response) (TableSetAccessPolicyResponse, error) { result := TableSetAccessPolicyResponse{RawResponse: resp.Response} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val @@ -1003,7 +1004,7 @@ func (client *tableClient) setAccessPolicyHandleResponse(resp *azcore.Response) } // setAccessPolicyHandleError handles the SetAccessPolicy error response. -func (client *tableClient) setAccessPolicyHandleError(resp *azcore.Response) error { +func (client *tableClient) setAccessPolicyHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) @@ -1076,7 +1077,7 @@ func (client *tableClient) updateEntityCreateRequest(ctx context.Context, table } // updateEntityHandleResponse handles the UpdateEntity response. -func (client *tableClient) updateEntityHandleResponse(resp *azcore.Response) (TableUpdateEntityResponse, error) { +func (client *tableClient) updateEntityHandleResponse(resp *http.Response) (TableUpdateEntityResponse, error) { result := TableUpdateEntityResponse{RawResponse: resp.Response} if val := resp.Header.Get("x-ms-client-request-id"); val != "" { result.ClientRequestID = &val @@ -1101,7 +1102,7 @@ func (client *tableClient) updateEntityHandleResponse(resp *azcore.Response) (Ta } // updateEntityHandleError handles the UpdateEntity error response. -func (client *tableClient) updateEntityHandleError(resp *azcore.Response) error { +func (client *tableClient) updateEntityHandleError(resp *http.Response) error { body, err := resp.Payload() if err != nil { return azcore.NewResponseError(err, resp.Response) From 9a54e0649474e86de5f7d9af7883ffd21b1ad28c Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Wed, 18 Aug 2021 15:03:08 -0400 Subject: [PATCH 28/39] fixing rqeuire --- sdk/tables/aztable/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/tables/aztable/go.mod b/sdk/tables/aztable/go.mod index 69836ebb3b4d..8a78d4ac7522 100644 --- a/sdk/tables/aztable/go.mod +++ b/sdk/tables/aztable/go.mod @@ -8,7 +8,7 @@ replace github.com/Azure/azure-sdk-for-go/sdk/azidentity => ../../azidentity replace github.com/Azure/azure-sdk-for-go/sdk/azcore => ../../azcore -replace github.com/Azure/azure-sdk-for-go/sdk/azcore => ../../azidentity +replace github.com/Azure/azure-sdk-for-go/sdk/azidentity => ../../azidentity require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v0.17.0 From bb7978a509d022aec63ac84547cee9e4e92e2014 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 11:19:43 -0400 Subject: [PATCH 29/39] removing eng stuff --- eng/common/testproxy/docker-start-proxy.ps1 | 2 +- .../templates/steps/configure-proxy.yml | 24 ------ eng/scripts/proxy-server.ps1 | 83 ------------------- 3 files changed, 1 insertion(+), 108 deletions(-) delete mode 100644 eng/pipelines/templates/steps/configure-proxy.yml delete mode 100644 eng/scripts/proxy-server.ps1 diff --git a/eng/common/testproxy/docker-start-proxy.ps1 b/eng/common/testproxy/docker-start-proxy.ps1 index 5432630e97ed..4e5da37278a2 100644 --- a/eng/common/testproxy/docker-start-proxy.ps1 +++ b/eng/common/testproxy/docker-start-proxy.ps1 @@ -42,7 +42,7 @@ $SelectedImage = $LINUX_IMAGE_SOURCE $Initial = "" # most of the time, running this script on a windows machine will work just fine, as docker defaults to linux containers -# however, in CI, windows images default to _windows_ containers. We cannot swap them. We can tell if we're in a CI build by +# however, in CI, windows images default to _windows_ containers. We cannot swap them. We can tell if we're in a CI build by # checking for the environment variable TF_BUILD. if ($IsWindows -and $env:TF_BUILD){ $SelectedImage = $WINDOWS_IMAGE_SOURCE diff --git a/eng/pipelines/templates/steps/configure-proxy.yml b/eng/pipelines/templates/steps/configure-proxy.yml deleted file mode 100644 index 6db2c10973e3..000000000000 --- a/eng/pipelines/templates/steps/configure-proxy.yml +++ /dev/null @@ -1,24 +0,0 @@ -parameters: - ServiceDirectory: '' - -steps: - - pwsh: | - $certUriPfx = "https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/testproxy/dotnet-devcert.pfx" - $certUriCrt = "https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/testproxy/dotnet-devcert.crt" - $certLocationPfx = "$(Build.SourcesDirectory)/dotnet-devcert.pfx" - $certLocationCrt = "$(Build.SourcesDirectory)/dotnet-devcert.crt" - - Invoke-WebRequest ` - -Uri $certUriPfx ` - -OutFile $certLocationPfx -UseBasicParsing - - Invoke-WebRequest ` - -Uri $certUriCrt ` - -OutFile $certLocationCrt -UseBasicParsing - - Write-Host "Successfully downloaded crt and pfx files." - - dotnet dev-certs https --clean --import $certLocationPfx -p "password" - - Write-Host "##vso[task.setvariable variable=PROXY_CERT]$certLocationCrt" - displayName: 'Download and Trust Certificate' diff --git a/eng/scripts/proxy-server.ps1 b/eng/scripts/proxy-server.ps1 deleted file mode 100644 index 5432630e97ed..000000000000 --- a/eng/scripts/proxy-server.ps1 +++ /dev/null @@ -1,83 +0,0 @@ - #!/usr/bin/env pwsh -c - -<# -.DESCRIPTION -Start the docker proxy container. If it is already running, quietly exit. Any other error should fail. -.PARAMETER Mode -"start" or "stop" to start up or stop the test-proxy instance. -.PARAMETER TargetFolder -The folder in which context the test proxy will be started. Defaults to current working directory. -#> -[CmdletBinding(SupportsShouldProcess = $true)] -param( - [ValidateSet("start", "stop")] - [String] - $Mode, - [String] - $TargetFolder = "." -) - -try { - docker --version | Out-Null -} -catch { - Write-Error "A invocation of docker --version failed. This indicates that docker is not properly installed or running." - Write-Error "Please check your docker invocation and try running the script again." -} - -$SELECTED_IMAGE_TAG = "1037115" -$CONTAINER_NAME = "ambitious_azsdk_test_proxy" -$LINUX_IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-lin:${SELECTED_IMAGE_TAG}" -$WINDOWS_IMAGE_SOURCE = "azsdkengsys.azurecr.io/engsys/testproxy-win:${SELECTED_IMAGE_TAG}" -$root = (Resolve-Path $TargetFolder).Path.Replace("`\", "/") - -function Get-Proxy-Container(){ - return (docker container ls -a --format "{{ json . }}" --filter "name=$CONTAINER_NAME" ` - | ConvertFrom-Json ` - | Select-Object -First 1) -} - - -$SelectedImage = $LINUX_IMAGE_SOURCE -$Initial = "" - -# most of the time, running this script on a windows machine will work just fine, as docker defaults to linux containers -# however, in CI, windows images default to _windows_ containers. We cannot swap them. We can tell if we're in a CI build by -# checking for the environment variable TF_BUILD. -if ($IsWindows -and $env:TF_BUILD){ - $SelectedImage = $WINDOWS_IMAGE_SOURCE - $Initial = "C:" -} - -if ($Mode -eq "start"){ - $proxyContainer = Get-Proxy-Container - - # if we already have one, we just need to check the state - if($proxyContainer){ - if ($proxyContainer.State -eq "running") - { - Write-Host "Discovered an already running instance of the test-proxy!. Exiting" - exit(0) - } - } - # else we need to create it - else { - Write-Host "Attempting creation of Docker host $CONTAINER_NAME" - Write-Host "docker container create -v `"${root}:${Initial}/etc/testproxy`" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage" - docker container create -v "${root}:${Initial}/etc/testproxy" -p 5001:5001 -p 5000:5000 --name $CONTAINER_NAME $SelectedImage - } - - Write-Host "Attempting start of Docker host $CONTAINER_NAME" - docker container start $CONTAINER_NAME -} - -if ($Mode -eq "stop"){ - $proxyContainer = Get-Proxy-Container - - if($proxyContainer){ - if($proxyContainer.State -eq "running"){ - Write-Host "Found a running instance of $CONTAINER_NAME, shutting it down." - docker container stop $CONTAINER_NAME - } - } -} \ No newline at end of file From 8194878a1e841943541e125512482313bd9a421b Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 16:17:10 -0400 Subject: [PATCH 30/39] conn str --- sdk/tables/aztable/connection_string.go | 2 +- sdk/tables/aztable/connection_string_test.go | 2 +- sdk/tables/aztable/go.mod | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sdk/tables/aztable/connection_string.go b/sdk/tables/aztable/connection_string.go index ecdd26d81433..d8bbb31f4a6c 100644 --- a/sdk/tables/aztable/connection_string.go +++ b/sdk/tables/aztable/connection_string.go @@ -76,7 +76,7 @@ func parseConnectionString(connStr string) (string, azcore.Credential, error) { if !ok { return "", nil, errConnectionString } - return fmt.Sprintf("%v://%v.table.%v/?%v", defaultScheme, accountName, defaultSuffix, sharedAccessSignature), azcore.AnonymousCredential(), nil + return fmt.Sprintf("%v://%v.table.%v/?%v", defaultScheme, accountName, defaultSuffix, sharedAccessSignature), azcore.NewAnonymousCredential(), nil } protocol, ok := connStrMap["DefaultEndpointsProtocol"] diff --git a/sdk/tables/aztable/connection_string_test.go b/sdk/tables/aztable/connection_string_test.go index 93937e0d3fb6..49138372fc01 100644 --- a/sdk/tables/aztable/connection_string_test.go +++ b/sdk/tables/aztable/connection_string_test.go @@ -131,7 +131,7 @@ func TestConnectionStringSAS(t *testing.T) { serviceURL, cred, err := parseConnectionString(connStr) require.NoError(t, err) require.Equal(t, serviceURL, "https://dummyaccount.table.core.windows.net/?fakesharedaccesssignature") - require.Nil(t, cred) + require.NotNil(t, cred) client, err := NewTableClientFromConnectionString("tableName", connStr, nil) require.NoError(t, err) diff --git a/sdk/tables/aztable/go.mod b/sdk/tables/aztable/go.mod index 0e13fd4c62d2..4c10fa962220 100644 --- a/sdk/tables/aztable/go.mod +++ b/sdk/tables/aztable/go.mod @@ -4,8 +4,6 @@ go 1.13 replace github.com/Azure/azure-sdk-for-go/sdk/internal => ../../internal -replace github.com/Azure/azure-sdk-for-go/sdk/azidentity => ../../azidentity - require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v0.18.1 github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.9.3 From 9c095bd8d0542f2465cf4c373f7f14ceb9d8d299 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 16:23:56 -0400 Subject: [PATCH 31/39] running tests --- eng/config.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eng/config.json b/eng/config.json index 711b2f4c3575..ae362a578535 100644 --- a/eng/config.json +++ b/eng/config.json @@ -11,6 +11,10 @@ { "Name": "internal", "CoverageGoal": 0.90 + }, + { + "Name": "aztable", + "CoverageGoal": 0.01 } ] } From 532c74eb591c7a4ab59cd3bf56f68a967740f4bb Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 16:29:03 -0400 Subject: [PATCH 32/39] run tests = true --- sdk/tables/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/tables/ci.yml b/sdk/tables/ci.yml index 3e9703ae327e..107eb650032f 100644 --- a/sdk/tables/ci.yml +++ b/sdk/tables/ci.yml @@ -13,3 +13,4 @@ stages: - template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml parameters: ServiceDirectory: 'tables' + RunTests: true From caa14e8f2f225693e1ab727b1d20c4bff8f9718d Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 16:39:29 -0400 Subject: [PATCH 33/39] adding build sourcesDir --- eng/pipelines/templates/steps/build-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 3c5de34ce81c..f21bd41cd603 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -5,6 +5,7 @@ parameters: Image: '' GoVersion: '' RunTests: false + rootFolder: '$(Build.SourcesDirectory)' steps: From ca092079e9c712195266e1e989b64fe076a6ed69 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 16:42:08 -0400 Subject: [PATCH 34/39] relative path --- eng/pipelines/templates/steps/build-test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index f21bd41cd603..d0865d396439 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -5,7 +5,6 @@ parameters: Image: '' GoVersion: '' RunTests: false - rootFolder: '$(Build.SourcesDirectory)' steps: @@ -31,7 +30,7 @@ steps: displayName: "Install Coverage and Junit Dependencies" workingDirectory: '${{parameters.GoWorkspace}}' - - template: $(Build.SourcesDirectory)/eng/common/testproxy/trust-proxy-docker.ps1 + - template: ./eng/common/testproxy/trust-proxy-docker.ps1 - pwsh: | $testDirs = (./eng/scripts/get_test_dirs.ps1 -serviceDir $(SCOPE)) From 4125fd0811009bd93c8367f09ae6a03b6afec394 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 16:45:15 -0400 Subject: [PATCH 35/39] fixing up path --- eng/pipelines/templates/steps/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index d0865d396439..a19e2249f740 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -30,7 +30,7 @@ steps: displayName: "Install Coverage and Junit Dependencies" workingDirectory: '${{parameters.GoWorkspace}}' - - template: ./eng/common/testproxy/trust-proxy-docker.ps1 + - template: ../../../common/testproxy/trust-proxy-docker.ps1 - pwsh: | $testDirs = (./eng/scripts/get_test_dirs.ps1 -serviceDir $(SCOPE)) From c125e2ceb4747b18fef1f0e504a0d3b3e7e5b073 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 16:49:44 -0400 Subject: [PATCH 36/39] build-test --- eng/pipelines/templates/steps/build-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index a19e2249f740..4d666045b548 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -30,7 +30,7 @@ steps: displayName: "Install Coverage and Junit Dependencies" workingDirectory: '${{parameters.GoWorkspace}}' - - template: ../../../common/testproxy/trust-proxy-docker.ps1 + - template: /eng/common/testproxy/test-proxy-docker.yml - pwsh: | $testDirs = (./eng/scripts/get_test_dirs.ps1 -serviceDir $(SCOPE)) @@ -50,6 +50,8 @@ steps: workingDirectory: '${{parameters.GoWorkspace}}' env: GO111MODULE: 'on' + AZURE_RECORD_MODE: 'playback' + PROXY_CERT: $(Build.SourcesDirectory)/eng/common/testproxy/dotnet-devcert.crt - pwsh: ../eng/scripts/create_coverage.ps1 ${{parameters.ServiceDirectory}} displayName: 'Generate Coverage XML' From 315a1903eb52686aec880bf6ce138a602ffd4553 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 17:03:55 -0400 Subject: [PATCH 37/39] moving byte array response inside table pager --- eng/config.json | 2 +- sdk/tables/aztable/byte_array_response.go | 181 ---------------------- sdk/tables/aztable/table_pagers.go | 174 +++++++++++++++++++++ 3 files changed, 175 insertions(+), 182 deletions(-) delete mode 100644 sdk/tables/aztable/byte_array_response.go diff --git a/eng/config.json b/eng/config.json index ae362a578535..676616e63227 100644 --- a/eng/config.json +++ b/eng/config.json @@ -10,7 +10,7 @@ }, { "Name": "internal", - "CoverageGoal": 0.90 + "CoverageGoal": 0.70 }, { "Name": "aztable", diff --git a/sdk/tables/aztable/byte_array_response.go b/sdk/tables/aztable/byte_array_response.go deleted file mode 100644 index eeb1eece86ae..000000000000 --- a/sdk/tables/aztable/byte_array_response.go +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package aztable - -import ( - "encoding/json" - "net/http" - "time" -) - -// ByteArrayResponse is the return type for a GetEntity operation. The entities properties are stored in the Value property -type ByteArrayResponse struct { - // ClientRequestID contains the information returned from the x-ms-client-request-id header response. - ClientRequestID *string - - // ContentType contains the information returned from the Content-Type header response. - ContentType *string - - // Date contains the information returned from the Date header response. - Date *time.Time - - // ETag contains the information returned from the ETag header response. - ETag *string - - // PreferenceApplied contains the information returned from the Preference-Applied header response. - PreferenceApplied *string - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response - - // RequestID contains the information returned from the x-ms-request-id header response. - RequestID *string - - // The other properties of the table entity. - Value []byte - - // Version contains the information returned from the x-ms-version header response. - Version *string - - // XMSContinuationNextPartitionKey contains the information returned from the x-ms-continuation-NextPartitionKey header response. - XMSContinuationNextPartitionKey *string - - // XMSContinuationNextRowKey contains the information returned from the x-ms-continuation-NextRowKey header response. - XMSContinuationNextRowKey *string -} - -// newByteArrayResponse converts a MapofInterfaceResponse from a map[string]interface{} to a []byte. -func newByteArrayResponse(m MapOfInterfaceResponse) (ByteArrayResponse, error) { - marshalledValue, err := json.Marshal(m.Value) - if err != nil { - return ByteArrayResponse{}, err - } - return ByteArrayResponse{ - ClientRequestID: m.ClientRequestID, - ContentType: m.ContentType, - Date: m.Date, - ETag: m.ETag, - PreferenceApplied: m.PreferenceApplied, - RawResponse: m.RawResponse, - RequestID: m.RequestID, - Value: marshalledValue, - Version: m.Version, - XMSContinuationNextPartitionKey: m.XMSContinuationNextPartitionKey, - XMSContinuationNextRowKey: m.XMSContinuationNextRowKey, - }, nil -} - -// TableEntityListByteResponseResponse is the response envelope for operations that return a TableEntityQueryResponse type. -type TableEntityListByteResponseResponse struct { - // ClientRequestID contains the information returned from the x-ms-client-request-id header response. - ClientRequestID *string - - // Date contains the information returned from the Date header response. - Date *time.Time - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response - - // RequestID contains the information returned from the x-ms-request-id header response. - RequestID *string - - // The properties for the table entity query response. - TableEntityQueryResponse *TableEntityQueryByteResponse - - // Version contains the information returned from the x-ms-version header response. - Version *string - - // XMSContinuationNextPartitionKey contains the information returned from the x-ms-continuation-NextPartitionKey header response. - XMSContinuationNextPartitionKey *string - - // XMSContinuationNextRowKey contains the information returned from the x-ms-continuation-NextRowKey header response. - XMSContinuationNextRowKey *string -} - -// TableEntityQueryByteResponse - The properties for the table entity query response. -type TableEntityQueryByteResponse struct { - // The metadata response of the table. - OdataMetadata *string - - // List of table entities. - Value [][]byte -} - -func castToByteResponse(resp *TableEntityQueryResponseResponse) (TableEntityListByteResponseResponse, error) { - marshalledValue := make([][]byte, 0) - for _, e := range resp.TableEntityQueryResponse.Value { - m, err := json.Marshal(e) - if err != nil { - return TableEntityListByteResponseResponse{}, err - } - marshalledValue = append(marshalledValue, m) - } - - t := TableEntityQueryByteResponse{ - OdataMetadata: resp.TableEntityQueryResponse.OdataMetadata, - Value: marshalledValue, - } - - return TableEntityListByteResponseResponse{ - ClientRequestID: resp.ClientRequestID, - Date: resp.Date, - RawResponse: resp.RawResponse, - RequestID: resp.RequestID, - TableEntityQueryResponse: &t, - Version: resp.Version, - XMSContinuationNextPartitionKey: resp.XMSContinuationNextPartitionKey, - XMSContinuationNextRowKey: resp.XMSContinuationNextRowKey, - }, nil -} - -type TableListResponse struct { - // The metadata response of the table. - OdataMetadata *string `json:"odata.metadata,omitempty"` - - // List of tables. - Value []*TableResponseProperties `json:"value,omitempty"` -} - -func tableListResponseFromQueryResponse(q *TableQueryResponse) *TableListResponse { - return &TableListResponse{ - OdataMetadata: q.OdataMetadata, - Value: q.Value, - } -} - -// TableListResponseResponse stores the results of a ListTables operation -type TableListResponseResponse struct { - // ClientRequestID contains the information returned from the x-ms-client-request-id header response. - ClientRequestID *string - - // Date contains the information returned from the Date header response. - Date *time.Time - - // RawResponse contains the underlying HTTP response. - RawResponse *http.Response - - // RequestID contains the information returned from the x-ms-request-id header response. - RequestID *string - - // The properties for the table query response. - TableListResponse *TableListResponse - - // Version contains the information returned from the x-ms-version header response. - Version *string - - // XMSContinuationNextTableName contains the information returned from the x-ms-continuation-NextTableName header response. - XMSContinuationNextTableName *string -} - -func listResponseFromQueryResponse(q TableQueryResponseResponse) *TableListResponseResponse { - return &TableListResponseResponse{ - ClientRequestID: q.ClientRequestID, - Date: q.Date, - RawResponse: q.RawResponse, - RequestID: q.RequestID, - TableListResponse: tableListResponseFromQueryResponse(q.TableQueryResponse), - Version: q.Version, - XMSContinuationNextTableName: q.XMSContinuationNextTableName, - } -} diff --git a/sdk/tables/aztable/table_pagers.go b/sdk/tables/aztable/table_pagers.go index 2aa6875205db..5d2b98bf64f7 100644 --- a/sdk/tables/aztable/table_pagers.go +++ b/sdk/tables/aztable/table_pagers.go @@ -5,6 +5,9 @@ package aztable import ( "context" + "encoding/json" + "net/http" + "time" ) // TableEntityListResponsePager is a Pager for Table entity query results. @@ -142,3 +145,174 @@ func (p *tableQueryResponsePager) PageResponse() TableListResponseResponse { func (p *tableQueryResponsePager) Err() error { return p.err } + +// ByteArrayResponse is the return type for a GetEntity operation. The entities properties are stored in the Value property +type ByteArrayResponse struct { + // ClientRequestID contains the information returned from the x-ms-client-request-id header response. + ClientRequestID *string + + // ContentType contains the information returned from the Content-Type header response. + ContentType *string + + // Date contains the information returned from the Date header response. + Date *time.Time + + // ETag contains the information returned from the ETag header response. + ETag *string + + // PreferenceApplied contains the information returned from the Preference-Applied header response. + PreferenceApplied *string + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response + + // RequestID contains the information returned from the x-ms-request-id header response. + RequestID *string + + // The other properties of the table entity. + Value []byte + + // Version contains the information returned from the x-ms-version header response. + Version *string + + // XMSContinuationNextPartitionKey contains the information returned from the x-ms-continuation-NextPartitionKey header response. + XMSContinuationNextPartitionKey *string + + // XMSContinuationNextRowKey contains the information returned from the x-ms-continuation-NextRowKey header response. + XMSContinuationNextRowKey *string +} + +// newByteArrayResponse converts a MapofInterfaceResponse from a map[string]interface{} to a []byte. +func newByteArrayResponse(m MapOfInterfaceResponse) (ByteArrayResponse, error) { + marshalledValue, err := json.Marshal(m.Value) + if err != nil { + return ByteArrayResponse{}, err + } + return ByteArrayResponse{ + ClientRequestID: m.ClientRequestID, + ContentType: m.ContentType, + Date: m.Date, + ETag: m.ETag, + PreferenceApplied: m.PreferenceApplied, + RawResponse: m.RawResponse, + RequestID: m.RequestID, + Value: marshalledValue, + Version: m.Version, + XMSContinuationNextPartitionKey: m.XMSContinuationNextPartitionKey, + XMSContinuationNextRowKey: m.XMSContinuationNextRowKey, + }, nil +} + +// TableEntityListByteResponseResponse is the response envelope for operations that return a TableEntityQueryResponse type. +type TableEntityListByteResponseResponse struct { + // ClientRequestID contains the information returned from the x-ms-client-request-id header response. + ClientRequestID *string + + // Date contains the information returned from the Date header response. + Date *time.Time + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response + + // RequestID contains the information returned from the x-ms-request-id header response. + RequestID *string + + // The properties for the table entity query response. + TableEntityQueryResponse *TableEntityQueryByteResponse + + // Version contains the information returned from the x-ms-version header response. + Version *string + + // XMSContinuationNextPartitionKey contains the information returned from the x-ms-continuation-NextPartitionKey header response. + XMSContinuationNextPartitionKey *string + + // XMSContinuationNextRowKey contains the information returned from the x-ms-continuation-NextRowKey header response. + XMSContinuationNextRowKey *string +} + +// TableEntityQueryByteResponse - The properties for the table entity query response. +type TableEntityQueryByteResponse struct { + // The metadata response of the table. + OdataMetadata *string + + // List of table entities. + Value [][]byte +} + +func castToByteResponse(resp *TableEntityQueryResponseResponse) (TableEntityListByteResponseResponse, error) { + marshalledValue := make([][]byte, 0) + for _, e := range resp.TableEntityQueryResponse.Value { + m, err := json.Marshal(e) + if err != nil { + return TableEntityListByteResponseResponse{}, err + } + marshalledValue = append(marshalledValue, m) + } + + t := TableEntityQueryByteResponse{ + OdataMetadata: resp.TableEntityQueryResponse.OdataMetadata, + Value: marshalledValue, + } + + return TableEntityListByteResponseResponse{ + ClientRequestID: resp.ClientRequestID, + Date: resp.Date, + RawResponse: resp.RawResponse, + RequestID: resp.RequestID, + TableEntityQueryResponse: &t, + Version: resp.Version, + XMSContinuationNextPartitionKey: resp.XMSContinuationNextPartitionKey, + XMSContinuationNextRowKey: resp.XMSContinuationNextRowKey, + }, nil +} + +type TableListResponse struct { + // The metadata response of the table. + OdataMetadata *string `json:"odata.metadata,omitempty"` + + // List of tables. + Value []*TableResponseProperties `json:"value,omitempty"` +} + +func tableListResponseFromQueryResponse(q *TableQueryResponse) *TableListResponse { + return &TableListResponse{ + OdataMetadata: q.OdataMetadata, + Value: q.Value, + } +} + +// TableListResponseResponse stores the results of a ListTables operation +type TableListResponseResponse struct { + // ClientRequestID contains the information returned from the x-ms-client-request-id header response. + ClientRequestID *string + + // Date contains the information returned from the Date header response. + Date *time.Time + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response + + // RequestID contains the information returned from the x-ms-request-id header response. + RequestID *string + + // The properties for the table query response. + TableListResponse *TableListResponse + + // Version contains the information returned from the x-ms-version header response. + Version *string + + // XMSContinuationNextTableName contains the information returned from the x-ms-continuation-NextTableName header response. + XMSContinuationNextTableName *string +} + +func listResponseFromQueryResponse(q TableQueryResponseResponse) *TableListResponseResponse { + return &TableListResponseResponse{ + ClientRequestID: q.ClientRequestID, + Date: q.Date, + RawResponse: q.RawResponse, + RequestID: q.RequestID, + TableListResponse: tableListResponseFromQueryResponse(q.TableQueryResponse), + Version: q.Version, + XMSContinuationNextTableName: q.XMSContinuationNextTableName, + } +} From 3b7e68da6a4d2910c6538bc9c34ed6458ccc313e Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 17:14:46 -0400 Subject: [PATCH 38/39] env var playing to fix ci lint --- eng/pipelines/templates/steps/build-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eng/pipelines/templates/steps/build-test.yml b/eng/pipelines/templates/steps/build-test.yml index 4d666045b548..46ba835be976 100644 --- a/eng/pipelines/templates/steps/build-test.yml +++ b/eng/pipelines/templates/steps/build-test.yml @@ -56,6 +56,8 @@ steps: - pwsh: ../eng/scripts/create_coverage.ps1 ${{parameters.ServiceDirectory}} displayName: 'Generate Coverage XML' workingDirectory: '${{parameters.GoWorkspace}}sdk' + env: + GO111MODULE: 'off' - task: PublishTestResults@2 condition: succeededOrFailed() From 8c9c9d69969d44760ada40013eabf4a78093e39a Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 20 Aug 2021 17:22:14 -0400 Subject: [PATCH 39/39] changing package name --- eng/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/config.json b/eng/config.json index 676616e63227..c06a0ba0ca4d 100644 --- a/eng/config.json +++ b/eng/config.json @@ -13,7 +13,7 @@ "CoverageGoal": 0.70 }, { - "Name": "aztable", + "Name": "tables", "CoverageGoal": 0.01 } ]