Skip to content

Commit

Permalink
Add KeyVaultResourceURL (#367)
Browse files Browse the repository at this point in the history
* Add KeyVaultResourceID for auth

* refactor based on feedback

* remove MicrosoftGraph and Storage, added OperationalInsights

* update tests
  • Loading branch information
karataliu authored and jhendrixMSFT committed Apr 17, 2019
1 parent 7461c5d commit 562d376
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 30 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## v11.9.0

### New Features

- Add `ResourceIdentifiers` field to `azure.Environment` containing resource IDs for public and sovereign clouds.

## v11.8.0

### New Features
Expand Down
97 changes: 70 additions & 27 deletions autorest/azure/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ import (
"strings"
)

// EnvironmentFilepathName captures the name of the environment variable containing the path to the file
// to be used while populating the Azure Environment.
const EnvironmentFilepathName = "AZURE_ENVIRONMENT_FILEPATH"
const (
// EnvironmentFilepathName captures the name of the environment variable containing the path to the file
// to be used while populating the Azure Environment.
EnvironmentFilepathName = "AZURE_ENVIRONMENT_FILEPATH"

// NotAvailable is used for endpoints and resource IDs that are not available for a given cloud.
NotAvailable = "N/A"
)

var environments = map[string]Environment{
"AZURECHINACLOUD": ChinaCloud,
Expand All @@ -33,29 +38,39 @@ var environments = map[string]Environment{
"AZUREUSGOVERNMENTCLOUD": USGovernmentCloud,
}

// ResourceIdentifier contains a set of Azure resource IDs.
type ResourceIdentifier struct {
Graph string `json:"graph"`
KeyVault string `json:"keyVault"`
Datalake string `json:"datalake"`
Batch string `json:"batch"`
OperationalInsights string `json:"operationalInsights"`
}

// Environment represents a set of endpoints for each of Azure's Clouds.
type Environment struct {
Name string `json:"name"`
ManagementPortalURL string `json:"managementPortalURL"`
PublishSettingsURL string `json:"publishSettingsURL"`
ServiceManagementEndpoint string `json:"serviceManagementEndpoint"`
ResourceManagerEndpoint string `json:"resourceManagerEndpoint"`
ActiveDirectoryEndpoint string `json:"activeDirectoryEndpoint"`
GalleryEndpoint string `json:"galleryEndpoint"`
KeyVaultEndpoint string `json:"keyVaultEndpoint"`
GraphEndpoint string `json:"graphEndpoint"`
ServiceBusEndpoint string `json:"serviceBusEndpoint"`
BatchManagementEndpoint string `json:"batchManagementEndpoint"`
StorageEndpointSuffix string `json:"storageEndpointSuffix"`
SQLDatabaseDNSSuffix string `json:"sqlDatabaseDNSSuffix"`
TrafficManagerDNSSuffix string `json:"trafficManagerDNSSuffix"`
KeyVaultDNSSuffix string `json:"keyVaultDNSSuffix"`
ServiceBusEndpointSuffix string `json:"serviceBusEndpointSuffix"`
ServiceManagementVMDNSSuffix string `json:"serviceManagementVMDNSSuffix"`
ResourceManagerVMDNSSuffix string `json:"resourceManagerVMDNSSuffix"`
ContainerRegistryDNSSuffix string `json:"containerRegistryDNSSuffix"`
CosmosDBDNSSuffix string `json:"cosmosDBDNSSuffix"`
TokenAudience string `json:"tokenAudience"`
Name string `json:"name"`
ManagementPortalURL string `json:"managementPortalURL"`
PublishSettingsURL string `json:"publishSettingsURL"`
ServiceManagementEndpoint string `json:"serviceManagementEndpoint"`
ResourceManagerEndpoint string `json:"resourceManagerEndpoint"`
ActiveDirectoryEndpoint string `json:"activeDirectoryEndpoint"`
GalleryEndpoint string `json:"galleryEndpoint"`
KeyVaultEndpoint string `json:"keyVaultEndpoint"`
GraphEndpoint string `json:"graphEndpoint"`
ServiceBusEndpoint string `json:"serviceBusEndpoint"`
BatchManagementEndpoint string `json:"batchManagementEndpoint"`
StorageEndpointSuffix string `json:"storageEndpointSuffix"`
SQLDatabaseDNSSuffix string `json:"sqlDatabaseDNSSuffix"`
TrafficManagerDNSSuffix string `json:"trafficManagerDNSSuffix"`
KeyVaultDNSSuffix string `json:"keyVaultDNSSuffix"`
ServiceBusEndpointSuffix string `json:"serviceBusEndpointSuffix"`
ServiceManagementVMDNSSuffix string `json:"serviceManagementVMDNSSuffix"`
ResourceManagerVMDNSSuffix string `json:"resourceManagerVMDNSSuffix"`
ContainerRegistryDNSSuffix string `json:"containerRegistryDNSSuffix"`
CosmosDBDNSSuffix string `json:"cosmosDBDNSSuffix"`
TokenAudience string `json:"tokenAudience"`
ResourceIdentifiers ResourceIdentifier `json:"resourceIdentifiers"`
}

var (
Expand All @@ -82,6 +97,13 @@ var (
ContainerRegistryDNSSuffix: "azurecr.io",
CosmosDBDNSSuffix: "documents.azure.com",
TokenAudience: "https://management.azure.com/",
ResourceIdentifiers: ResourceIdentifier{
Graph: "https://graph.windows.net/",
KeyVault: "https://vault.azure.net",
Datalake: "https://datalake.azure.net/",
Batch: "https://batch.core.windows.net/",
OperationalInsights: "https://api.loganalytics.io",
},
}

// USGovernmentCloud is the cloud environment for the US Government
Expand All @@ -107,6 +129,13 @@ var (
ContainerRegistryDNSSuffix: "azurecr.us",
CosmosDBDNSSuffix: "documents.azure.us",
TokenAudience: "https://management.usgovcloudapi.net/",
ResourceIdentifiers: ResourceIdentifier{
Graph: "https://graph.windows.net/",
KeyVault: "https://vault.usgovcloudapi.net",
Datalake: NotAvailable,
Batch: "https://batch.core.usgovcloudapi.net/",
OperationalInsights: "https://api.loganalytics.us",
},
}

// ChinaCloud is the cloud environment operated in China
Expand All @@ -132,6 +161,13 @@ var (
ContainerRegistryDNSSuffix: "azurecr.cn",
CosmosDBDNSSuffix: "documents.azure.cn",
TokenAudience: "https://management.chinacloudapi.cn/",
ResourceIdentifiers: ResourceIdentifier{
Graph: "https://graph.chinacloudapi.cn/",
KeyVault: "https://vault.azure.cn",
Datalake: NotAvailable,
Batch: "https://batch.chinacloudapi.cn/",
OperationalInsights: NotAvailable,
},
}

// GermanCloud is the cloud environment operated in Germany
Expand All @@ -154,9 +190,16 @@ var (
ServiceBusEndpointSuffix: "servicebus.cloudapi.de",
ServiceManagementVMDNSSuffix: "azurecloudapp.de",
ResourceManagerVMDNSSuffix: "cloudapp.microsoftazure.de",
// ContainerRegistryDNSSuffix: "", ACR not present yet in the German Cloud
CosmosDBDNSSuffix: "documents.microsoftazure.de",
TokenAudience: "https://management.microsoftazure.de/",
ContainerRegistryDNSSuffix: NotAvailable,
CosmosDBDNSSuffix: "documents.microsoftazure.de",
TokenAudience: "https://management.microsoftazure.de/",
ResourceIdentifiers: ResourceIdentifier{
Graph: "https://graph.cloudapi.de/",
KeyVault: "https://vault.microsoftazure.de",
Datalake: NotAvailable,
Batch: "https://batch.cloudapi.de/",
OperationalInsights: NotAvailable,
},
}
)

Expand Down
61 changes: 60 additions & 1 deletion autorest/azure/environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ import (
"testing"
)

const (
batchResourceID = "--batch-resource-id--"
datalakeResourceID = "--datalake-resource-id--"
graphResourceID = "--graph-resource-id--"
keyvaultResourceID = "--keyvault-resource-id--"
opInsightsResourceID = "--operational-insights-resource-id--"
)

// This correlates to the expected contents of ./testdata/test_environment_1.json
var testEnvironment1 = Environment{
Name: "--unit-test--",
Expand All @@ -47,6 +55,13 @@ var testEnvironment1 = Environment{
ResourceManagerVMDNSSuffix: "--arm-vm-dns-suffix--",
ContainerRegistryDNSSuffix: "--container-registry-dns-suffix--",
TokenAudience: "--token-audience",
ResourceIdentifiers: ResourceIdentifier{
Batch: batchResourceID,
Datalake: datalakeResourceID,
Graph: graphResourceID,
KeyVault: keyvaultResourceID,
OperationalInsights: opInsightsResourceID,
},
}

func TestEnvironment_EnvironmentFromURL_NoOverride_Success(t *testing.T) {
Expand Down Expand Up @@ -196,7 +211,14 @@ func TestDeserializeEnvironment(t *testing.T) {
"trafficManagerDNSSuffix": "--traffic-manager-dns-suffix--",
"serviceManagementVMDNSSuffix": "--asm-vm-dns-suffix--",
"resourceManagerVMDNSSuffix": "--arm-vm-dns-suffix--",
"containerRegistryDNSSuffix": "--container-registry-dns-suffix--"
"containerRegistryDNSSuffix": "--container-registry-dns-suffix--",
"resourceIdentifiers": {
"batch": "` + batchResourceID + `",
"datalake": "` + datalakeResourceID + `",
"graph": "` + graphResourceID + `",
"keyVault": "` + keyvaultResourceID + `",
"operationalInsights": "` + opInsightsResourceID + `"
}
}`

testSubject := Environment{}
Expand Down Expand Up @@ -256,6 +278,21 @@ func TestDeserializeEnvironment(t *testing.T) {
if "--container-registry-dns-suffix--" != testSubject.ContainerRegistryDNSSuffix {
t.Errorf("Expected ContainerRegistryDNSSuffix to be \"--container-registry-dns-suffix--\", but got %q", testSubject.ContainerRegistryDNSSuffix)
}
if batchResourceID != testSubject.ResourceIdentifiers.Batch {
t.Errorf("Expected ResourceIdentifiers.Batch to be "+batchResourceID+", but got %q", testSubject.ResourceIdentifiers.Batch)
}
if datalakeResourceID != testSubject.ResourceIdentifiers.Datalake {
t.Errorf("Expected ResourceIdentifiers.Datalake to be "+datalakeResourceID+", but got %q", testSubject.ResourceIdentifiers.Datalake)
}
if graphResourceID != testSubject.ResourceIdentifiers.Graph {
t.Errorf("Expected ResourceIdentifiers.Graph to be "+graphResourceID+", but got %q", testSubject.ResourceIdentifiers.Graph)
}
if keyvaultResourceID != testSubject.ResourceIdentifiers.KeyVault {
t.Errorf("Expected ResourceIdentifiers.KeyVault to be "+keyvaultResourceID+", but got %q", testSubject.ResourceIdentifiers.KeyVault)
}
if opInsightsResourceID != testSubject.ResourceIdentifiers.OperationalInsights {
t.Errorf("Expected ResourceIdentifiers.OperationalInsights to be "+opInsightsResourceID+", but got %q", testSubject.ResourceIdentifiers.OperationalInsights)
}
}

func TestRoundTripSerialization(t *testing.T) {
Expand All @@ -278,6 +315,13 @@ func TestRoundTripSerialization(t *testing.T) {
ServiceManagementVMDNSSuffix: "--asm-vm-dns-suffix--",
ResourceManagerVMDNSSuffix: "--arm-vm-dns-suffix--",
ContainerRegistryDNSSuffix: "--container-registry-dns-suffix--",
ResourceIdentifiers: ResourceIdentifier{
Batch: batchResourceID,
Datalake: datalakeResourceID,
Graph: graphResourceID,
KeyVault: keyvaultResourceID,
OperationalInsights: opInsightsResourceID,
},
}

bytes, err := json.Marshal(env)
Expand Down Expand Up @@ -345,4 +389,19 @@ func TestRoundTripSerialization(t *testing.T) {
if env.ContainerRegistryDNSSuffix != testSubject.ContainerRegistryDNSSuffix {
t.Errorf("Expected ContainerRegistryDNSSuffix to be %q, but got %q", env.ContainerRegistryDNSSuffix, testSubject.ContainerRegistryDNSSuffix)
}
if env.ResourceIdentifiers.Batch != testSubject.ResourceIdentifiers.Batch {
t.Errorf("Expected ResourceIdentifiers.Batch to be %q, but got %q", env.ResourceIdentifiers.Batch, testSubject.ResourceIdentifiers.Batch)
}
if env.ResourceIdentifiers.Datalake != testSubject.ResourceIdentifiers.Datalake {
t.Errorf("Expected ResourceIdentifiers.Datalake to be %q, but got %q", env.ResourceIdentifiers.Datalake, testSubject.ResourceIdentifiers.Datalake)
}
if env.ResourceIdentifiers.Graph != testSubject.ResourceIdentifiers.Graph {
t.Errorf("Expected ResourceIdentifiers.Graph to be %q, but got %q", env.ResourceIdentifiers.Graph, testSubject.ResourceIdentifiers.Graph)
}
if env.ResourceIdentifiers.KeyVault != testSubject.ResourceIdentifiers.KeyVault {
t.Errorf("Expected ResourceIdentifiers.KeyVault to be %q, but got %q", env.ResourceIdentifiers.KeyVault, testSubject.ResourceIdentifiers.KeyVault)
}
if env.ResourceIdentifiers.OperationalInsights != testSubject.ResourceIdentifiers.OperationalInsights {
t.Errorf("Expected ResourceIdentifiers.OperationalInsights to be %q, but got %q", env.ResourceIdentifiers.OperationalInsights, testSubject.ResourceIdentifiers.OperationalInsights)
}
}
9 changes: 8 additions & 1 deletion autorest/azure/testdata/test_environment_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@
"serviceManagementVMDNSSuffix": "--asm-vm-dns-suffix--",
"resourceManagerVMDNSSuffix": "--arm-vm-dns-suffix--",
"containerRegistryDNSSuffix": "--container-registry-dns-suffix--",
"tokenAudience": "--token-audience"
"tokenAudience": "--token-audience",
"resourceIdentifiers": {
"batch": "--batch-resource-id--",
"datalake": "--datalake-resource-id--",
"graph": "--graph-resource-id--",
"keyVault": "--keyvault-resource-id--",
"operationalInsights": "--operational-insights-resource-id--"
}
}
2 changes: 1 addition & 1 deletion autorest/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"runtime"
)

const number = "v11.8.0"
const number = "v11.9.0"

var (
userAgent = fmt.Sprintf("Go/%s (%s-%s) go-autorest/%s",
Expand Down

0 comments on commit 562d376

Please sign in to comment.