Skip to content

Commit

Permalink
[KeyVault] Updating internal to go1.18 (#17402)
Browse files Browse the repository at this point in the history
* updating to go 1.18

* moving parsing into internal

* build tags and copyright

* version

* updating to latest azcore
  • Loading branch information
seankane-msft authored Apr 5, 2022
1 parent 60601f6 commit d244917
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 29 deletions.
8 changes: 3 additions & 5 deletions sdk/keyvault/internal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
6 changes: 3 additions & 3 deletions sdk/keyvault/internal/challenge_policy.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions sdk/keyvault/internal/challenge_policy_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions sdk/keyvault/internal/constants.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//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.

package internal

const (
version = "v0.2.2" //nolint
version = "v0.3.0" //nolint
)
4 changes: 2 additions & 2 deletions sdk/keyvault/internal/doc.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions sdk/keyvault/internal/expiring_resource.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions sdk/keyvault/internal/expiring_resource_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 11 additions & 3 deletions sdk/keyvault/internal/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
11 changes: 4 additions & 7 deletions sdk/keyvault/internal/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand Down
37 changes: 37 additions & 0 deletions sdk/keyvault/internal/parse.go
Original file line number Diff line number Diff line change
@@ -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])
}
43 changes: 43 additions & 0 deletions sdk/keyvault/internal/parse_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit d244917

Please sign in to comment.