void CopyProfile(AzureRmProfile source, IProfileOperations target) { if (source == null || target == null) { return; } foreach (var environment in source.Environments) { IAzureEnvironment merged; target.TrySetEnvironment(environment, out merged); } foreach (var context in source.Contexts) { target.TrySetContext(context.Key, context.Value); } if (!string.IsNullOrWhiteSpace(source.DefaultContextKey)) { target.TrySetDefaultContext(source.DefaultContextKey); } AzureRmProfileProvider.Instance.SetTokenCacheForProfile(target.ToProfile()); EnsureProtectedCache(target, source.DefaultContext?.TokenCache?.CacheData); }
void CopyProfile(AzureRmProfile source, IProfileOperations target) { if (source == null || target == null) { return; } foreach (var environment in source.Environments) { IAzureEnvironment merged; target.TrySetEnvironment(environment, out merged); } foreach (var context in source.Contexts) { target.TrySetContext(context.Key, context.Value); } if (!string.IsNullOrWhiteSpace(source.DefaultContextKey)) { target.TrySetDefaultContext(source.DefaultContextKey); } EnsureProtectedMsalCache(); }
/// <summary> /// Update a Traffic Manager profile. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group containing the Traffic /// Manager profile. /// </param> /// <param name='profileName'> /// Required. The name of the Traffic Manager profile. /// </param> /// <param name='parameters'> /// Required. The Traffic Manager profile parameters supplied to the /// Update operation. /// </param> /// <returns> /// Parameters supplied to update a Traffic Manager profile. /// </returns> public static ProfileUpdateResponse Update(this IProfileOperations operations, string resourceGroupName, string profileName, ProfileUpdateParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IProfileOperations)s).UpdateAsync(resourceGroupName, profileName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Deletes a profile and all of its definitions. This operation cannot /// be reverted. (see /// http://msdn.microsoft.com/en-us/library/hh758256.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='profileName'> /// Required. The name of the profile. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static AzureOperationResponse Delete(this IProfileOperations operations, string profileName) { return(Task.Factory.StartNew((object s) => { return ((IProfileOperations)s).DeleteAsync(profileName); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Returns all profiles owned by a subscription. (see /// http://msdn.microsoft.com/en-us/library/hh758249.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <returns> /// The List Profiles operation response. /// </returns> public static ProfilesListResponse List(this IProfileOperations operations) { return(Task.Factory.StartNew((object s) => { return ((IProfileOperations)s).ListAsync(); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Enables or disables a profile. (see /// http://msdn.microsoft.com/en-us/library/hh758250.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='profileName'> /// Required. The name of the profile. /// </param> /// <param name='profileStatus'> /// Required. Specifies whether the profile should be enabled or /// disabled. /// </param> /// <param name='definitionVersionNumber'> /// Required. Version of the definition associated with the profile /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static AzureOperationResponse Update(this IProfileOperations operations, string profileName, ProfileDefinitionStatus profileStatus, int definitionVersionNumber) { return(Task.Factory.StartNew((object s) => { return ((IProfileOperations)s).UpdateAsync(profileName, profileStatus, definitionVersionNumber); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// The DNS name that you want to use. You must include /// .trafficmanager.net in the name. (see /// http://msdn.microsoft.com/en-us/library/dn510368.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='dnsName'> /// Required. DNS name that you want to use /// </param> /// <returns> /// The response to the request for a listing of namespaces. /// </returns> public static DnsPrefixAvailabilityCheckResponse CheckDnsPrefixAvailability(this IProfileOperations operations, string dnsName) { return(Task.Factory.StartNew((object s) => { return ((IProfileOperations)s).CheckDnsPrefixAvailabilityAsync(dnsName); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Lists all Traffic Manager profiles within a resource group. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group containing the Traffic /// Manager profiles to be listed. /// </param> /// <returns> /// The response to a Traffic Manager profile 'ListAll' or /// 'ListAllInResourceGroup' operation. /// </returns> public static ProfileListResponse ListAllInResourceGroup(this IProfileOperations operations, string resourceGroupName) { return(Task.Factory.StartNew((object s) => { return ((IProfileOperations)s).ListAllInResourceGroupAsync(resourceGroupName); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
private void InitSubApis() { this.communicationOperations = new CommunicationTemplate(this.RestTemplate); this.connectionOperations = new ConnectionTemplate(this.RestTemplate); this.profileOperations = new ProfileTemplate(this.RestTemplate); #if NET_4_0 || SILVERLIGHT_5 this.groupOperations = new GroupTemplate(this.RestTemplate); #endif }
/// <summary> /// Initializes a new instance of the TrafficManagerManagementClient /// class. /// </summary> /// <param name='httpClient'> /// The Http client /// </param> public TrafficManagerManagementClient(HttpClient httpClient) : base(httpClient) { this._profiles = new ProfileOperations(this); this._apiVersion = "2015-04-28-preview"; this._longRunningOperationInitialTimeout = -1; this._longRunningOperationRetryTimeout = -1; this.HttpClient.Timeout = TimeSpan.FromSeconds(300); }
/// <summary> /// Initializes a new instance of the TrafficManagerManagementClient /// class. /// </summary> public TrafficManagerManagementClient() : base() { this._endpoints = new EndpointOperations(this); this._profiles = new ProfileOperations(this); this._apiVersion = "2015-11-01"; this._longRunningOperationInitialTimeout = -1; this._longRunningOperationRetryTimeout = -1; this.HttpClient.Timeout = TimeSpan.FromSeconds(300); }
/// <summary> /// Initializes a new instance of the TrafficManagerManagementClient /// class. /// </summary> /// <param name='httpClient'> /// The Http client /// </param> private TrafficManagerManagementClient(HttpClient httpClient) : base(httpClient) { this._definitions = new DefinitionOperations(this); this._profiles = new ProfileOperations(this); this._apiVersion = "2011-10-01"; this._longRunningOperationInitialTimeout = -1; this._longRunningOperationRetryTimeout = -1; this.HttpClient.Timeout = TimeSpan.FromSeconds(300); }
/// <summary> /// Initializes a new instance of the TrafficManagerManagementClient /// class. /// </summary> /// <param name='httpClient'> /// The Http client /// </param> public TrafficManagerManagementClient(HttpClient httpClient) : base(httpClient) { this._endpoints = new EndpointOperations(this); this._geographicHierarchy = new GeographicHierarchyOperations(this); this._profiles = new ProfileOperations(this); this._apiVersion = "2017-03-01"; this._longRunningOperationInitialTimeout = -1; this._longRunningOperationRetryTimeout = -1; this.HttpClient.Timeout = TimeSpan.FromSeconds(300); }
public RMProfileClient(IProfileOperations profile) { _profile = profile; var context = _profile.DefaultContext; _cache = AzureSession.Instance.TokenCache; if (_profile != null && context != null && context.TokenCache != null) { _cache = context.TokenCache; } }
public RMProfileClient(IProfileOperations profile) { _profile = profile; var context = _profile.DefaultContext; _cache = AzureSession.Instance.TokenCache; if (_profile != null && context != null && context.TokenCache != null) { _cache = context.TokenCache; } SubscriptionAndTenantClient = new SubscriptionClientProxy(t => WriteWarningMessage(t)); }
void CopyProfile(AzureRmProfile source, IProfileOperations target) { if (source == null || target == null) { return; } foreach (var environment in source.Environments) { IAzureEnvironment merged; target.TrySetEnvironment(environment, out merged); } if (!AzureSession.Instance.TryGetComponent(AzKeyStore.Name, out AzKeyStore keyStore)) { keyStore = null; } foreach (var context in source.Contexts) { target.TrySetContext(context.Key, context.Value); if (keyStore != null) { var account = context.Value.Account; if (account != null) { var secret = account.GetProperty(AzureAccount.Property.ServicePrincipalSecret); if (!string.IsNullOrEmpty(secret)) { keyStore.SaveKey(new ServicePrincipalKey(AzureAccount.Property.ServicePrincipalSecret, account.Id, context.Value.Tenant?.Id) , secret.ConvertToSecureString()); } var password = account.GetProperty(AzureAccount.Property.CertificatePassword); if (!string.IsNullOrEmpty(password)) { keyStore.SaveKey(new ServicePrincipalKey(AzureAccount.Property.CertificatePassword, account.Id, context.Value.Tenant?.Id) , password.ConvertToSecureString()); } } } } if (!string.IsNullOrWhiteSpace(source.DefaultContextKey)) { target.TrySetDefaultContext(source.DefaultContextKey); } EnsureProtectedMsalCache(); }
/// <summary> /// Get the default profile for the current cmdlet invocation /// </summary> /// <returns>The default profile, whether it is a process-specific profile, ot a profile for the current user</returns> protected virtual IProfileOperations GetDefaultProfile() { IProfileOperations result = null; var currentProfile = DefaultProfile as AzureRmProfile; switch (GetContextModificationScope()) { case ContextModificationScope.Process: result = currentProfile; break; case ContextModificationScope.CurrentUser: result = new AzureRmAutosaveProfile(currentProfile, ProtectedFileProvider.CreateFileProvider(Path.Combine(AzureSession.Instance.ARMProfileDirectory, AzureSession.Instance.ARMProfileFile), FileProtection.ExclusiveWrite)); break; } return(result); }
private void CompleteContextProcessing(IProfileOperations profile) { var context = profile.DefaultContext; if (context != null && context.Subscription != null && context.Subscription.State != null && !context.Subscription.State.Equals( "Enabled", StringComparison.OrdinalIgnoreCase)) { WriteWarning(string.Format( Resources.SelectedSubscriptionNotActive, context.Subscription.State)); } if (context != null) { if (MyInvocation.BoundParameters.ContainsKey(nameof(ExtendedProperty))) { foreach (var property in ExtendedProperty) { if (ShouldProcess(string.Format(Resources.ContextNameTarget, Name ?? "default"), string.Format(Resources.SetPropertyAction, property.Key, property.Value))) { context.SetProperty(property.Key, property.Value); } } } var psContext = new PSAzureContext(context); string name = Name; if (string.IsNullOrWhiteSpace(name)) { profile.TryFindContext(context, out name); } psContext.Name = name; WriteObject(psContext); } }
void EnsureProtectedCache(IProfileOperations profile, byte[] cacheData) { if (profile == null || cacheData == null) { return; } AzureRmAutosaveProfile autosave = profile as AzureRmAutosaveProfile; var protectedcache = AzureSession.Instance.TokenCache as ProtectedFileTokenCache; if (autosave != null && protectedcache == null && cacheData.Any()) { try { var cache = new ProtectedFileTokenCache(cacheData, AzureSession.Instance.DataStore); } catch { WriteWarning(Resources.ImportAuthenticationFailure); } } }
protected override void BeginProcessing() { _profile = new AzureRmAutosaveProfile( (DefaultProfile as AzureRmProfile), ProtectedFileProvider.CreateFileProvider( Path.Combine(AzureSession.Instance.ARMProfileDirectory, AzureSession.Instance.ARMProfileFile), FileProtection.ExclusiveWrite)); var context = _profile.DefaultContext; _cache = AzureSession.Instance.TokenCache; if (_profile != null && context != null && context.TokenCache != null) { _cache = context.TokenCache; } _environment = AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud]; if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password)) { _credential = new PSCredential(UserName, ConvertToSecureString(Password)); } base.BeginProcessing(); }
private void RemoveDefaultProperty(IProfileOperations profile) { var context = profile.DefaultContext; context.ExtendedProperties.Remove(Resources.DefaultResourceGroupKey); }
/// <summary> /// The DNS name that you want to use. You must include /// .trafficmanager.net in the name. (see /// http://msdn.microsoft.com/en-us/library/dn510368.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='dnsName'> /// Required. DNS name that you want to use /// </param> /// <returns> /// The response to the request for a listing of namespaces. /// </returns> public static Task <DnsPrefixAvailabilityCheckResponse> CheckDnsPrefixAvailabilityAsync(this IProfileOperations operations, string dnsName) { return(operations.CheckDnsPrefixAvailabilityAsync(dnsName, CancellationToken.None)); }
/// <summary> /// Enables or disables a profile. (see /// http://msdn.microsoft.com/en-us/library/hh758250.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='profileName'> /// Required. The name of the profile. /// </param> /// <param name='profileStatus'> /// Required. Specifies whether the profile should be enabled or /// disabled. /// </param> /// <param name='definitionVersionNumber'> /// Required. Version of the definition associated with the profile /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <AzureOperationResponse> UpdateAsync(this IProfileOperations operations, string profileName, ProfileDefinitionStatus profileStatus, int definitionVersionNumber) { return(operations.UpdateAsync(profileName, profileStatus, definitionVersionNumber, CancellationToken.None)); }
/// <summary> /// Returns profile details, including all definition versions and /// their statuses. (see /// http://msdn.microsoft.com/en-us/library/hh758248.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='profileName'> /// Required. The name of the profile. /// </param> /// <returns> /// The Get Profile Details operation response. /// </returns> public static Task <ProfileGetResponse> GetAsync(this IProfileOperations operations, string profileName) { return(operations.GetAsync(profileName, CancellationToken.None)); }
/// <summary> /// Deletes a profile and all of its definitions. This operation cannot /// be reverted. (see /// http://msdn.microsoft.com/en-us/library/hh758256.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='profileName'> /// Required. The name of the profile. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <AzureOperationResponse> DeleteAsync(this IProfileOperations operations, string profileName) { return(operations.DeleteAsync(profileName, CancellationToken.None)); }
private void InitSubApis() { this.communicationOperations = new CommunicationTemplate(this.RestTemplate); this.connectionOperations = new ConnectionTemplate(this.RestTemplate); this.profileOperations = new ProfileTemplate(this.RestTemplate); }
/// <summary> /// Creates a new profile for a domain name, owned by the specified /// subscription. (see /// http://msdn.microsoft.com/en-us/library/hh758254.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='name'> /// Required. The name of the profile. /// </param> /// <param name='domainName'> /// Required. The name of the domain that the profile is being created /// for. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <AzureOperationResponse> CreateAsync(this IProfileOperations operations, string name, string domainName) { return(operations.CreateAsync(name, domainName, CancellationToken.None)); }
/// <summary> /// Create or update a Traffic Manager endpoint. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='parameters'> /// Required. The Traffic Manager name parameters supplied to the /// CheckTrafficManagerNameAvailability operation. /// </param> /// <returns> /// The response to a 'CheckTrafficManagerNameAvailability' operation. /// </returns> public static CheckTrafficManagerRelativeDnsNameAvailabilityResponse CheckTrafficManagerRelativeDnsNameAvailability(this IProfileOperations operations, CheckTrafficManagerRelativeDnsNameAvailabilityParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IProfileOperations)s).CheckTrafficManagerRelativeDnsNameAvailabilityAsync(parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
private void SetDefaultProperty(IProfileOperations profile) { var context = profile.DefaultContext; context.SetProperty(Resources.DefaultResourceGroupKey, ResourceGroupName); }
/// <summary> /// Create or update a Traffic Manager endpoint. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='parameters'> /// Required. The Traffic Manager name parameters supplied to the /// CheckTrafficManagerNameAvailability operation. /// </param> /// <returns> /// The response to a 'CheckTrafficManagerNameAvailability' operation. /// </returns> public static Task <CheckTrafficManagerRelativeDnsNameAvailabilityResponse> CheckTrafficManagerRelativeDnsNameAvailabilityAsync(this IProfileOperations operations, CheckTrafficManagerRelativeDnsNameAvailabilityParameters parameters) { return(operations.CheckTrafficManagerRelativeDnsNameAvailabilityAsync(parameters, CancellationToken.None)); }
/// <summary> /// Returns all profiles owned by a subscription. (see /// http://msdn.microsoft.com/en-us/library/hh758249.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <returns> /// The List Profiles operation response. /// </returns> public static Task <ProfilesListResponse> ListAsync(this IProfileOperations operations) { return(operations.ListAsync(CancellationToken.None)); }