-
Notifications
You must be signed in to change notification settings - Fork 860
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KeyVault] Updating internal to go1.18 (#17402)
* updating to go 1.18 * moving parsing into internal * build tags and copyright * version * updating to latest azcore
- Loading branch information
1 parent
60601f6
commit d244917
Showing
11 changed files
with
112 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |