Skip to content

Commit

Permalink
Merge pull request #1 from markcowl/fixopindata
Browse files Browse the repository at this point in the history
Update common code changes for new operational insights endpoint
  • Loading branch information
csuich2 authored Jan 18, 2018
2 parents 489af88 + d21e254 commit d77071e
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 196 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ public static class AzureEnvironmentConstants
/// <summary>
/// The token audience for Log Analytics Queries
/// </summary>
public const string AzureOperationalInsightsServiceEndpointResourceId = "https://api.loganalytics.io";
public const string AzureOperationalInsightsEndpointResourceId = "https://api.loganalytics.io";

/// <summary>
/// The endpoint URI for Log Analytics Queries
/// </summary>
public const string AzureOperationalInsightsServiceEndpoint = "https://api.loganalytics.io/v1";
public const string AzureOperationalInsightsEndpoint = "https://api.loganalytics.io/v1";

/// <summary>
/// The domain name suffix for Azure DataLake services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ public static bool TryGetEndpointUrl(this IAzureEnvironment environment, string
case AzureEnvironment.Endpoint.BatchEndpointResourceId:
endpoint = new Uri(environment.BatchEndpointResourceId);
break;
case AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId:
endpoint = new Uri(environment.AzureOperationalInsightsEndpointResourceId);
break;
case AzureEnvironment.Endpoint.AzureOperationalInsightsEndpoint:
endpoint = new Uri(environment.AzureOperationalInsightsEndpoint);
break;
default:
result = false;
result = environment.IsPropertySet(endpointName);
if (result)
{
endpoint = new Uri(environment.GetProperty(endpointName));
}
break;
}

Expand Down Expand Up @@ -153,13 +151,9 @@ public static bool TryGetEndpointString(this IAzureEnvironment environment, stri
case AzureEnvironment.Endpoint.BatchEndpointResourceId:
propertyValue = environment.BatchEndpointResourceId;
break;
case AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId:
propertyValue = environment.AzureOperationalInsightsEndpointResourceId;
break;
case AzureEnvironment.Endpoint.AzureOperationalInsightsEndpoint:
propertyValue = environment.AzureOperationalInsightsEndpoint;
break;
default:
// get property from the extended properties of the environment
propertyValue = environment.GetProperty(endpointName);
break;
}
}
Expand Down Expand Up @@ -271,11 +265,11 @@ public static void SetEndpoint(this IAzureEnvironment environment, string endpoi
case AzureEnvironment.Endpoint.ServiceManagement:
environment.ServiceManagementUrl = propertyValue;
break;
case AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId:
environment.AzureOperationalInsightsEndpointResourceId = propertyValue;
case AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId:
environment.SetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId, propertyValue);
break;
case AzureEnvironment.Endpoint.AzureOperationalInsightsEndpoint:
environment.AzureOperationalInsightsEndpoint= propertyValue;
case AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint:
environment.SetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, propertyValue);
break;
}
}
Expand All @@ -289,20 +283,28 @@ public static void SetEndpoint(this IAzureEnvironment environment, string endpoi
/// <returns>The correct token audience for tokens bound for the given endpoint.</returns>
public static string GetTokenAudience(this IAzureEnvironment environment, string targetEndpoint)
{
string resource = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId;
if (targetEndpoint == AzureEnvironment.Endpoint.Graph)
string resource;
switch (targetEndpoint)
{
resource = AzureEnvironment.Endpoint.GraphEndpointResourceId;
}
else if (targetEndpoint == AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix ||
targetEndpoint == AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix ||
targetEndpoint == AzureEnvironment.Endpoint.DataLakeEndpointResourceId)
{
resource = AzureEnvironment.Endpoint.DataLakeEndpointResourceId;
}
else if (targetEndpoint == AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId)
{
resource = AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId;
case AzureEnvironment.Endpoint.Graph:
resource = AzureEnvironment.Endpoint.GraphEndpointResourceId;
break;
case AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix:
case AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix:
case AzureEnvironment.Endpoint.DataLakeEndpointResourceId:
resource = AzureEnvironment.Endpoint.DataLakeEndpointResourceId;
break;
case AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix:
case AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId:
resource = AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId;
break;
case AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint:
case AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId:
resource = AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId;
break;
default:
resource = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId;
break;
}

return resource;
Expand Down Expand Up @@ -482,14 +484,6 @@ public static void CopyFrom(this IAzureEnvironment environment, IAzureEnvironmen
{
environment.BatchEndpointResourceId = other.BatchEndpointResourceId;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId))
{
environment.AzureOperationalInsightsEndpointResourceId = other.AzureOperationalInsightsEndpointResourceId;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.AzureOperationalInsightsEndpoint))
{
environment.AzureOperationalInsightsEndpoint= other.AzureOperationalInsightsEndpoint;
}

environment.VersionProfiles.Clear();
foreach (var profile in other.VersionProfiles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,6 @@ public interface IAzureEnvironment : IExtensibleModel
/// </summary>
string AzureDataLakeStoreFileSystemEndpointSuffix { get; set; }

/// <summary>
/// The token audience required for communicating with the Azure Log Analytics query service in this environment
/// </summary>
string AzureOperationalInsightsEndpointResourceId { get; set; }

/// <summary>
/// The endpoint to use when communicating with the Azure Log Analytics query service in this environment
/// </summary>
string AzureOperationalInsightsEndpoint { get; set; }

/// <summary>
/// The default Active Directory Tenant
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,32 @@ public bool OnPremise
/// <summary>
/// The token audience required for communicating with the Azure Log Analytics query service in this environment
/// </summary>
public string AzureOperationalInsightsEndpointResourceId { get; set; }
public string AzureOperationalInsightsEndpointResourceId
{
get
{
return this.GetEndpoint(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId);
}
set
{
this.SetEndpoint(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId, value);
}
}

/// <summary>
/// The endpoint to use when communicating with the Azure Log Analytics query service in this environment
/// </summary>
public string AzureOperationalInsightsEndpoint { get; set; }
public string AzureOperationalInsightsEndpoint
{
get
{
return this.GetEndpoint(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint);
}
set
{
this.SetEndpoint(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, value);
}
}

public IList<string> VersionProfiles { get; } = new List<string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal OperationalInsightsDataClient OperationalInsightsDataClient
}
else
{
clientCredentials = AzureSession.Instance.AuthenticationFactory.GetServiceClientCredentials(DefaultContext, "AzureOperationalInsightsEndpointResourceId");
clientCredentials = AzureSession.Instance.AuthenticationFactory.GetServiceClientCredentials(DefaultContext, AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint);
}

this._operationalInsightsDataClient =
Expand All @@ -74,7 +74,7 @@ internal OperationalInsightsDataClient OperationalInsightsDataClient

Uri targetUri= null;
DefaultContext.Environment.TryGetEndpointUrl(
AzureEnvironment.Endpoint.AzureOperationalInsightsEndpoint, out targetUri);
AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, out targetUri);
if (targetUri == null)
{
throw new Exception("Operational Insights is not supported in this Azure Environment");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ public void ProfileSerializeDeserializeWorks()
Name = "testCloud",
ActiveDirectoryAuthority = "http://contoso.com"
};
environment.SetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, "http://contoso.io");
environment.SetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId, "http://insights.contoso.io/");
var account = new AzureAccount
{
Id = "[email protected]",
Expand Down Expand Up @@ -713,6 +715,10 @@ public void ProfileSerializeDeserializeWorks()
var jCurrentProfile = currentProfile.ToString();
var jDeserializedProfile = deserializedProfile.ToString();
Assert.Equal(jCurrentProfile, jDeserializedProfile);
Assert.True(deserializedProfile.DefaultContext.Environment.IsPropertySet(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint));
Assert.True(deserializedProfile.DefaultContext.Environment.IsPropertySet(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId));
Assert.Equal("http://contoso.io", deserializedProfile.DefaultContext.Environment.GetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint));
Assert.Equal("http://insights.contoso.io/", deserializedProfile.DefaultContext.Environment.GetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId));
}

[Fact]
Expand Down Expand Up @@ -743,11 +749,12 @@ public void SavingProfileWorks()
""BatchEndpointResourceId"": null,
""AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix"": null,
""AzureDataLakeStoreFileSystemEndpointSuffix"": null,
""AzureOperationalInsightsEndpointResourceId"": null,
""AzureOperationalInsightsEndpoint"": null,
""AdTenant"": null,
""VersionProfiles"": [],
""ExtendedProperties"": {}
""ExtendedProperties"": {
""OperationalInsightsEndpoint"": ""http://contoso.io"",
""OperationalInsightsEndpointResourceId"": ""http://insights.contoso.io/""
}
}
},
""Contexts"": {
Expand Down Expand Up @@ -797,11 +804,12 @@ public void SavingProfileWorks()
""BatchEndpointResourceId"": null,
""AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix"": null,
""AzureDataLakeStoreFileSystemEndpointSuffix"": null,
""AzureOperationalInsightsEndpointResourceId"": null,
""AzureOperationalInsightsEndpoint"": null,
""AdTenant"": null,
""VersionProfiles"": [],
""ExtendedProperties"": {}
""ExtendedProperties"": {
""OperationalInsightsEndpoint"": ""http://contoso.io"",
""OperationalInsightsEndpointResourceId"": ""http://insights.contoso.io/""
}
},
""VersionProfile"": null,
""TokenCache"": {
Expand All @@ -822,6 +830,8 @@ public void SavingProfileWorks()
Name = "testCloud",
ActiveDirectoryAuthority = "http://contoso.com"
};
environment.SetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, "http://contoso.io");
environment.SetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId, "http://insights.contoso.io/");
var account = new AzureAccount
{
Id = "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public void CanConvertValidEnvironments(string name, bool onPremise, string acti
environment.TrafficManagerDnsSuffix);
CheckEndpoint(AzureEnvironment.Endpoint.BatchEndpointResourceId, azEnvironment,
environment.BatchEndpointResourceId);
CheckEndpoint(AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId, azEnvironment,
CheckEndpoint(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId, azEnvironment,
environment.AzureOperationalInsightsEndpointResourceId);
CheckEndpoint(AzureEnvironment.Endpoint.AzureOperationalInsightsEndpoint, azEnvironment,
CheckEndpoint(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, azEnvironment,
environment.AzureOperationalInsightsEndpoint);
Assert.Equal(azEnvironment.Name, environment.Name);
Assert.Equal(azEnvironment.OnPremise, environment.EnableAdfsAuthentication);
Expand Down Expand Up @@ -161,8 +161,8 @@ public void CanConvertNullPSEnvironments()
Assert.False(environment.IsEndpointSet(AzureEnvironment.Endpoint.StorageEndpointSuffix));
Assert.False(environment.IsEndpointSet(AzureEnvironment.Endpoint.TrafficManagerDnsSuffix));
Assert.False(environment.IsEndpointSet(AzureEnvironment.Endpoint.BatchEndpointResourceId));
Assert.False(environment.IsEndpointSet(AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId));
Assert.False(environment.IsEndpointSet(AzureEnvironment.Endpoint.AzureOperationalInsightsEndpoint));
Assert.False(environment.IsEndpointSet(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId));
Assert.False(environment.IsEndpointSet(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint));
}
[Theory]
[InlineData("TestAll", true, "https://login.microsoftonline.com", "https://management.core.windows.net/",
Expand Down Expand Up @@ -247,9 +247,9 @@ public void CanConvertValidPSEnvironments(string name, bool onPremise, string ac
environment.TrafficManagerDnsSuffix);
CheckEndpoint(AzureEnvironment.Endpoint.BatchEndpointResourceId, azEnvironment,
environment.BatchEndpointResourceId);
CheckEndpoint(AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId, azEnvironment,
CheckEndpoint(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId, azEnvironment,
environment.AzureOperationalInsightsEndpointResourceId);
CheckEndpoint(AzureEnvironment.Endpoint.AzureOperationalInsightsEndpoint, azEnvironment,
CheckEndpoint(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, azEnvironment,
environment.AzureOperationalInsightsEndpoint);
Assert.Equal(azEnvironment.Name, environment.Name);
Assert.Equal(azEnvironment.OnPremise, environment.EnableAdfsAuthentication);
Expand Down Expand Up @@ -302,9 +302,9 @@ private AzureEnvironment CreateEnvironment(string name, bool onPremise, string a
trafficManagerSuffix);
CheckEndpoint(AzureEnvironment.Endpoint.BatchEndpointResourceId, environment,
batchResource);
CheckEndpoint(AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId, environment,
CheckEndpoint(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId, environment,
azureOperationalInsightsEndpointResourceId);
CheckEndpoint(AzureEnvironment.Endpoint.AzureOperationalInsightsEndpoint, environment,
CheckEndpoint(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, environment,
azureOperationalInsightsEndpoint);
return environment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ public override void ExecuteCmdlet()
nameof(DataLakeAudience));
SetEndpointIfBound(newEnvironment, AzureEnvironment.Endpoint.BatchEndpointResourceId,
nameof(BatchEndpointResourceId));
SetEndpointIfBound(newEnvironment, AzureEnvironment.Endpoint.AzureOperationalInsightsEndpointResourceId,
SetEndpointIfBound(newEnvironment, AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId,
nameof(AzureOperationalInsightsEndpointResourceId));
SetEndpointIfBound(newEnvironment, AzureEnvironment.Endpoint.AzureOperationalInsightsEndpoint,
SetEndpointIfBound(newEnvironment, AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint,
nameof(AzureOperationalInsightsEndpoint));
WriteObject(new PSAzureEnvironment(profileClient.AddOrSetEnvironment(newEnvironment)));
}
Expand Down
Loading

0 comments on commit d77071e

Please sign in to comment.