/// <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)); }
/// <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> /// Get all the resources in a single resource group. /// </summary> /// <param name="subscriptionId">The subscription Id.</param> /// <param name="resourceGroupName">The resource group name.</param> /// <param name="apiVersion">The API version to use.</param> /// <param name="cancellationToken"></param> /// <param name="top">The number of resources to fetch.</param> /// <param name="filter">The filter query.</param> public Task <ResponseWithContinuation <TType[]> > ListResources <TType>( Guid subscriptionId, string resourceGroupName, string apiVersion, CancellationToken cancellationToken, int?top = null, string filter = null) { var resourceId = ResourceIdUtility.GetResourceId( subscriptionId: subscriptionId, resourceGroupName: resourceGroupName, resourceType: null, resourceName: null); var requestUri = this.GetResourceManagementRequestUri( resourceId: resourceId, action: "resources", top: top == null ? null : string.Format("$top={0}", top.Value), odataQuery: string.IsNullOrWhiteSpace(filter) ? null : string.Format("$filter={0}", filter), apiVersion: apiVersion); return(this.SendRequestAsync <ResponseWithContinuation <TType[]> >( httpMethod: HttpMethod.Get, requestUri: requestUri, cancellationToken: cancellationToken)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> protected string MakePolicyAssignmentId(string scope, string resourceName) { return(ResourceIdUtility.GetResourceId( resourceId: scope, extensionResourceType: Constants.MicrosoftAuthorizationPolicyAssignmentType, extensionResourceName: resourceName)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> /// <param name="lockName">The name of the lock.</param> protected string GetResourceId(string lockName) { if (!string.IsNullOrWhiteSpace(this.LockId)) { var resourceType = ResourceIdUtility.GetResourceType(this.LockId); var extensionResourceType = ResourceIdUtility.GetExtensionResourceType(this.LockId); if ((resourceType.EqualsInsensitively(Constants.MicrosoftAuthorizationLocksType) && string.IsNullOrWhiteSpace(extensionResourceType)) || extensionResourceType.EqualsInsensitively(Constants.MicrosoftAuthorizationLocksType)) { return(this.LockId); } throw new InvalidOperationException(string.Format("The Id '{0}' does not belong to a lock.", this.LockId)); } return(!string.IsNullOrWhiteSpace(this.Scope) ? ResourceIdUtility.GetResourceId( resourceId: this.Scope, extensionResourceType: Constants.MicrosoftAuthorizationLocksType, extensionResourceName: lockName) : ResourceIdUtility.GetResourceId( subscriptionId: this.SubscriptionId, resourceGroupName: this.ResourceGroupName, resourceType: this.ResourceType, resourceName: this.ResourceName, extensionResourceType: Constants.MicrosoftAuthorizationLocksType, extensionResourceName: lockName)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> protected string MakePolicyAssignmentId(string scope, string resourceName) { return(ResourceIdUtility.GetResourceId( resourceId: scope ?? $"/{Constants.Subscriptions}/{DefaultContext.Subscription.Id}", extensionResourceType: Constants.MicrosoftAuthorizationPolicyAssignmentType, extensionResourceName: resourceName)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> protected string GetResourceId() { return(ResourceIdUtility.GetResourceId( resourceId: this.Scope, extensionResourceType: Constants.MicrosoftAuthorizationPolicyAssignmentType, extensionResourceName: this.Name)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> protected string GetPolicyArtifactFullyQualifiedId(string scope, string resourceType, string resourceName) { return(ResourceIdUtility.GetResourceId( resourceId: scope ?? $"/{Constants.Subscriptions}/{DefaultContext.Subscription.Id}", extensionResourceType: resourceType, extensionResourceName: resourceName)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> protected string GetResourceId() { return(ResourceIdUtility.GetResourceId( subscriptionId: this.SubscriptionId, resourceGroupName: this.ResourceGroupName, resourceType: Constants.MicrosoftResourcesDeploymentOperationsType, resourceName: this.DeploymentName)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> protected string GetResourceId() { return(ResourceIdUtility.GetResourceId( subscriptionId: DefaultContext.Subscription.Id, resourceGroupName: this.ResourceGroupName, resourceType: null, resourceName: null)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> private string GetResourceGroupId() { return(ResourceIdUtility.GetResourceId( subscriptionId: this.SubscriptionId, resourceGroupName: this.ResourceGroupName, resourceType: null, resourceName: null)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> protected string GetResourceId() { return(ResourceIdUtility.GetResourceId( subscriptionId: DefaultContext.Subscription.GetId(), resourceGroupName: this.ResourceGroupName, resourceType: Constants.MicrosoftResourcesDeploymentType, resourceName: this.DeploymentName)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> private string GetResourceId() { return(!string.IsNullOrWhiteSpace(this.ResourceId) ? this.ResourceId : ResourceIdUtility.GetResourceId( subscriptionId: this.SubscriptionId.Value, resourceGroupName: this.ResourceGroupName, resourceType: this.ResourceType, resourceName: this.Name)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> private string GetResourceIdWithoutParentResource() { return(ResourceIdUtility.GetResourceId( subscriptionId: this.SubscriptionId, resourceGroupName: this.ResourceGroupName, resourceType: this.ResourceType, resourceName: this.ResourceName, extensionResourceType: this.ExtensionResourceType, extensionResourceName: this.ExtensionResourceName)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> private string GetResourceIdWithoutParentResource() { return(ResourceIdUtility.GetResourceId( subscriptionId: TenantLevel.IsPresent?null: (Guid?)this.SubscriptionId, resourceGroupName: TenantLevel.IsPresent ? null : this.ResourceGroupName, resourceType: this.ResourceType, resourceName: this.ResourceName, extensionResourceType: this.ExtensionResourceType, extensionResourceName: this.ExtensionResourceName)); }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> private string GetResourceId() { return(!string.IsNullOrWhiteSpace(this.ResourceId) ? this.ResourceId : ResourceIdUtility.GetResourceId( subscriptionId: this.SubscriptionId.CoalesceEnumerable().FirstOrDefault(), resourceGroupName: this.ResourceGroupName, resourceType: this.ResourceType, resourceName: this.ResourceName, extensionResourceType: this.ExtensionResourceType, extensionResourceName: this.ExtensionResourceName)); }
/// <summary> /// Gets the resource Id using the <c>ParentResource</c>. /// </summary> private string GetResourceIdWithParentResource() { #pragma warning disable 618 return(ResourceIdUtility.GetResourceId( subscriptionId: this.SubscriptionId.Value, resourceGroupName: this.ResourceGroupName, parentResource: this.ParentResource, resourceType: this.ResourceType, resourceName: this.ResourceName)); #pragma warning restore 618 }
/// <summary> /// Gets the resource Id from the supplied PowerShell parameters. /// </summary> protected string GetResourceId() { return(!string.IsNullOrWhiteSpace(this.Scope) ? ResourceIdUtility.GetResourceId( resourceId: this.Scope, extensionResourceType: Constants.MicrosoftAuthorizationLocksType, extensionResourceName: this.LockName) : ResourceIdUtility.GetResourceId( subscriptionId: this.SubscriptionId, resourceGroupName: this.ResourceGroupName, resourceType: this.ResourceType, resourceName: this.ResourceName, extensionResourceType: Constants.MicrosoftAuthorizationLocksType, extensionResourceName: this.LockName)); }
/// <summary> /// Gets the resource Id using the <c>ParentResource</c>. /// </summary> private string GetResourceIdWithParentResource() { if (this.SubscriptionId.Length != 1) { throw new ArgumentException(); } #pragma warning disable 618 return(ResourceIdUtility.GetResourceId( subscriptionId: this.SubscriptionId.First(), resourceGroupName: this.ResourceGroupName, parentResource: this.ParentResource, resourceType: this.ResourceType, resourceName: this.ResourceName)); #pragma warning restore 618 }
/// <summary> /// Gets the resource Id /// </summary> private string GetResourceId() { var subscriptionId = DefaultContext.Subscription.Id; if (string.IsNullOrEmpty(this.Name) && string.IsNullOrEmpty(this.Scope)) { return(string.Format("/subscriptions/{0}/providers/{1}", subscriptionId.ToString(), Constants.MicrosoftAuthorizationPolicyAssignmentType)); } else if (string.IsNullOrEmpty(this.Name) && !string.IsNullOrEmpty(this.Scope)) { return(ResourceIdUtility.GetResourceId( resourceId: this.Scope, extensionResourceType: Constants.MicrosoftAuthorizationPolicyAssignmentType, extensionResourceName: null)); } return(ResourceIdUtility.GetResourceId( resourceId: this.Scope, extensionResourceType: Constants.MicrosoftAuthorizationPolicyAssignmentType, extensionResourceName: this.Name)); }
/// <summary> /// Executes the cmdlet /// </summary> private void RunCmdlet() { var resourceIdsToUse = this.resourceIds .Concat(this.ResourceId) .DistinctArray(StringComparer.InvariantCultureIgnoreCase); this.DestinationSubscriptionId = this.Profile.Context.Subscription.Id; var resourceGroup = ResourceIdUtility.GetResourceId( subscriptionId: this.DestinationSubscriptionId, resourceGroupName: this.DestinationResourceGroupName, resourceName: null, resourceType: null); this.ConfirmAction( this.Force, string.Format( "Are you sure you want to move these resources to the resource group '{0}' the resources: {1}", resourceGroup, Environment.NewLine.AsArray().Concat(resourceIdsToUse).ConcatStrings(Environment.NewLine)), "Moving the resources.", resourceGroup, () => { var apiVersion = this .DetermineApiVersion( providerNamespace: Constants.MicrosoftResourceNamesapce, resourceType: Constants.ResourceGroups) .Result; var parameters = new ResourceBatchMoveParameters { Resources = resourceIdsToUse, TargetResourceGroup = resourceGroup, }; var operationResult = this.GetResourcesClient() .InvokeActionOnResource <JObject>( resourceId: resourceGroup, action: Constants.Move, apiVersion: apiVersion, parameters: parameters.ToJToken(), cancellationToken: this.CancellationToken.Value) .Result; var managementUri = this.GetResourcesClient() .GetResourceManagementRequestUri( resourceId: resourceGroup, apiVersion: apiVersion, action: Constants.Move); var activity = string.Format("POST {0}", managementUri.PathAndQuery); var result = this .GetLongRunningOperationTracker( activityName: activity, isResourceCreateOrUpdate: false) .WaitOnOperation(operationResult: operationResult); this.WriteObject(result); }); }
/// <summary> /// Executes the cmdlet /// </summary> private void RunCmdlet() { var resourceIdsToUse = this.resourceIds .Concat(this.ResourceId) .DistinctArray(StringComparer.InvariantCultureIgnoreCase); this.DestinationSubscriptionId = this.DestinationSubscriptionId ?? DefaultContext.Subscription.Id; var sourceResourceGroups = resourceIdsToUse .Select(resourceId => ResourceIdUtility.GetResourceGroupId(resourceId)) .Where(resourceGroupId => !string.IsNullOrWhiteSpace(resourceGroupId)) .DistinctArray(StringComparer.InvariantCultureIgnoreCase); var count = sourceResourceGroups.Count(); if (count == 0) { throw new InvalidOperationException("At least one valid resource Id must be provided."); } else if (count > 1) { throw new InvalidOperationException( string.Format("The resources being moved must all reside in the same resource group. The resources: {0}", resourceIdsToUse.ConcatStrings(", "))); } var sourceResourceGroup = sourceResourceGroups.Single(); var destinationResourceGroup = ResourceIdUtility.GetResourceId( subscriptionId: this.DestinationSubscriptionId, resourceGroupName: this.DestinationResourceGroupName, resourceName: null, resourceType: null); this.ConfirmAction( this.Force, string.Format( "Are you sure you want to move these resources to the resource group '{0}' the resources: {1}", destinationResourceGroup, Environment.NewLine.AsArray().Concat(resourceIdsToUse).ConcatStrings(Environment.NewLine)), "Moving the resources.", destinationResourceGroup, () => { var apiVersion = this .DetermineApiVersion( providerNamespace: Constants.MicrosoftResourceNamesapce, resourceType: Constants.ResourceGroups) .Result; var parameters = new ResourceBatchMoveParameters { Resources = resourceIdsToUse, TargetResourceGroup = destinationResourceGroup, }; var operationResult = this.GetResourcesClient() .InvokeActionOnResource <JObject>( resourceId: sourceResourceGroup, action: Constants.MoveResources, apiVersion: apiVersion, parameters: parameters.ToJToken(), cancellationToken: this.CancellationToken.Value) .Result; var managementUri = this.GetResourcesClient() .GetResourceManagementRequestUri( resourceId: destinationResourceGroup, apiVersion: apiVersion, action: Constants.MoveResources); var activity = string.Format("POST {0}", managementUri.PathAndQuery); var result = this .GetLongRunningOperationTracker( activityName: activity, isResourceCreateOrUpdate: false) .WaitOnOperation(operationResult: operationResult); this.TryConvertAndWriteObject(result); }); }