public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.ResourceId)) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); this.ResourceGroupName = resourceIdentifier.ResourceGroupName; this.WorkspaceName = resourceIdentifier.ParentResource; this.WorkspaceName = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1); this.Name = resourceIdentifier.ResourceName; } if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (!string.IsNullOrEmpty(this.Name)) { var result = new PSWorkspaceKey(this.SynapseAnalyticsClient.GetKey(this.ResourceGroupName, this.WorkspaceName, this.Name)); WriteObject(result); } else { var result = this.SynapseAnalyticsClient.ListKeys(this.ResourceGroupName, this.WorkspaceName).Select(r => new PSWorkspaceKey(r)); WriteObject(result, true); } }
public override void ExecuteCmdlet() { if (this.IsParameterBound(c => c.WorkspaceObject)) { this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName; this.WorkspaceName = this.WorkspaceObject.Name; } if (string.IsNullOrEmpty(this.ResourceGroupName)) { this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName); } var existingWorkspace = this.SynapseAnalyticsClient.GetWorkspaceOrDefault(this.ResourceGroupName, this.WorkspaceName); if (existingWorkspace == null) { throw new AzPSResourceNotFoundCloudException(string.Format(Resources.WorkspaceDoesNotExist, this.WorkspaceName)); } var existingKey = this.SynapseAnalyticsClient.GetKeyOrDefault(this.ResourceGroupName, this.WorkspaceName, this.Name); if (existingKey != null) { throw new AzPSInvalidOperationException(string.Format(Resources.WorkspaceKeyExists, this.Name, this.ResourceGroupName, this.WorkspaceName)); } var createParams = new Key { IsActiveCMK = this.Activate.IsPresent, KeyVaultUrl = this.EncryptionKeyIdentifier }; if (!this.IsParameterBound(c => c.Name)) { this.Name = SynapseConstants.DefaultName; } if (this.ShouldProcess(this.Name, string.Format(Resources.CreatingSynapseWorkspaceKey, this.ResourceGroupName, this.WorkspaceName, this.Name))) { var result = new PSWorkspaceKey(this.SynapseAnalyticsClient.CreateOrUpdateKey(this.ResourceGroupName, this.WorkspaceName, this.Name, createParams)); WriteObject(result); } }