/// <summary> /// Constructs the resource /// </summary> private JToken GetResource(string resourceId, string apiVersion) { var resource = this.GetExistingResource(resourceId, apiVersion).Result.ToResource(); var policyAssignmentObject = new PolicyAssignment { Name = this.Name ?? ResourceIdUtility.GetResourceName(this.Id), Sku = this.Sku != null ? this.Sku.ToDictionary(addValueLayer : false).ToJson().FromJson <PolicySku>() : (resource.Sku == null ? new PolicySku { Name = "A0", Tier = "Free" } : resource.Sku.ToJson().FromJson <PolicySku>()), Properties = new PolicyAssignmentProperties { DisplayName = this.DisplayName ?? (resource.Properties["displayName"] != null ? resource.Properties["displayName"].ToString() : null), Description = this.Description ?? (resource.Properties["description"] != null ? resource.Properties["description"].ToString() : null), Scope = resource.Properties["scope"].ToString(), NotScopes = this.NotScope ?? (resource.Properties["NotScopes"] == null ? null : resource.Properties["NotScopes"].ToString().Split(',')), PolicyDefinitionId = resource.Properties["policyDefinitionId"].ToString() } }; return(policyAssignmentObject.ToJToken()); }
public override void ExecuteCmdlet() { PsDeploymentScriptLog deploymentScriptLog; try { switch (ParameterSetName) { case GetDeploymentScriptLogByName: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(Name, ResourceGroupName); break; case GetDeploymentScriptLogByResourceId: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog( ResourceIdUtility.GetResourceName(this.DeploymentScriptResourceId), ResourceIdUtility.GetResourceGroupName(this.DeploymentScriptResourceId)); break; case GetDeploymentScriptLogByInputObject: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(DeploymentScriptInputObject.Name, ResourceIdUtility.GetResourceGroupName(DeploymentScriptInputObject.Id)); break; default: throw new PSInvalidOperationException(); } WriteObject(deploymentScriptLog); } catch (Exception ex) { WriteExceptionError(ex); } }
/// <summary> /// Converts a <see cref="Resource{JToken}"/> object into a <see cref="PSObject"/> object. /// </summary> /// <param name="resource">The <see cref="Resource{JToken}"/> object.</param> internal static PSObject ToPsObject(this Resource <JToken> resource) { var resourceType = ResourceIdUtility.GetResourceType(resource.Id); var extensionResourceType = ResourceIdUtility.GetExtensionResourceType(resource.Id); var objectDefinition = new Dictionary <string, object> { { "Name", resource.Name }, { "ResourceId", resource.Id }, { "ResourceName", ResourceIdUtility.GetResourceName(resource.Id) }, { "ResourceType", resourceType }, { "ExtensionResourceName", ResourceIdUtility.GetExtensionResourceName(resource.Id) }, { "ExtensionResourceType", extensionResourceType }, { "Kind", resource.Kind }, { "ResourceGroupName", ResourceIdUtility.GetResourceGroup(resource.Id) }, { "Location", resource.Location }, { "SubscriptionId", ResourceIdUtility.GetSubscriptionId(resource.Id) }, { "Tags", TagsHelper.GetTagsHashtables(resource.Tags) }, { "Plan", resource.Plan.ToJToken().ToPsObject() }, { "Properties", resource.Properties.ToPsObject() }, { "PropertiesText", resource.Properties == null ? null : resource.Properties.ToString() }, { "CreatedTime", resource.CreatedTime }, { "ChangedTime", resource.ChangedTime }, { "ETag", resource.ETag }, }; return(PowerShellUtilities.ConstructPSObject( (resourceType + extensionResourceType).Replace('/', '.'), objectDefinition.Where(kvp => kvp.Value != null).SelectManyArray(kvp => new[] { kvp.Key, kvp.Value }))); }
/// <summary> /// Constructs the resource /// </summary> private JToken GetResource(string resourceId, string apiVersion) { var resource = this.GetExistingResource(resourceId, apiVersion).Result.ToResource(); var policySetDefinitionObject = new PolicySetDefinition { Name = this.Name ?? ResourceIdUtility.GetResourceName(this.Id), Properties = new PolicySetDefinitionProperties { Description = this.Description ?? (resource.Properties["description"] != null ? resource.Properties["description"].ToString() : null), DisplayName = this.DisplayName ?? (resource.Properties["displayName"] != null ? resource.Properties["displayName"].ToString() : null) } }; if (!string.IsNullOrEmpty(this.PolicyDefinition)) { policySetDefinitionObject.Properties.PolicyDefinitions = GetPolicyDefinitionsObject(); } else { policySetDefinitionObject.Properties.PolicyDefinitions = JArray.Parse(resource.Properties["policyDefinitions"].ToString()); } return(policySetDefinitionObject.ToJToken()); }
public override void ExecuteCmdlet() { try { switch (ParameterSetName) { case GetDeploymentScriptByName: WriteObject(DeploymentScriptsSdkClient.GetDeploymentScript(Name, ResourceGroupName)); break; case GetDeploymentScriptByResourceId: WriteObject(DeploymentScriptsSdkClient.GetDeploymentScript(ResourceIdUtility.GetResourceName(this.Id), ResourceIdUtility.GetResourceGroupName(this.Id))); break; case ListDeploymentScript: WriteObject(!string.IsNullOrEmpty(ResourceGroupName) ? DeploymentScriptsSdkClient.ListDeploymentScriptsByResourceGroup(ResourceGroupName) : DeploymentScriptsSdkClient.ListDeploymentScriptsBySubscription()); break; default: throw new PSInvalidOperationException(); } } catch (Exception ex) { WriteExceptionError(ex); } }
/// <summary> /// Queries the ARM cache and returns the cached resource that match the query specified. /// </summary> private async Task <ResponseWithContinuation <JObject[]> > GetResources() { string resourceId = this.Id ?? this.GetResourceId(); var apiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.PolicyDefinitionApiVersion : this.ApiVersion; if (!string.IsNullOrEmpty(ResourceIdUtility.GetResourceName(resourceId))) { var resource = await this .GetResourcesClient() .GetResource <JObject>( resourceId: resourceId, apiVersion: apiVersion, cancellationToken: this.CancellationToken.Value) .ConfigureAwait(continueOnCapturedContext: false); ResponseWithContinuation <JObject[]> retVal; return(resource.TryConvertTo(out retVal) && retVal.Value != null ? retVal : new ResponseWithContinuation <JObject[]> { Value = resource.AsArray() }); } else { return(await this .GetResourcesClient() .ListObjectColleciton <JObject>( resourceCollectionId: resourceId, apiVersion: apiVersion, cancellationToken: this.CancellationToken.Value) .ConfigureAwait(continueOnCapturedContext: false)); } }
public override void ExecuteCmdlet() { PsDeploymentScriptLog deploymentScriptLog; try { switch (ParameterSetName) { case SaveDeploymentScriptLogByName: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(Name, ResourceGroupName); break; case SaveDeploymentScriptLogByResourceId: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog( ResourceIdUtility.GetResourceName(this.DeploymentScriptResourceId), ResourceIdUtility.GetResourceGroupName(this.DeploymentScriptResourceId)); break; case SaveDeploymentScriptLogByInputObject: deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog( DeploymentScriptInputObject.Name, ResourceIdUtility.GetResourceGroupName(DeploymentScriptInputObject.Id)); break; default: throw new PSInvalidOperationException(); } if (!string.IsNullOrEmpty(OutputPath) && !string.IsNullOrEmpty(deploymentScriptLog?.Log)) { var outputPathWithFileName = Path.Combine(GetValidatedFolderPath(OutputPath), $"{deploymentScriptLog.DeploymentScriptName}.txt"); // if a file with the same name exists and -Force is not provided, let's ask if we can replace the file. this.ConfirmAction( this.Force || !AzureSession.Instance.DataStore.FileExists(outputPathWithFileName), string.Format( Properties.Resources.DeploymentScriptLogFileExists, Name, OutputPath), Properties.Resources.DeploymentScriptShouldProcessString, OutputPath, () => { AzureSession.Instance.DataStore.WriteFile(outputPathWithFileName, deploymentScriptLog.Log); WriteObject(new PsDeploymentScriptLogPath() { Path = outputPathWithFileName }); }); } } catch (Exception ex) { WriteExceptionError(ex); } }
public override void ExecuteCmdlet() { FilterDeploymentOptions options = new FilterDeploymentOptions() { DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id)) }; WriteObject(ResourceManagerSdkClient.FilterDeploymentsAtSubscriptionScope(options), true); }
protected override void ProcessRecord() { FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(Id), DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id)) }; WriteObject(ResourcesClient.FilterResourceGroupDeployments(options), true); }
public override void ExecuteCmdlet() { FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(Id), DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id)) }; WriteObject(ResourcesClient.FilterResourceGroupDeployments(options), true); }
/// <summary> /// Queries the ARM cache and returns the cached resource that match the query specified. /// </summary> /// <param name="policyTypeFilter">The policy type filter.</param> private async Task <ResponseWithContinuation <JObject[]> > GetResources(ListFilter policyTypeFilter) { string resourceId = this.GetResourceId(); var odataFilter = policyTypeFilter != ListFilter.None ? string.Format(PolicyCmdletBase.PolicyTypeFilterFormat, policyTypeFilter.ToString()) : null; var apiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.PolicySetDefintionApiVersion : this.ApiVersion; if (!string.IsNullOrEmpty(ResourceIdUtility.GetResourceName(resourceId))) { JObject resource; try { resource = await this .GetResourcesClient() .GetResource <JObject>( resourceId: resourceId, apiVersion: apiVersion, cancellationToken: this.CancellationToken.Value) .ConfigureAwait(continueOnCapturedContext: false); } catch (ErrorResponseMessageException ex) { if (!ex.Message.StartsWith("PolicySetDefinitionNotFound", StringComparison.OrdinalIgnoreCase)) { throw; } resourceId = this.GetBuiltinResourceId(); resource = await this .GetResourcesClient() .GetResource <JObject>( resourceId: resourceId, apiVersion: apiVersion, cancellationToken: this.CancellationToken.Value) .ConfigureAwait(continueOnCapturedContext: false); } return(resource.TryConvertTo(out ResponseWithContinuation <JObject[]> retVal) && retVal.Value != null ? retVal : new ResponseWithContinuation <JObject[]> { Value = resource.AsArray() }); } else { return(await this .GetResourcesClient() .ListObjectColleciton <JObject>( resourceCollectionId: resourceId, apiVersion: apiVersion, cancellationToken: this.CancellationToken.Value, odataQuery: odataFilter) .ConfigureAwait(continueOnCapturedContext: false)); } }
public override void ExecuteCmdlet() { WriteWarning("The output object type of this cmdlet will be modified in a future release."); FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(Id), DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id)) }; WriteObject(ResourcesClient.FilterResourceGroupDeployments(options), true); }
public override void ExecuteCmdlet() { try { ResourceIdentifier resourceIdentifier = (ResourceId != null) ? new ResourceIdentifier(ResourceId) : null; ResourceGroupName = ResourceGroupName ?? resourceIdentifier.ResourceGroupName; Name = Name ?? ResourceIdUtility.GetResourceName(ResourceId); // Get the template spec version model from the SDK: TemplateSpecVersion specificVersion = TemplateSpecsSdkClient.TemplateSpecsClient.TemplateSpecVersions.Get( ResourceGroupName, Name, Version ); // Get the parent template spec from the SDK. We do this because we want to retrieve the // template spec name with its proper casing for naming our main template output file (the // Name parameter may have mismatched casing): TemplateSpec parentTemplateSpec = TemplateSpecsSdkClient.TemplateSpecsClient.TemplateSpecs.Get(ResourceGroupName, Name); PackagedTemplate packagedTemplate = new PackagedTemplate(specificVersion); // TODO: Handle overwriting prompts... // Ensure our output path is resolved based on the current powershell working // directory instead of the current process directory: OutputFolder = ResolveUserPath(OutputFolder); string mainTemplateFileName = $"{parentTemplateSpec.Name}.{specificVersion.Name}.json"; string uiFormDefinitionFileName = $"{parentTemplateSpec.Name}.{specificVersion.Name}.uiformdefinition.json"; string fullRootTemplateFilePath = Path.GetFullPath( Path.Combine(OutputFolder, mainTemplateFileName) ); if (ShouldProcess(specificVersion.Id, $"Export to '{fullRootTemplateFilePath}'")) { TemplateSpecPackagingEngine.Unpack( packagedTemplate, OutputFolder, mainTemplateFileName, uiFormDefinitionFileName); } WriteObject(PowerShellUtilities.ConstructPSObject(null, "Path", fullRootTemplateFilePath)); } catch (Exception ex) { WriteExceptionError(ex); } }
public override void ExecuteCmdlet() { if (string.IsNullOrEmpty(ResourceGroupName) && string.IsNullOrEmpty(Name)) { ResourceGroupName = ResourceIdUtility.GetResourceGroupName(Id); Name = ResourceIdUtility.GetResourceName(Id); } ConfirmAction( ProjectResources.CancelResourceGroupDeploymentMessage, ResourceGroupName, () => ResourceManagerSdkClient.CancelDeployment(ResourceGroupName, Name)); WriteObject(true); }
public override void ExecuteCmdlet() { var options = new FilterDeploymentOptions(DeploymentScopeType.ResourceGroup) { ResourceGroupName = !string.IsNullOrEmpty(this.ResourceGroupName) ? this.ResourceGroupName : ResourceIdUtility.GetResourceGroupName(Id), DeploymentName = !string.IsNullOrEmpty(this.Name) ? this.Name : ResourceIdUtility.GetResourceName(Id) }; ConfirmAction( ProjectResources.CancelDeploymentMessage, ResourceGroupName, () => ResourceManagerSdkClient.CancelDeployment(options)); WriteObject(true); }
/// <summary> /// Constructs the resource /// </summary> private JToken GetResource(string resourceId, string apiVersion) { var resource = this.GetExistingResource(resourceId, apiVersion).Result.ToResource(); var policyDefinitionObject = new PolicyDefinition { Name = this.Name ?? ResourceIdUtility.GetResourceName(this.Id), Properties = new PolicyDefinitionProperties { Description = this.Description ?? (resource.Properties["description"] != null ? resource.Properties["description"].ToString() : null), DisplayName = this.DisplayName ?? (resource.Properties["displayName"] != null ? resource.Properties["displayName"].ToString() : null) } }; if (!string.IsNullOrEmpty(this.Policy)) { policyDefinitionObject.Properties.PolicyRule = JObject.Parse(GetObjectFromParameter(this.Policy).ToString()); } else { policyDefinitionObject.Properties.PolicyRule = JObject.Parse(resource.Properties["policyRule"].ToString()); } if (!string.IsNullOrEmpty(this.Metadata)) { policyDefinitionObject.Properties.Metadata = JObject.Parse(GetObjectFromParameter(this.Metadata).ToString()); } else { policyDefinitionObject.Properties.Metadata = resource.Properties["metaData"] == null ? null : JObject.Parse(resource.Properties["metaData"].ToString()); } if (!string.IsNullOrEmpty(this.Parameter)) { policyDefinitionObject.Properties.Parameters = JObject.Parse(GetObjectFromParameter(this.Parameter).ToString()); } else { policyDefinitionObject.Properties.Parameters = resource.Properties["parameters"] == null ? null : JObject.Parse(resource.Properties["parameters"].ToString()); } return(policyDefinitionObject.ToJToken()); }
public override void ExecuteCmdlet() { var deploymentName = !string.IsNullOrEmpty(this.Name) ? this.Name : !string.IsNullOrEmpty(this.Id) ? ResourceIdUtility.GetResourceName(this.Id) : this.InputObject.DeploymentName; ConfirmAction( ProjectResources.CancelDeploymentMessage, this.Name, () => ResourceManagerSdkClient.CancelDeploymentAtSubscriptionScope(deploymentName)); if (this.PassThru.IsPresent) { WriteObject(true); } }
protected override void ProcessRecord() { if (string.IsNullOrEmpty(ResourceGroupName) && string.IsNullOrEmpty(Name)) { ResourceGroupName = ResourceIdUtility.GetResourceGroupName(Id); Name = ResourceIdUtility.GetResourceName(Id); } ConfirmAction( Force.IsPresent, string.Format(ProjectResources.DeleteResourceGroupDeployment, Name), ProjectResources.DeleteResourceGroupDeploymentMessage, ResourceGroupName, () => ResourcesClient.DeleteDeployment(ResourceGroupName, Name)); WriteObject(true); }
public override void ExecuteCmdlet() { try { switch (ParameterSetName) { case GetTemplateSpecByNameParameterSet: WriteObject( TemplateSpecsSdkClient.GetTemplateSpec(Name, ResourceGroupName, Version) ); break; case GetTemplateSpecByIdParameterSet: WriteObject( TemplateSpecsSdkClient.GetTemplateSpec( ResourceIdUtility.GetResourceName(this.ResourceId), ResourceIdUtility.GetResourceGroupName(this.ResourceId), Version ) ); break; case ListTemplateSpecsParameterSet: var templateSpecs = !string.IsNullOrEmpty(ResourceGroupName) ? TemplateSpecsSdkClient.ListTemplateSpecsByResourceGroup(ResourceGroupName) : TemplateSpecsSdkClient.ListTemplateSpecsBySubscription(); var templateSpecListItems = templateSpecs .Select(ts => PSTemplateSpecListItem.FromTemplateSpec(ts)) .GroupBy(ts => ts.Id).Select(g => g.First()) // Required due to current backend bug returning duplicates .OrderBy(ts => ts.ResourceGroupName) .ThenBy(ts => ts.Name) .Distinct() .ToList(); WriteObject(templateSpecListItems); break; default: throw new PSInvalidOperationException(); } } catch (Exception ex) { WriteExceptionError(ex); } }
public override void ExecuteCmdlet() { try { string scriptName = ""; switch (ParameterSetName) { case RemoveDeploymentScriptByName: scriptName = Name; if (ShouldProcess(scriptName, "Remove Deployment Script")) { DeploymentScriptsSdkClient.DeleteDeploymentScript(scriptName, ResourceGroupName); } break; case RemoveDeploymentScriptByResourceId: scriptName = ResourceIdUtility.GetResourceName(this.Id); if (ShouldProcess(scriptName, "Remove Deployment Script")) { DeploymentScriptsSdkClient.DeleteDeploymentScript(scriptName, ResourceIdUtility.GetResourceGroupName(this.Id)); } break; case RemoveDeploymentScriptByInputObject: scriptName = InputObject.Name; if (ShouldProcess(scriptName, "Remove Deployment Script")) { DeploymentScriptsSdkClient.DeleteDeploymentScript(scriptName, ResourceIdUtility.GetResourceGroupName(InputObject.Id)); } break; default: throw new PSInvalidOperationException(); } if (PassThru.IsPresent) { WriteObject(true); } } catch (Exception ex) { WriteExceptionError(ex); } }
/// <summary> /// Converts a <see cref="Resource{JToken}"/> object into a <see cref="PSObject"/> object. /// </summary> /// <param name="resource">The <see cref="Resource{JToken}"/> object.</param> internal static PSObject ToPsObject(this Resource <JToken> resource) { var resourceType = string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetResourceType(resource.Id); var extensionResourceType = string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetExtensionResourceType(resource.Id); var objectDefinition = new Dictionary <string, object> { { "Name", resource.Name }, { "ResourceId", string.IsNullOrEmpty(resource.Id) ? null : resource.Id }, { "ResourceName", string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetResourceName(resource.Id) }, { "ResourceType", resourceType }, { "ExtensionResourceName", string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetExtensionResourceName(resource.Id) }, { "ExtensionResourceType", extensionResourceType }, { "Kind", resource.Kind }, { "ResourceGroupName", string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetResourceGroupName(resource.Id) }, { "Location", resource.Location }, { "SubscriptionId", string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetSubscriptionId(resource.Id) }, { "Tags", TagsHelper.GetTagsHashtable(resource.Tags) }, { "Plan", resource.Plan.ToJToken().ToPsObject() }, { "Properties", ResourceExtensions.GetProperties(resource) }, { "CreatedTime", resource.CreatedTime }, { "ChangedTime", resource.ChangedTime }, { "ETag", resource.ETag }, { "Sku", resource.Sku.ToJToken().ToPsObject() }, { "Zones", resource.Zones }, }; var resourceTypeName = resourceType == null && extensionResourceType == null ? null : (resourceType + extensionResourceType).Replace('/', '.'); var psObject = PowerShellUtilities.ConstructPSObject( resourceTypeName, objectDefinition.Where(kvp => kvp.Value != null).SelectManyArray(kvp => new[] { kvp.Key, kvp.Value })); psObject.TypeNames.Add(Constants.MicrosoftAzureResource); return(psObject); }
protected override void ProcessRecord() { FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(Id), DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id)), ProvisioningStates = string.IsNullOrEmpty(ProvisioningState) ? new List <string>() : new List <string>() { ProvisioningState } }; if (!string.IsNullOrEmpty(ProvisioningState)) { WriteWarning("The ProvisioningState parameter is being deprecated and will be removed in a future release."); } WriteObject(ResourcesClient.FilterResourceGroupDeployments(options), true); }
/// <summary> /// Constructs the resource /// </summary> private JToken GetResource(string resourceId, string apiVersion) { var resource = this.GetExistingResource(resourceId, apiVersion).Result.ToResource(); var policyAssignmentObject = new PolicyAssignment { Name = this.Name ?? ResourceIdUtility.GetResourceName(this.Id), Properties = new PolicyAssignmentProperties { DisplayName = this.DisplayName ?? (resource.Properties["displayName"] != null ? resource.Properties["displayName"].ToString() : null), Scope = resource.Properties["scope"].ToString(), PolicyDefinitionId = resource.Properties["policyDefinitionId"].ToString() } }; return(policyAssignmentObject.ToJToken()); }
protected override void OnProcessRecord() { var options = new FilterDeploymentOptions(DeploymentScopeType.Subscription) { DeploymentName = !string.IsNullOrEmpty(this.Name) ? this.Name : !string.IsNullOrEmpty(this.Id) ? ResourceIdUtility.GetResourceName(this.Id) : this.InputObject.DeploymentName }; ConfirmAction( ProjectResources.CancelDeploymentMessage, this.Name, () => ResourceManagerSdkClient.CancelDeployment(options)); if (this.PassThru.IsPresent) { WriteObject(true); } }
protected override void OnProcessRecord() { ConfirmAction( ProjectResources.DeleteDeploymentMessage, Name, () => { var deploymentName = !string.IsNullOrEmpty(this.Name) ? this.Name : !string.IsNullOrEmpty(this.Id) ? ResourceIdUtility.GetResourceName(this.Id) : this.InputObject.DeploymentName; ResourceManagerSdkClient.DeleteDeploymentAtSubscriptionScope(deploymentName); if (this.PassThru.IsPresent) { WriteObject(true); } }); }
public override void ExecuteCmdlet() { try { ResourceIdentifier resourceIdentifier = (ResourceId != null) ? new ResourceIdentifier(ResourceId) : null; ResourceGroupName = ResourceGroupName ?? resourceIdentifier.ResourceGroupName; Name = Name ?? ResourceIdUtility.GetResourceName(ResourceId); if (ResourceId != null && Version == null) { // Check if the resource id includes a version... string resourceType = resourceIdentifier.ResourceType; if (!string.IsNullOrEmpty(resourceType) && resourceType.Equals("Microsoft.Resources/templateSpecs/versions", StringComparison.OrdinalIgnoreCase)) { // It does... Version = resourceIdentifier.ResourceName; } } string confirmationMessage = (Version != null) ? $"Are you sure you want to remove version '{Version}' of Template Spec '{Name}'" : $"Are you sure you want to remove Template Spec '{Name}'"; ConfirmAction( Force.IsPresent, confirmationMessage, "Deleting Template Spec...", Version ?? Name, () => TemplateSpecsSdkClient.DeleteTemplateSpec(ResourceGroupName, Name, Version) ); WriteObject(true); } catch (Exception ex) { WriteExceptionError(ex); } }
protected override void ProcessRecord() { if (string.IsNullOrEmpty(ResourceGroupName) && string.IsNullOrEmpty(Name)) { ResourceGroupName = ResourceIdUtility.GetResourceGroupName(Id); Name = ResourceIdUtility.GetResourceName(Id); } ConfirmAction( Force.IsPresent, string.Format(ProjectResources.DeleteResourceGroupDeployment, Name), ProjectResources.DeleteResourceGroupDeploymentMessage, ResourceGroupName, () => ResourcesClient.DeleteDeployment(ResourceGroupName, Name)); if (PassThru) { WriteWarning("The PassThru switch parameter is being deprecated and will be removed in a future release."); WriteObject(true); } }
protected override void ProcessRecord() { if (string.IsNullOrEmpty(ResourceGroupName) && string.IsNullOrEmpty(Name)) { ResourceGroupName = ResourceIdUtility.GetResourceGroupName(Id); Name = ResourceIdUtility.GetResourceName(Id); } ConfirmAction( Force.IsPresent, string.Format(ProjectResources.CancelResourceGroupDeployment, ResourceGroupName), ProjectResources.CancelResourceGroupDeploymentMessage, ResourceGroupName, () => ResourcesClient.CancelDeployment(ResourceGroupName, Name)); if (PassThru) { WriteWarning("The output object of this cmdlet will be modified in a future release."); WriteObject(true); } }
public virtual object GetDynamicParameters() { if (!this.IsParameterBound(c => c.SkipTemplateParameterPrompt)) { // Resolve the static parameter names for this cmdlet: string[] staticParameterNames = this.GetStaticParameterNames(); if (TemplateObject != null && TemplateObject != templateObject) { templateObject = TemplateObject; if (string.IsNullOrEmpty(TemplateParameterUri)) { dynamicParameters = TemplateUtility.GetTemplateParametersFromFile( TemplateObject, TemplateParameterObject, this.ResolvePath(TemplateParameterFile), staticParameterNames); } else { dynamicParameters = TemplateUtility.GetTemplateParametersFromFile( TemplateObject, TemplateParameterObject, TemplateParameterUri, staticParameterNames); } } else if (!string.IsNullOrEmpty(TemplateFile) && !TemplateFile.Equals(templateFile, StringComparison.OrdinalIgnoreCase)) { templateFile = TemplateFile; if (string.IsNullOrEmpty(TemplateParameterUri)) { dynamicParameters = TemplateUtility.GetTemplateParametersFromFile( this.ResolvePath(TemplateFile), TemplateParameterObject, this.ResolvePath(TemplateParameterFile), staticParameterNames); } else { dynamicParameters = TemplateUtility.GetTemplateParametersFromFile( this.ResolvePath(TemplateFile), TemplateParameterObject, TemplateParameterUri, staticParameterNames); } } else if (!string.IsNullOrEmpty(TemplateUri) && !TemplateUri.Equals(templateUri, StringComparison.OrdinalIgnoreCase)) { if (string.IsNullOrEmpty(protectedTemplateUri)) { templateUri = TemplateUri; } else { templateUri = protectedTemplateUri; } if (string.IsNullOrEmpty(TemplateParameterUri)) { dynamicParameters = TemplateUtility.GetTemplateParametersFromFile( templateUri, TemplateParameterObject, this.ResolvePath(TemplateParameterFile), staticParameterNames); } else { dynamicParameters = TemplateUtility.GetTemplateParametersFromFile( templateUri, TemplateParameterObject, TemplateParameterUri, staticParameterNames); } } else if (!string.IsNullOrEmpty(TemplateSpecId) && !TemplateSpecId.Equals(templateSpecId, StringComparison.OrdinalIgnoreCase)) { templateSpecId = TemplateSpecId; ResourceIdentifier resourceIdentifier = new ResourceIdentifier(templateSpecId); if (!resourceIdentifier.ResourceType.Equals("Microsoft.Resources/templateSpecs/versions", StringComparison.OrdinalIgnoreCase)) { throw new PSArgumentException("No version found in Resource ID"); } if (!string.IsNullOrEmpty(resourceIdentifier.Subscription) && TemplateSpecsClient.SubscriptionId != resourceIdentifier.Subscription) { // The template spec is in a different subscription than our default // context. Force the client to use that subscription: TemplateSpecsClient.SubscriptionId = resourceIdentifier.Subscription; } var templateSpecVersion = TemplateSpecsClient.TemplateSpecVersions.Get( ResourceIdUtility.GetResourceGroupName(templateSpecId), ResourceIdUtility.GetResourceName(templateSpecId).Split('/')[0], resourceIdentifier.ResourceName); if (!(templateSpecVersion.Template is JObject)) { throw new InvalidOperationException("Unexpected type."); // Sanity check } JObject templateObj = (JObject)templateSpecVersion.Template; if (string.IsNullOrEmpty(TemplateParameterUri)) { dynamicParameters = TemplateUtility.GetTemplateParametersFromFile( templateObj, TemplateParameterObject, this.ResolvePath(TemplateParameterFile), staticParameterNames); } else { dynamicParameters = TemplateUtility.GetTemplateParametersFromFile( templateObj, TemplateParameterObject, TemplateParameterUri, staticParameterNames); } } } RegisterDynamicParameters(dynamicParameters); return(dynamicParameters); }
/// <summary> /// Returns true if it is a single policy assignment get /// </summary> /// <param name="resourceId"></param> private bool IsResourceGet(string resourceId) { return((!string.IsNullOrEmpty(this.Name) && !string.IsNullOrEmpty(this.Scope)) || !string.IsNullOrEmpty(ResourceIdUtility.GetResourceName(resourceId))); }