本文整理汇总了C#中Microsoft.Azure.Common.Authentication.Models.AzureEnvironment.GetEndpointAsUri方法的典型用法代码示例。如果您正苦于以下问题:C# AzureEnvironment.GetEndpointAsUri方法的具体用法?C# AzureEnvironment.GetEndpointAsUri怎么用?C# AzureEnvironment.GetEndpointAsUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Common.Authentication.Models.AzureEnvironment
的用法示例。
在下文中一共展示了AzureEnvironment.GetEndpointAsUri方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSubscriptionCertificateCredentials
public static IHDInsightSubscriptionCredentials GetSubscriptionCertificateCredentials(this IAzureHDInsightCommonCommandBase command,
AzureSubscription currentSubscription, AzureAccount azureAccount, AzureEnvironment environment)
{
return new HDInsightCertificateCredential
{
SubscriptionId = currentSubscription.Id,
Certificate = AzureSession.DataStore.GetCertificate(currentSubscription.Account),
Endpoint = environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement),
};
}
示例2: ListSubscriptionsForTenant
private IEnumerable<AzureSubscription> ListSubscriptionsForTenant(AzureAccount account, AzureEnvironment environment,
SecureString password, ShowDialog promptBehavior, string tenantId)
{
IAccessToken accessToken = null;
try
{
accessToken = AcquireAccessToken(account, environment, tenantId, password, promptBehavior);
}
catch
{
WriteWarningMessage(string.Format(Microsoft.Azure.Commands.Profile.Properties.Resources.UnableToAqcuireToken, tenantId));
return new List<AzureSubscription>();
}
using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient<SubscriptionClient>(
new TokenCloudCredentials(accessToken.AccessToken),
environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)))
{
var subscriptions = subscriptionClient.Subscriptions.List();
if (subscriptions != null && subscriptions.Subscriptions != null)
{
return
subscriptions.Subscriptions.Select(
(s) =>
s.ToAzureSubscription(new AzureContext(_profile.Context.Subscription, account,
environment, CreateTenantFromString(tenantId, accessToken.TenantId))));
}
return new List<AzureSubscription>();
}
}
示例3: ListAccountTenants
private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironment environment, SecureString password, ShowDialog promptBehavior)
{
List<AzureTenant> result = new List<AzureTenant>();
try
{
var commonTenantToken = AcquireAccessToken(account, environment, AuthenticationFactory.CommonAdTenant,
password, promptBehavior);
using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient<SubscriptionClient>(
new TokenCloudCredentials(commonTenantToken.AccessToken),
environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)))
{
//TODO: Fix subscription client to not require subscriptionId
result = account.MergeTenants(subscriptionClient.Tenants.List().TenantIds, commonTenantToken);
}
}
catch
{
WriteWarningMessage(string.Format(Microsoft.Azure.Commands.Profile.Properties.Resources.UnableToAqcuireToken, AuthenticationFactory.CommonAdTenant));
if (account.IsPropertySet(AzureAccount.Property.Tenants))
{
result =
account.GetPropertyAsArray(AzureAccount.Property.Tenants)
.Select( ti => {
var tenant = new AzureTenant();
Guid guid;
if(Guid.TryParse(ti, out guid))
{
tenant.Id = guid;
tenant.Domain = AccessTokenExtensions.GetDomain(account.Id);
}
else
{
tenant.Domain = ti;
}
return tenant;
}).ToList();
}
}
return result;
}
示例4: TryGetTenantSubscription
private bool TryGetTenantSubscription(IAccessToken accessToken,
AzureAccount account,
AzureEnvironment environment,
string tenantId,
string subscriptionId,
string subscriptionName,
out AzureSubscription subscription,
out AzureTenant tenant)
{
using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient<SubscriptionClient>(
new TokenCloudCredentials(accessToken.AccessToken),
environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)))
{
Subscriptions.Models.Subscription subscriptionFromServer = null;
try
{
if (subscriptionId != null)
{
subscriptionFromServer = subscriptionClient.Subscriptions.Get(subscriptionId).Subscription;
}
else
{
var subscriptions = (subscriptionClient.Subscriptions.List().Subscriptions ??
new List<Microsoft.Azure.Subscriptions.Models.Subscription>())
.Where(s => "enabled".Equals(s.State, StringComparison.OrdinalIgnoreCase) ||
"warned".Equals(s.State, StringComparison.OrdinalIgnoreCase));
if (subscriptions.Any())
{
if (subscriptionName != null)
{
subscriptionFromServer = subscriptions.FirstOrDefault(
s => s.DisplayName.Equals(subscriptionName, StringComparison.OrdinalIgnoreCase));
}
else
{
if (subscriptions.Count() > 1)
{
WriteWarningMessage(string.Format(
"TenantId '{0}' contains more than one active subscription. First one will be selected for further use. " +
"To select another subscription, use Set-AzureRmContext.",
tenantId));
}
subscriptionFromServer = subscriptions.First();
}
}
}
}
catch (CloudException ex)
{
WriteWarningMessage(ex.Message);
}
if (subscriptionFromServer != null)
{
subscription = new AzureSubscription
{
Id = new Guid(subscriptionFromServer.SubscriptionId),
Account = accessToken.UserId,
Environment = environment.Name,
Name = subscriptionFromServer.DisplayName,
Properties = new Dictionary<AzureSubscription.Property, string> { { AzureSubscription.Property.Tenants, accessToken.TenantId } }
};
tenant = new AzureTenant();
tenant.Id = new Guid(accessToken.TenantId);
tenant.Domain = accessToken.GetDomain();
return true;
}
subscription = null;
if (accessToken != null && accessToken.TenantId != null)
{
tenant = new AzureTenant();
tenant.Id = Guid.Parse(accessToken.TenantId);
if (accessToken.UserId != null)
{
var domain = accessToken.UserId.Split(new[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
if (domain.Length == 2)
{
tenant.Domain = domain[1];
}
}
return true;
}
tenant = null;
return false;
}
}
示例5: ListServiceManagementSubscriptions
private IEnumerable<AzureSubscription> ListServiceManagementSubscriptions(AzureAccount account, AzureEnvironment environment, SecureString password, ShowDialog promptBehavior, string[] tenants)
{
List<AzureSubscription> result = new List<AzureSubscription>();
if (!environment.IsEndpointSet(AzureEnvironment.Endpoint.ServiceManagement))
{
return result;
}
foreach (var tenant in tenants)
{
try
{
var tenantAccount = new AzureAccount();
CopyAccount(account, tenantAccount);
var tenantToken = AzureSession.AuthenticationFactory.Authenticate(tenantAccount, environment, tenant, password, ShowDialog.Never);
if (string.Equals(tenantAccount.Id, account.Id, StringComparison.InvariantCultureIgnoreCase))
{
tenantAccount = account;
}
tenantAccount.SetOrAppendProperty(AzureAccount.Property.Tenants, new string[] { tenant });
using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient<SubscriptionClient>(
new TokenCloudCredentials(tenantToken.AccessToken),
environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement)))
{
var subscriptionListResult = subscriptionClient.Subscriptions.List();
foreach (var subscription in subscriptionListResult.Subscriptions)
{
// only add the subscription if it's actually in this tenant
if (subscription.ActiveDirectoryTenantId == tenant)
{
AzureSubscription psSubscription = new AzureSubscription
{
Id = new Guid(subscription.SubscriptionId),
Name = subscription.SubscriptionName,
Environment = environment.Name
};
psSubscription.SetProperty(AzureSubscription.Property.Tenants,
subscription.ActiveDirectoryTenantId);
psSubscription.Account = tenantAccount.Id;
tenantAccount.SetOrAppendProperty(AzureAccount.Property.Subscriptions,
new string[] { psSubscription.Id.ToString() });
result.Add(psSubscription);
}
}
}
AddOrSetAccount(tenantAccount);
}
catch (CloudException cEx)
{
WriteOrThrowAadExceptionMessage(cEx);
}
catch (AadAuthenticationException aadEx)
{
WriteOrThrowAadExceptionMessage(aadEx);
}
}
return result;
}
示例6: LoadAccountTenants
private string[] LoadAccountTenants(AzureAccount account, AzureEnvironment environment, SecureString password, ShowDialog promptBehavior)
{
var commonTenantToken = AzureSession.AuthenticationFactory.Authenticate(account, environment,
AuthenticationFactory.CommonAdTenant, password, promptBehavior);
using (SubscriptionClient SubscriptionClient = AzureSession.ClientFactory
.CreateCustomClient<SubscriptionClient>(
new TokenCloudCredentials(commonTenantToken.AccessToken),
environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement)))
{
var subscriptionListResult = SubscriptionClient.Subscriptions.List();
return subscriptionListResult.Subscriptions.Select(s => s.ActiveDirectoryTenantId).Distinct().ToArray();
}
}
示例7: ListSubscriptionsForTenant
private IEnumerable<AzureSubscription> ListSubscriptionsForTenant(AzureAccount account, AzureEnvironment environment,
SecureString password, ShowDialog promptBehavior, string tenantId)
{
var accessToken = AcquireAccessToken(account, environment, tenantId, password, promptBehavior);
using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient<SubscriptionClient>(
new TokenCloudCredentials(accessToken.AccessToken),
environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)))
{
var subscriptions = subscriptionClient.Subscriptions.List();
if (subscriptions != null && subscriptions.Subscriptions != null)
{
return
subscriptions.Subscriptions.Select(
(s) =>
s.ToAzureSubscription(new AzureContext(_profile.Context.Subscription, account,
environment, CreateTenantFromString(tenantId))));
}
return new List<AzureSubscription>();
}
}
示例8: ListAccountTenants
private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironment environment, SecureString password, ShowDialog promptBehavior)
{
var commonTenantToken = AcquireAccessToken(account, environment, AuthenticationFactory.CommonAdTenant,
password, promptBehavior);
using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient<SubscriptionClient>(
new TokenCloudCredentials(commonTenantToken.AccessToken),
environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)))
{
return subscriptionClient.Tenants.List().TenantIds
.Select(ti => new AzureTenant() { Id = new Guid(ti.TenantId), Domain = commonTenantToken.GetDomain() })
.ToList();
}
}
示例9: TryGetTenantSubscription
private bool TryGetTenantSubscription(IAccessToken accessToken,
AzureAccount account,
AzureEnvironment environment,
string tenantId,
string subscriptionId,
string subscriptionName,
out AzureSubscription subscription,
out AzureTenant tenant)
{
using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient<SubscriptionClient>(
new TokenCloudCredentials(accessToken.AccessToken),
environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)))
{
Subscriptions.Models.Subscription subscriptionFromServer = null;
try
{
if (subscriptionId != null)
{
subscriptionFromServer = subscriptionClient.Subscriptions.Get(subscriptionId).Subscription;
}
else
{
var subscriptions = subscriptionClient.Subscriptions.List().Subscriptions;
if (subscriptions != null && subscriptions.Any())
{
if (subscriptionName != null)
{
subscriptionFromServer = subscriptions.FirstOrDefault(s => s.DisplayName.Equals(subscriptionName, StringComparison.OrdinalIgnoreCase));
}
else
{
if (subscriptions.Count > 1)
{
WriteWarningMessage(string.Format(
"Tenant '{0}' contains more than one subscription. First one will be selected for further use. " +
"To select another subscription, use Set-AzureRmContext.",
tenantId));
}
subscriptionFromServer = subscriptions.First();
}
}
}
}
catch (CloudException ex)
{
WriteWarningMessage(ex.Message);
}
if (subscriptionFromServer != null)
{
subscription = new AzureSubscription
{
Id = new Guid(subscriptionFromServer.SubscriptionId),
Account = accessToken.UserId,
Environment = environment.Name,
Name = subscriptionFromServer.DisplayName,
Properties = new Dictionary<AzureSubscription.Property, string> { { AzureSubscription.Property.Tenants, accessToken.TenantId } }
};
account.Properties[AzureAccount.Property.Tenants] = accessToken.TenantId;
tenant = new AzureTenant();
tenant.Id = new Guid(accessToken.TenantId);
tenant.Domain = accessToken.GetDomain();
return true;
}
subscription = null;
tenant = null;
return false;
}
}
示例10: MainAsync
static async Task MainAsync()
{
// Set Environment - Choose between Azure public cloud, china cloud and US govt. cloud
_environment = AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud];
// Get the credentials
TokenCloudCredentials cloudCreds = GetCredsFromServicePrincipal();
var tokenCreds = new TokenCredentials(cloudCreds.Token);
var loggingHandler = new LoggingHandler(new HttpClientHandler());
// Create our own HttpClient so we can do logging
var httpClient = new HttpClient(loggingHandler);
// Use the creds to create the clients we need
_resourceGroupClient = new ResourceManagementClient(cloudCreds, _environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager), httpClient);
_websiteClient = new WebSiteManagementClient(_environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager), tokenCreds, loggingHandler);
_websiteClient.SubscriptionId = cloudCreds.SubscriptionId;
await ListResourceGroupsAndSites();
// Note: site names are globally unique, so you may need to change it to avoid conflicts
await CreateSite("MyResourceGroup", "MyAppServicePlan", "SampleSiteFromAPI", "West US");
// Upload certificate to resource group
await UpdateLoadCertificate("MyResourceGroup", "CertificateName", "West US", "PathToPfxFile", "CertificatePassword");
}