/// <summary>
        /// Lists resources in a type collection.
        /// </summary>
        private async Task <ResponseWithContinuation <JObject[]> > ListResourcesTypeCollection()
        {
            var resourceCollectionId = ResourceIdUtility.GetResourceId(
                subscriptionId: this.SubscriptionId.AsArray().CoalesceEnumerable().Cast <Guid?>().FirstOrDefault(),
                resourceGroupName: null,
                resourceType: this.ResourceType,
                resourceName: null,
                extensionResourceType: this.ExtensionResourceType,
                extensionResourceName: null);

            var odataQuery = QueryFilterBuilder.CreateFilter(
                subscriptionId: null,
                resourceGroup: this.ResourceGroupNameEquals,
                resourceType: null,
                resourceName: this.ResourceNameEquals,
                tagName: TagsHelper.GetTagNameFromParameters(this.Tag, this.TagName),
                tagValue: TagsHelper.GetTagValueFromParameters(this.Tag, this.TagValue),
                filter: this.ODataQuery,
                resourceGroupNameContains: this.ResourceGroupNameContains,
                nameContains: this.ResourceNameContains);

            return(await this
                   .GetResourcesClient()
                   .ListObjectColleciton <JObject>(
                       resourceCollectionId: resourceCollectionId,
                       apiVersion: this.DefaultApiVersion,
                       cancellationToken: this.CancellationToken.Value,
                       odataQuery: odataQuery)
                   .ConfigureAwait(continueOnCapturedContext: false));
        }
        /// <summary>
        /// Lists the resources in a resource group.
        /// </summary>
        private async Task <ResponseWithContinuation <JObject[]> > ListResourcesInResourceGroup()
        {
            var filterQuery = QueryFilterBuilder
                              .CreateFilter(
                subscriptionId: null,
                resourceGroup: this.ResourceGroupNameEquals,
                resourceType: this.ResourceType,
                resourceName: this.ResourceNameEquals,
                tagName: TagsHelper.GetTagNameFromParameters(this.Tag, this.TagName),
                tagValue: TagsHelper.GetTagValueFromParameters(this.Tag, this.TagValue),
                filter: this.ODataQuery,
                resourceGroupNameContains: this.ResourceGroupNameContains,
                nameContains: this.ResourceNameContains);

            return(await this
                   .GetResourcesClient()
                   .ListResources <JObject>(
                       subscriptionId: this.SubscriptionId.Value,
                       resourceGroupName: null,
                       apiVersion: this.DefaultApiVersion,
                       top: this.Top,
                       filter: filterQuery,
                       cancellationToken: this.CancellationToken.Value)
                   .ConfigureAwait(continueOnCapturedContext: false));
        }
Example #3
0
        /// <summary>
        /// Lists the resources in a resource group.
        /// </summary>
        private async Task <ResponseWithContinuation <JObject[]> > ListResourcesInResourceGroup()
        {
            var filterQuery = QueryFilterBuilder
                              .CreateFilter(
                resourceType: this.ResourceType,
                resourceName: this.ResourceName,
                tagName: null,
                tagValue: null,
                filter: this.ODataQuery);

            var apiVersion = await this
                             .DetermineApiVersion(providerNamespace : Constants.MicrosoftResourceNamesapce, resourceType : Constants.ResourceGroups)
                             .ConfigureAwait(continueOnCapturedContext: false);

            return(await this
                   .GetResourcesClient()
                   .ListResources <JObject>(
                       subscriptionId: this.SubscriptionId.Value,
                       resourceGroupName: this.ResourceGroupName,
                       apiVersion: apiVersion,
                       top: this.Top,
                       filter: filterQuery,
                       cancellationToken: this.CancellationToken.Value)
                   .ConfigureAwait(continueOnCapturedContext: false));
        }
Example #4
0
        /// <summary>
        /// Gets a resource.
        /// </summary>
        private async Task <JObject> GetResource()
        {
#pragma warning disable 618

            var resourceId = this.GetResourceId();

#pragma warning restore 618

            var apiVersion = await this
                             .DetermineApiVersion(resourceId : resourceId)
                             .ConfigureAwait(continueOnCapturedContext: false);

            var odataQuery = QueryFilterBuilder.CreateFilter(
                resourceType: null,
                resourceName: null,
                tagName: null,
                tagValue: null,
                filter: this.ODataQuery);

            return(await this
                   .GetResourcesClient()
                   .GetResource <JObject>(
                       resourceId: resourceId,
                       apiVersion: apiVersion,
                       cancellationToken: this.CancellationToken.Value,
                       odataQuery: odataQuery)
                   .ConfigureAwait(continueOnCapturedContext: false));
        }
        /// <summary>
        /// Lists resources in a type collection.
        /// </summary>
        private async Task <ResponseWithContinuation <JObject[]> > ListResourcesTypeCollection()
        {
            var resourceCollectionId = ResourceIdUtility.GetResourceId(
                subscriptionId: this.SubscriptionId.CoalesceEnumerable().FirstOrDefault(),
                resourceGroupName: this.ResourceGroupName,
                resourceType: this.ResourceType,
                resourceName: this.ResourceName,
                extensionResourceType: this.ExtensionResourceType,
                extensionResourceName: this.ExtensionResourceName);

            var apiVersion = await this
                             .DetermineApiVersion(resourceId : resourceCollectionId)
                             .ConfigureAwait(continueOnCapturedContext: false);

            var odataQuery = QueryFilterBuilder.CreateFilter(
                resourceType: null,
                resourceName: null,
                tagName: this.TagName,
                tagValue: this.TagValue,
                filter: this.ODataQuery);

            return(await this
                   .GetResourcesClient()
                   .ListObjectColleciton <JObject>(
                       resourceCollectionId: resourceCollectionId,
                       apiVersion: apiVersion,
                       cancellationToken: this.CancellationToken.Value,
                       odataQuery: odataQuery)
                   .ConfigureAwait(continueOnCapturedContext: false));
        }
Example #6
0
        private void RunSimpleCmdlet()
        {
            if (this.IsParameterBound(c => c.Tag))
            {
                this.TagName  = TagsHelper.GetTagNameFromParameters(this.Tag, null);
                this.TagValue = TagsHelper.GetTagValueFromParameters(this.Tag, null);
            }

            var expression = QueryFilterBuilder.CreateFilter(
                subscriptionId: null,
                resourceGroup: null,
                resourceType: this.ResourceType,
                resourceName: null,
                tagName: null,
                tagValue: null,
                filter: this.ODataQuery);

            var odataQuery = new Rest.Azure.OData.ODataQuery <GenericResourceFilter>(expression);
            var result     = Enumerable.Empty <PSResource>();

            if (!ShouldListBySubscription(ResourceGroupName, Name))
            {
                result = this.ResourceManagerSdkClient.ListByResourceGroup(this.ResourceGroupName, odataQuery);
            }
            else
            {
                result = this.ResourceManagerSdkClient.ListResources(odataQuery);
            }

            result = TopLevelWildcardFilter(ResourceGroupName, Name, result);

            if (!string.IsNullOrEmpty(this.TagName) && !string.IsNullOrEmpty(this.TagValue))
            {
                result = result.Where(r => r.Tags != null &&
                                      r.Tags.Keys != null &&
                                      r.Tags.Keys.Where(k => string.Equals(k, this.TagName, StringComparison.OrdinalIgnoreCase))
                                      .Any(k => string.Equals(r.Tags[k], this.TagValue, StringComparison.OrdinalIgnoreCase)));
            }
            else if (!string.IsNullOrEmpty(this.TagName))
            {
                result = result.Where(r => r.Tags != null &&
                                      r.Tags.Keys != null &&
                                      r.Tags.Keys.Where(k => string.Equals(k, this.TagName, StringComparison.OrdinalIgnoreCase))
                                      .Any());
            }
            else if (!string.IsNullOrEmpty(this.TagValue))
            {
                result = result.Where(r => r.Tags != null &&
                                      r.Tags.Values != null &&
                                      r.Tags.Values.Where(v => string.Equals(v, this.TagValue, StringComparison.OrdinalIgnoreCase))
                                      .Any());
            }

            WriteObject(result, true);
        }
Example #7
0
        /// <summary>
        /// Lists the resources in the tenant.
        /// </summary>
        private async Task <ResponseWithContinuation <JObject[]> > ListResourcesInTenant()
        {
            var filterQuery = QueryFilterBuilder
                              .CreateFilter(
                subscriptionId: null,
                resourceGroup: this.ResourceGroupName,
                resourceType: this.ResourceType,
                resourceName: this.Name,
                tagName: null,
                tagValue: null,
                filter: this.ODataQuery);

            return(await this
                   .GetResourcesClient()
                   .ListResources <JObject>(
                       apiVersion: this.DefaultApiVersion,
                       filter: filterQuery,
                       cancellationToken: this.CancellationToken.Value)
                   .ConfigureAwait(continueOnCapturedContext: false));
        }