/// <summary>
 /// Initializes a new instance of the <see cref="AzureResourceManagerClient"/> class.
 /// </summary>
 /// <param name="baseUri"> The base URI of the service. </param>
 /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
 /// <param name="defaultSubscriptionId"> The id of the default Azure subscription. </param>
 /// <param name="options"> The client parameters to use in these operations. </param>
 public AzureResourceManagerClient(Uri baseUri, TokenCredential credential, string defaultSubscriptionId, AzureResourceManagerClientOptions options)
 {
     ClientOptions = new AzureResourceManagerClientOptions(baseUri, credential, options);
     defaultSubscriptionId ??= GetDefaultSubscription().ConfigureAwait(false).GetAwaiter().GetResult();
     DefaultSubscription = new SubscriptionOperations(ClientOptions, new ResourceIdentifier($"/subscriptions/{defaultSubscriptionId}"));
     ApiVersionOverrides = new Dictionary <string, string>();
 }
        private static Pageable <ArmResource> ListAtContextInternal(
            AzureResourceManagerClientOptions clientOptions,
            ResourceIdentifier scopeId,
            string scopeFilter = null,
            ArmFilterCollection resourceFilters = null,
            int?top = null,
            CancellationToken cancellationToken = default)
        {
            var resourceOperations = GetResourcesClient(clientOptions, scopeId.Subscription).Resources;
            Pageable <GenericResourceExpanded> result;

            if (scopeFilter == null)
            {
                result = resourceOperations.List(resourceFilters?.ToString(), null, top, cancellationToken);
            }
            else
            {
                result = resourceOperations.ListByResourceGroup(
                    scopeFilter,
                    resourceFilters?.ToString(),
                    null,
                    top,
                    cancellationToken);
            }

            return(ConvertResults(result, clientOptions));
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OperationsBase"/> class.
        /// </summary>
        /// <param name="options"> The client parameters to use in these operations. </param>
        /// <param name="id"> The identifier of the resource that is the target of operations. </param>
        /// <param name="location"> The location for the Azure resource. </param>
        protected OperationsBase(AzureResourceManagerClientOptions options, ResourceIdentifier id, Location location = null)
        {
            ClientOptions   = options;
            Id              = id;
            DefaultLocation = location ?? Location.Default;

            Validate(id);
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureResourceManagerClientOptions"/> class.
 /// </summary>
 /// <param name="other"> The client parameters to use in these operations. </param>
 internal AzureResourceManagerClientOptions(AzureResourceManagerClientOptions other = null)
 {
     // Will go away when moved into core since we will have directy acces the policies and transport, so just need to set those
     if (!ReferenceEquals(other, null))
     {
         Copy(other);
     }
 }
 private static AsyncPageable <ArmResource> ConvertResultsAsync(
     AsyncPageable <GenericResourceExpanded> result,
     AzureResourceManagerClientOptions clientOptions)
 {
     return(new PhWrappingAsyncPageable <GenericResourceExpanded, ArmResource>(
                result,
                CreateResourceConverter(clientOptions)));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OperationsBase"/> class.
        /// </summary>
        /// <param name="options"> The client parameters to use in these operations. </param>
        /// <param name="id"> The identifier of the resource that is the target of operations. </param>
        /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
        /// <param name="baseUri"> The base URI of the service. </param>
        protected OperationsBase(AzureResourceManagerClientOptions options, ResourceIdentifier id, TokenCredential credential, Uri baseUri)
        {
            ClientOptions = options;
            Id            = id;
            Credential    = credential;
            BaseUri       = baseUri;

            Validate(id);
        }
Exemple #7
0
        // Will be removed like AddPolicy when we move to azure core
        private void Copy(AzureResourceManagerClientOptions other)
        {
            this.Transport = other.Transport;
            foreach (var pol in other.PerCallPolicies)
            {
                this.AddPolicy(pol, HttpPipelinePosition.PerCall);
            }

            foreach (var pol in other.PerRetryPolicies)
            {
                this.AddPolicy(pol, HttpPipelinePosition.PerRetry);
            }
        }
        /// <summary>
        /// List resources under the a resource context
        /// </summary>
        /// <param name="clientOptions"> The client parameters to use in these operations. </param>
        /// <param name="id"> The identifier of the resource that is the target of operations. </param>
        /// <param name="resourceFilters"> Optional filters for results. </param>
        /// <param name="top"> The number of results to return. </param>
        /// <param name="cancellationToken"> A token to allow the caller to cancel the call to the service.
        /// The default value is <see cref="P:System.Threading.CancellationToken.None" />. </param>
        /// <returns>An async collection of resource operations that may take multiple service requests to iterate over. </returns>
        /// <exception cref="ArgumentException"> <paramref name="id"/> is not valid to list at context. </exception>
        public static AsyncPageable <ArmResource> ListAtContextAsync(
            AzureResourceManagerClientOptions clientOptions,
            ResourceIdentifier id,
            ArmFilterCollection resourceFilters = null,
            int?top = null,
            CancellationToken cancellationToken = default)
        {
            Validate(id);

            var scopeId = id.Type == ResourceGroupOperations.ResourceType ? id.Name : null;

            return(ListAtContextInternalAsync(
                       clientOptions,
                       id,
                       scopeId,
                       resourceFilters,
                       top,
                       cancellationToken));
        }
 private static Func <GenericResourceExpanded, ArmResource> CreateResourceConverter(AzureResourceManagerClientOptions clientOptions)
 {
     return(s => Activator.CreateInstance(
                typeof(ArmResource),
                clientOptions,
                Activator.CreateInstance(typeof(ArmResourceData), s as GenericResource) as ArmResourceData) as ArmResource);
 }
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionContainer"/> class.
 /// </summary>
 /// <param name="options"> The client parameters to use in these operations. </param>
 internal SubscriptionContainer(AzureResourceManagerClientOptions options)
     : base(options, null, null)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureResourceManagerClient"/> class.
 /// </summary>
 /// <param name="baseUri"> The base URI of the service. </param>
 /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
 /// <param name="options"> The client parameters to use in these operations. </param>
 public AzureResourceManagerClient(Uri baseUri, TokenCredential credential, AzureResourceManagerClientOptions options = default)
     : this(null, baseUri, credential, options)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceContainerBase{TOperations, TData}"/> class.
 /// </summary>
 /// <param name="options"> The client parameters to use in these operations. </param>
 /// <param name="parentId"> The resource Id of the parent resource. </param>
 protected ResourceContainerBase(AzureResourceManagerClientOptions options, ResourceIdentifier parentId)
     : base(options, parentId)
 {
 }
Exemple #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtensionResourceOperationsBase"/> class.
 /// </summary>
 /// <param name="options">Client configuration properties for these operations</param>
 /// <param name="resource">The extention resource for operations to act upon</param>
 protected ExtensionResourceOperationsBase(AzureResourceManagerClientOptions options, Resource resource)
     : this(options, resource.Id)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionOperations"/> class.
 /// </summary>
 /// <param name="options"> The client parameters to use in these operations. </param>
 /// <param name="id"> The identifier of the subscription. </param>
 internal SubscriptionOperations(AzureResourceManagerClientOptions options, ResourceIdentifier id)
     : base(options, id)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionOperations"/> class.
 /// </summary>
 /// <param name="options"> The client parameters to use in these operations. </param>
 /// <param name="subscriptionId"> The Id of the subscription. </param>
 internal SubscriptionOperations(AzureResourceManagerClientOptions options, string subscriptionId)
     : base(options, $"/subscriptions/{subscriptionId}")
 {
 }
Exemple #16
0
 internal ResourceGroupContainer(AzureResourceManagerClientOptions options, ResourceIdentifier id)
     : base(options, id)
 {
 }
Exemple #17
0
 internal ResourceGroupContainer(AzureResourceManagerClientOptions options, SubscriptionOperations subscription)
     : base(options, subscription.Id)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceOperationsBase"/> class.
 /// </summary>
 /// <param name="options">The client parameters to use in these operations.</param>
 /// <param name="resource">The resource that is the target of operations.</param>
 protected ResourceOperationsBase(AzureResourceManagerClientOptions options, Resource resource)
     : base(options, resource)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionContainer"/> class.
 /// </summary>
 /// <param name="options"> The client parameters to use in these operations. </param>
 /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
 /// <param name="baseUri"> The base URI of the service. </param>
 internal SubscriptionContainer(AzureResourceManagerClientOptions options, TokenCredential credential, Uri baseUri)
     : base(options, null, credential, baseUri)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureResourceManagerClient"/> class.
        /// </summary>
        /// <param name="defaultSubscriptionId"> The id of the default Azure subscription. </param>
        /// <param name="baseUri"> The base URI of the service. </param>
        /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
        /// <param name="options"> The client parameters to use in these operations. </param>
        private AzureResourceManagerClient(string defaultSubscriptionId, Uri baseUri, TokenCredential credential, AzureResourceManagerClientOptions options = default)
        {
            _credentials  = credential;
            _baseUri      = baseUri;
            ClientOptions = options ?? new AzureResourceManagerClientOptions();

            if (string.IsNullOrWhiteSpace(defaultSubscriptionId))
            {
                DefaultSubscription = GetDefaultSubscription();
            }
            else
            {
                DefaultSubscription = GetSubscriptionOperations(defaultSubscriptionId).Get().Value;
            }

            ApiVersionOverrides = new Dictionary <string, string>();
        }
Exemple #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtensionResourceOperationsBase"/> class.
 /// </summary>
 /// <param name="options">Client configuration properties for these operations</param>
 /// <param name="id">The identifier of the extension resource</param>
 protected ExtensionResourceOperationsBase(AzureResourceManagerClientOptions options, ResourceIdentifier id)
     : base(options, id)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionOperations"/> class.
 /// </summary>
 /// <param name="options"> The client parameters to use in these operations. </param>
 /// <param name="subscription"> The subscription resource. </param>
 internal SubscriptionOperations(AzureResourceManagerClientOptions options, Resource subscription)
     : base(options, subscription)
 {
 }
Exemple #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureResourceManagerClientOptions"/> class.
 /// </summary>
 /// <param name="baseUri"> The base URI of the service. </param>
 /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
 /// <param name="other"> The client parameters to use in these operations. </param>
 public AzureResourceManagerClientOptions(Uri baseUri, TokenCredential credential, AzureResourceManagerClientOptions other = null)
 {
     BaseUri    = baseUri;
     Credential = credential;
     //Will go away when moved into core since we will have directy acces the policies and transport, so just need to set those
     if (!Object.ReferenceEquals(other, null))
     {
         Copy(other);
     }
 }
 internal ResourceGroupOperations(AzureResourceManagerClientOptions options, ResourceIdentifier id)
     : base(options, id)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureResourceManagerClient"/> class.
 /// </summary>
 /// <param name="options"> The client parameters to use in these operations. </param>
 public AzureResourceManagerClient(AzureResourceManagerClientOptions options = default)
     : this(null, null, new DefaultAzureCredential(), options)
 {
 }
 private static ResourcesManagementClient GetResourcesClient(AzureResourceManagerClientOptions options, string id)
 {
     return(new ResourcesManagementClient(options.BaseUri, id, options.Credential));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceContainerBase{TOperations, TData}"/> class.
 /// </summary>
 /// <param name="options"> The client parameters to use in these operations. </param>
 /// <param name="parentResource"> The resource representing the parent resource. </param>
 protected ResourceContainerBase(AzureResourceManagerClientOptions options, TrackedResource parentResource)
     : base(options, parentResource)
 {
     Parent = parentResource;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureResourceManagerClient"/> class.
 /// </summary>
 /// <param name="defaultSubscriptionId"> The id of the default Azure subscription. </param>
 /// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
 /// <param name="options"> The client parameters to use in these operations. </param>
 public AzureResourceManagerClient(string defaultSubscriptionId, TokenCredential credential, AzureResourceManagerClientOptions options = default)
     : this(defaultSubscriptionId, null, credential, options)
 {
 }
 internal ResourceGroupOperations(AzureResourceManagerClientOptions options, Resource resource)
     : base(options, resource)
 {
 }
Exemple #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OperationsBase"/> class.
 /// </summary>
 /// <param name="options"> The client parameters to use in these operations. </param>
 /// <param name="resource"> The Azure resource that is the target of operations. </param>
 protected OperationsBase(AzureResourceManagerClientOptions options, Resource resource)
     : this(options, resource?.Id, (resource as TrackedResource)?.Location)
 {
     Resource = resource;
 }