diff --git a/sdk/keyvault/internal/CHANGELOG.md b/sdk/keyvault/internal/CHANGELOG.md index 5ce15f64802a..4521d0eee954 100644 --- a/sdk/keyvault/internal/CHANGELOG.md +++ b/sdk/keyvault/internal/CHANGELOG.md @@ -1,14 +1,12 @@ # Release History -## 0.2.2 (Unreleased) +## 0.3.0 (2022-04-04) ### Features Added +* Adds the `ParseKeyvaultID` function to parse an ID into the Key Vault URL, item name, and item version ### Breaking Changes - -### Bugs Fixed - -### Other Changes +* Updates to azcore v0.23.0 ## 0.2.1 (2022-01-31) diff --git a/sdk/keyvault/internal/challenge_policy.go b/sdk/keyvault/internal/challenge_policy.go index bba3b7be9a51..adb26ac0cff5 100644 --- a/sdk/keyvault/internal/challenge_policy.go +++ b/sdk/keyvault/internal/challenge_policy.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. @@ -125,7 +125,7 @@ func (k *KeyVaultChallengePolicy) Do(req *policy.Request) (*http.Response, error // https://login.microsoftonline.com/00000000-0000-0000-0000-000000000000 func parseTenant(url string) *string { if url == "" { - return to.StringPtr("") + return to.Ptr("") } parts := strings.Split(url, "/") tenant := parts[3] diff --git a/sdk/keyvault/internal/challenge_policy_test.go b/sdk/keyvault/internal/challenge_policy_test.go index ebc466b0bed8..c65e05d739ef 100644 --- a/sdk/keyvault/internal/challenge_policy_test.go +++ b/sdk/keyvault/internal/challenge_policy_test.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. diff --git a/sdk/keyvault/internal/constants.go b/sdk/keyvault/internal/constants.go index 58186e5d5288..4ab031fa574c 100644 --- a/sdk/keyvault/internal/constants.go +++ b/sdk/keyvault/internal/constants.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. @@ -7,5 +7,5 @@ package internal const ( - version = "v0.2.2" //nolint + version = "v0.3.0" //nolint ) diff --git a/sdk/keyvault/internal/doc.go b/sdk/keyvault/internal/doc.go index 4cde2d2bc1a7..d8f93492f51d 100644 --- a/sdk/keyvault/internal/doc.go +++ b/sdk/keyvault/internal/doc.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. diff --git a/sdk/keyvault/internal/expiring_resource.go b/sdk/keyvault/internal/expiring_resource.go index 93a2ff6ccf1b..2567b73e4fcd 100644 --- a/sdk/keyvault/internal/expiring_resource.go +++ b/sdk/keyvault/internal/expiring_resource.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. diff --git a/sdk/keyvault/internal/expiring_resource_test.go b/sdk/keyvault/internal/expiring_resource_test.go index 57cc432adf60..57daa67c0c2e 100644 --- a/sdk/keyvault/internal/expiring_resource_test.go +++ b/sdk/keyvault/internal/expiring_resource_test.go @@ -1,5 +1,5 @@ -//go:build go1.16 -// +build go1.16 +//go:build go1.18 +// +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. diff --git a/sdk/keyvault/internal/go.mod b/sdk/keyvault/internal/go.mod index c413a643ea54..77828f5db6ba 100644 --- a/sdk/keyvault/internal/go.mod +++ b/sdk/keyvault/internal/go.mod @@ -1,9 +1,17 @@ module github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal -go 1.16 +go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 - github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1 + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.23.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v0.9.2 github.com/stretchr/testify v1.7.0 ) + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/net v0.0.0-20210610132358-84b48f89b13b // indirect + golang.org/x/text v0.3.6 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) diff --git a/sdk/keyvault/internal/go.sum b/sdk/keyvault/internal/go.sum index 15eb8261ea84..ce7f432a8a42 100644 --- a/sdk/keyvault/internal/go.sum +++ b/sdk/keyvault/internal/go.sum @@ -1,7 +1,7 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 h1:KQgdWmEOmaJKxaUUZwHAYh12t+b+ZJf8q3friycK1kA= -github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0/go.mod h1:ZPW/Z0kLCTdDZaDbYTetxc9Cxl/2lNqxYHYNOF2bti0= -github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1 h1:BUYIbDf/mMZ8945v3QkG3OuqGVyS4Iek0AOLwdRAYoc= -github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.23.0 h1:D7l5jspkc4kwBYRWoZE4DQnu6LVpLwDsMZjBKS4wZLQ= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.23.0/go.mod h1:w5pDIZuawUmY3Bj4tVx3Xb8KS96ToB0j315w9rqpAg0= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.9.2 h1:Px2KVERcYEg2Lv25AqC2hVr0xUWaq94wuEObLIkYzmA= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.9.2/go.mod h1:CdSJQNNzZhCkwDaV27XV1w48ZBPtxe7mlrZAsPNxD5g= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= @@ -20,9 +20,6 @@ golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qx 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= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= diff --git a/sdk/keyvault/internal/parse.go b/sdk/keyvault/internal/parse.go new file mode 100644 index 000000000000..a46b25b7aeea --- /dev/null +++ b/sdk/keyvault/internal/parse.go @@ -0,0 +1,37 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +package internal + +import ( + "fmt" + "net/url" + "strings" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" +) + +// ParseID parses "https://myvaultname.vault.azure.net/keys/key1053998307/b86c2e6ad9054f4abf69cc185b99aa60" +// into "https://myvaultname.managedhsm.azure.net/", "key1053998307", and "b86c2e6ad9054f4abf69cc185b99aa60" +func ParseID(id *string) (*string, *string, *string) { + if id == nil { + return nil, nil, nil + } + parsed, err := url.Parse(*id) + if err != nil { + return nil, nil, nil + } + + url := fmt.Sprintf("%s://%s/", parsed.Scheme, parsed.Host) + split := strings.Split(strings.TrimPrefix(parsed.Path, "/"), "/") + if len(split) < 3 { + if len(split) == 2 { + return &url, to.Ptr(split[1]), nil + } + return &url, nil, nil + } + + return &url, to.Ptr(split[1]), to.Ptr(split[2]) +} diff --git a/sdk/keyvault/internal/parse_test.go b/sdk/keyvault/internal/parse_test.go new file mode 100644 index 000000000000..2d29605929af --- /dev/null +++ b/sdk/keyvault/internal/parse_test.go @@ -0,0 +1,43 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +package internal + +import ( + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/stretchr/testify/require" +) + +func TestParseID(t *testing.T) { + examples := map[string]struct{ url, name, version *string }{ + "https://myvaultname.vault.azure.net/keys/key1053998307/b86c2e6ad9054f4abf69cc185b99aa60": {to.Ptr("https://myvaultname.vault.azure.net/"), to.Ptr("key1053998307"), to.Ptr("b86c2e6ad9054f4abf69cc185b99aa60")}, + "https://myvaultname.vault.azure.net/keys/key1053998307": {to.Ptr("https://myvaultname.vault.azure.net/"), to.Ptr("key1053998307"), nil}, + "https://myvaultname.vault.azure.net/": {to.Ptr("https://myvaultname.vault.azure.net/"), nil, nil}, + } + + for url, result := range examples { + url, name, version := ParseID(&url) + if result.url == nil { + require.Nil(t, url) + } else { + require.NotNil(t, url) + require.Equal(t, *url, *result.url) + } + if result.name == nil { + require.Nil(t, name) + } else { + require.NotNilf(t, name, "expected %s", *result.name) + require.Equal(t, *name, *result.name) + } + if result.version == nil { + require.Nil(t, version) + } else { + require.NotNil(t, version) + require.Equal(t, *version, *result.version) + } + } +}