本文整理汇总了C#中Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext类的典型用法代码示例。如果您正苦于以下问题:C# AzureContext类的具体用法?C# AzureContext怎么用?C# AzureContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AzureContext类属于Microsoft.Azure.Commands.Common.Authentication.Models命名空间,在下文中一共展示了AzureContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetToken
private Tuple<IAccessToken, string> GetToken(IAuthenticationFactory authFactory, AzureContext context, AzureEnvironment.Endpoint resourceIdEndpoint)
{
if (context.Account == null)
throw new ArgumentException(KeyVaultProperties.Resources.ArmAccountNotFound);
if (context.Account.Type != AzureAccount.AccountType.User &&
context.Account.Type != AzureAccount.AccountType.ServicePrincipal)
throw new ArgumentException(string.Format(KeyVaultProperties.Resources.UnsupportedAccountType, context.Account.Type));
if (context.Subscription != null && context.Account != null)
TenantId = context.Subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants)
.Intersect(context.Account.GetPropertyAsArray(AzureAccount.Property.Tenants))
.FirstOrDefault();
if (string.IsNullOrWhiteSpace(TenantId) && context.Tenant != null && context.Tenant.Id != Guid.Empty)
TenantId = context.Tenant.Id.ToString();
if (string.IsNullOrWhiteSpace(TenantId))
throw new ArgumentException(KeyVaultProperties.Resources.NoTenantInContext);
try
{
var accesstoken = authFactory.Authenticate(context.Account, context.Environment, TenantId, null, ShowDialog.Auto,
resourceIdEndpoint);
return Tuple.Create(accesstoken, context.Environment.Endpoints[resourceIdEndpoint]);
}
catch (Exception ex)
{
throw new ArgumentException(KeyVaultProperties.Resources.InvalidSubscriptionState, ex);
}
}
示例2: ActiveDirectoryClient
/// <summary>
/// Creates new ActiveDirectoryClient using WindowsAzureSubscription.
/// </summary>
/// <param name="context"></param>
public ActiveDirectoryClient(AzureContext context)
{
GraphClient = AzureSession.ClientFactory.CreateArmClient<GraphRbacManagementClient>(
context, AzureEnvironment.Endpoint.Graph);
GraphClient.TenantID = context.Tenant.Id.ToString();
}
示例3: SetupTestEnvironment
private static RMProfileClient SetupTestEnvironment(List<string> tenants, params List<string>[] subscriptionLists)
{
AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(DefaultAccount,
Guid.NewGuid().ToString(), DefaultTenant.ToString());
var subscriptionList = new Queue<List<string>>(subscriptionLists);
var clientFactory = new MockSubscriptionClientFactory(tenants, subscriptionList);
var mock = new MockClientFactory(new List<object>
{
clientFactory.GetSubscriptionClient()
}, true);
mock.MoqClients = true;
AzureSession.ClientFactory = mock;
Context = new AzureContext(new AzureSubscription()
{
Account = DefaultAccount,
Environment = EnvironmentName.AzureCloud,
Id = DefaultSubscription,
Name = DefaultSubscriptionName
},
new AzureAccount() { Id = DefaultAccount, Type = AzureAccount.AccountType.User },
AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud],
new AzureTenant() { Domain = DefaultDomain, Id = DefaultTenant });
var profile = new AzureRMProfile();
profile.Context = Context;
return new RMProfileClient(profile);
}
示例4: AzureSqlDatabaseAdapter
/// <summary>
/// Constructs a database adapter
/// </summary>
/// <param name="profile">The current azure profile</param>
/// <param name="subscription">The current azure subscription</param>
public AzureSqlDatabaseAdapter(AzureContext context)
{
Context = context;
_subscription = context.Subscription;
Communicator = new AzureSqlDatabaseCommunicator(Context);
ElasticPoolCommunicator = new AzureSqlElasticPoolCommunicator(Context);
}
示例5: DelegatingHandlersAreCloned
public void DelegatingHandlersAreCloned()
{
string userAccount = "[email protected]";
Guid subscriptionId = Guid.NewGuid();
AzureContext context = new AzureContext
(
new AzureSubscription()
{
Account = userAccount,
Environment = "AzureCloud",
Id = subscriptionId,
Properties = new Dictionary<AzureSubscription.Property, string>() { { AzureSubscription.Property.Tenants, "common" } }
},
new AzureAccount()
{
Id = userAccount,
Type = AzureAccount.AccountType.User,
Properties = new Dictionary<AzureAccount.Property, string>() { { AzureAccount.Property.Tenants, "common" } }
},
AzureEnvironment.PublicEnvironments["AzureCloud"]
);
AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(userAccount, Guid.NewGuid().ToString());
var mockHandler = new MockDelegatingHandler();
var factory = new ClientFactory();
factory.AddHandler(mockHandler);
var client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
client = factory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
Assert.Equal(5, MockDelegatingHandler.cloneCount);
}
示例6: DetermineApiVersion
/// <summary>
/// Determines the API version.
/// </summary>
/// <param name="context">The azure profile.</param>
/// <param name="providerNamespace">The provider namespace.</param>
/// <param name="resourceType">The resource type.</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
internal static Task<string> DetermineApiVersion(AzureContext context, string providerNamespace, string resourceType, CancellationToken cancellationToken, bool? pre = null, Dictionary<string, string> cmdletHeaderValues = null)
{
var cacheKey = ApiVersionCache.GetCacheKey(providerNamespace: providerNamespace, resourceType: resourceType);
var apiVersions = ApiVersionCache.Instance
.AddOrGetExisting(cacheKey: cacheKey, getFreshData: () => ApiVersionHelper.GetApiVersionsForResourceType(
context,
providerNamespace: providerNamespace,
resourceType: resourceType,
cancellationToken: cancellationToken,
cmdletHeaderValues: cmdletHeaderValues));
apiVersions = apiVersions.CoalesceEnumerable().ToArray();
var apiVersionsToSelectFrom = apiVersions;
if (pre == null || pre == false)
{
apiVersionsToSelectFrom = apiVersions
.Where(apiVersion => apiVersion.IsDecimal(NumberStyles.AllowDecimalPoint) || apiVersion.IsDateTime("yyyy-mm-dd", DateTimeStyles.None))
.ToArray();
}
var selectedApiVersion = apiVersionsToSelectFrom.OrderByDescending(apiVersion => apiVersion).FirstOrDefault();
if (string.IsNullOrWhiteSpace(selectedApiVersion) && apiVersions.Any())
{
// fall back on pre-release APIs if they're the only ones available.
selectedApiVersion = apiVersions.OrderByDescending(apiVersion => apiVersion).FirstOrDefault();
}
var result = string.IsNullOrWhiteSpace(selectedApiVersion)
? Constants.DefaultApiVersion
: selectedApiVersion;
return Task.FromResult(result);
}
示例7: ActiveDirectoryClient
/// <summary>
/// Creates new ActiveDirectoryClient using WindowsAzureSubscription.
/// </summary>
/// <param name="context"></param>
public ActiveDirectoryClient(AzureContext context)
{
AccessTokenCredential creds = (AccessTokenCredential)AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(context, AzureEnvironment.Endpoint.Graph);
GraphClient = AzureSession.ClientFactory.CreateCustomClient<GraphRbacManagementClient>(
creds.TenantID,
creds,
context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.Graph));
}
示例8: ResourcesClient
/// <summary>
/// Creates new ResourceManagementClient
/// </summary>
/// <param name="context">Profile containing resources to manipulate</param>
public ResourcesClient(AzureContext context)
: this(
AzureSession.ClientFactory.CreateClient<ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager),
new GalleryTemplatesClient(context),
AzureSession.ClientFactory.CreateClient<AuthorizationManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager))
{
}
示例9: SqlThreatDetectionAdapter
public SqlThreatDetectionAdapter(AzureContext context)
{
Context = context;
Subscription = context.Subscription;
ThreatDetectionCommunicator = new ThreatDetectionEndpointsCommunicator(Context);
AzureCommunicator = new AzureEndpointsCommunicator(Context);
AuditingAdapter = new SqlAuditAdapter(context);
}
示例10: SqlAuditAdapter
public SqlAuditAdapter(AzureContext context)
{
Context = context;
Subscription = context.Subscription;
Communicator = new AuditingEndpointsCommunicator(Context);
AzureCommunicator = new AzureEndpointsCommunicator(Context);
IgnoreStorage = false;
}
示例11: AzureSqlDatabaseReplicationAdapter
/// <summary>
/// Constructs a database adapter
/// </summary>
/// <param name="profile">The current azure profile</param>
/// <param name="subscription">The current azure subscription</param>
public AzureSqlDatabaseReplicationAdapter(AzureContext context)
{
Context = context;
_subscription = context.Subscription;
ReplicationCommunicator = new AzureSqlDatabaseReplicationCommunicator(Context);
DatabaseCommunicator = new AzureSqlDatabaseCommunicator(Context);
ServerCommunicator = new AzureSqlServerCommunicator(Context);
}
示例12: DataMaskingEndpointsCommunicator
public DataMaskingEndpointsCommunicator(AzureContext context)
{
Context = context;
if (context.Subscription != Subscription)
{
Subscription = context.Subscription;
SqlClient = null;
}
}
示例13: AzureSqlDatabaseIndexRecommendationCommunicator
/// <summary>
/// Creates a communicator for Azure Sql Databases
/// </summary>
/// <param name="profile"></param>
/// <param name="subscription"></param>
public AzureSqlDatabaseIndexRecommendationCommunicator(AzureContext context)
{
Context = context;
if (context.Subscription != Subscription)
{
Subscription = context.Subscription;
SqlClient = null;
}
}
示例14: WebServicesClient
public WebServicesClient(AzureContext context)
{
this.apiClient = AzureSession.ClientFactory.
CreateArmClient<APIClient>(
context,
AzureEnvironment.Endpoint.ResourceManager);
this.apiClient.LongRunningOperationRetryTimeout =
WebServicesClient.AsyncOperationPollingIntervalSeconds;
}
示例15: AzureSqlDatabaseBackupCommunicator
/// <summary>
/// Creates a communicator for Azure Sql Database backup REST endpoints.
/// </summary>
/// <param name="profile">Azure profile</param>
/// <param name="subscription">Associated subscription</param>
public AzureSqlDatabaseBackupCommunicator(AzureContext context)
{
Context = context;
if (context.Subscription != Subscription)
{
Subscription = context.Subscription;
SqlClient = null;
}
}