Skip to content

Commit a3eb6de

Browse files
authored
Merge branch 'master' into patch-1
2 parents 3dbdd69 + 7ee8c23 commit a3eb6de

19 files changed

+276
-97
lines changed

src/AlertsManagement/AlertsManagement/ActionRuleCommands/SetAzureActionRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ private string DetermineScopeType(string value)
561561
}
562562
else if (tokens.Length >= 9)
563563
{
564-
return ScopeType.ResourceGroup;
564+
return ScopeType.Resource;
565565
}
566566
else
567567
{

src/HealthcareApis/HealthcareApis/ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@
1919
-->
2020
## Upcoming Release
2121

22+
* Added Error Handling in all cmdlets
23+
* Fixed few typos
24+
* Enable Set-AzHealthcareApisService to allow updating tags.
25+
26+
## Version 0.1.0
27+
2228
* Added following CRUD operation cmdlets to HealthcareApis service.
2329
* New-AzHealthcareApisService, Set-AzHealthcareApisService, Get-AzHealthcareApisService, Remove-AzHealthcareApisService
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.HealthcareApis.Properties;
16+
using System;
17+
using System.Management.Automation;
18+
19+
namespace Microsoft.Azure.PowerShell.Cmdlets.HealthcareApis.Common
20+
{
21+
public static class HealthcareApisArgumentValidator
22+
{
23+
public static bool ValidateObjectId(string accessPolicyObjectId)
24+
{
25+
if (!Guid.TryParse(accessPolicyObjectId, out _))
26+
{
27+
throw new PSArgumentException(Resources.invalidAccessPolicyObjectIdMessage);
28+
}
29+
30+
return true;
31+
}
32+
}
33+
}

src/HealthcareApis/HealthcareApis/Common/HealthcareApisBaseCmdlet.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Microsoft.Azure.PowerShell.Cmdlets.HealthcareApis.Common;
2222
using Microsoft.Rest.Azure;
2323
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24+
using Newtonsoft.Json;
2425
using System;
2526
using System.Collections.Generic;
2627
using System.Management.Automation;
@@ -160,14 +161,36 @@ public static List<PSHealthcareApisService> ToPSFhirServices(IPage<ServicesDescr
160161
{
161162
using (IEnumerator<ServicesDescription> sdenumerator = fhirServiceApps.GetEnumerator())
162163
{
163-
var newpne = new List<PSHealthcareApisService>();
164+
var fhirServiceList = new List<PSHealthcareApisService>();
164165
while (sdenumerator.MoveNext())
165166
{
166167
PSHealthcareApisService psHealthCareFhirService = ToPSFhirService(sdenumerator.Current);
167-
newpne.Add(psHealthCareFhirService);
168+
fhirServiceList.Add(psHealthCareFhirService);
168169
}
169170

170-
return newpne;
171+
return fhirServiceList;
172+
}
173+
}
174+
175+
public static ErrorRecord WriteErrorforBadrequest(ErrorDetailsException ex)
176+
{
177+
if (ex != null && !string.IsNullOrEmpty(ex.Response.Content))
178+
{
179+
ErrorDetailsInternal errorExtract = new ErrorDetailsInternal();
180+
errorExtract = JsonConvert.DeserializeObject<ErrorDetailsInternal>(ex.Response.Content);
181+
if (!string.IsNullOrEmpty(errorExtract.Message))
182+
{
183+
return new ErrorRecord(ex, errorExtract.Message, ErrorCategory.OpenError, ex);
184+
}
185+
else
186+
{
187+
return new ErrorRecord(ex, ex.Response.Content, ErrorCategory.OpenError, ex);
188+
}
189+
}
190+
else
191+
{
192+
Exception emptyEx = new Exception("Response object empty");
193+
return new ErrorRecord(emptyEx, "Response object was empty", ErrorCategory.OpenError, emptyEx);
171194
}
172195
}
173196
}

src/HealthcareApis/HealthcareApis/HealthcareApis/GetAzureRmHealthcareApisService.cs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,16 @@ public override void ExecuteCmdlet()
7272
{
7373
case ServiceNameParameterSet:
7474
{
75-
var healthcareApisAccount = this.HealthcareApisClient.Services.Get(this.ResourceGroupName, this.Name);
76-
WriteHealthcareApisAccount(healthcareApisAccount);
75+
try
76+
{
77+
var healthcareApisAccount = this.HealthcareApisClient.Services.Get(this.ResourceGroupName, this.Name);
78+
WriteHealthcareApisAccount(healthcareApisAccount);
79+
}
80+
catch (ErrorDetailsException wex)
81+
{
82+
WriteError(WriteErrorforBadrequest(wex));
83+
}
84+
7785
break;
7886
}
7987
case ResourceIdParameterSet:
@@ -83,23 +91,44 @@ public override void ExecuteCmdlet()
8391

8492
if (ValidateAndExtractName(this.ResourceId, out resourceGroupName, out resourceName))
8593
{
86-
var healthcareApisAccount = this.HealthcareApisClient.Services.Get(resourceGroupName, resourceName);
87-
WriteHealthcareApisAccount(healthcareApisAccount);
94+
try
95+
{
96+
var healthcareApisAccount = this.HealthcareApisClient.Services.Get(resourceGroupName, resourceName);
97+
WriteHealthcareApisAccount(healthcareApisAccount);
98+
}
99+
catch (ErrorDetailsException wex)
100+
{
101+
WriteError(WriteErrorforBadrequest(wex));
102+
}
88103
}
89104
break;
90105
}
91106
case ListParameterSet:
92107
{
93108
if (string.IsNullOrEmpty(this.ResourceGroupName))
94109
{
95-
IPage<ServicesDescription> healthcareApisServicesBySubscription = this.HealthcareApisClient.Services.List();
96-
this.WriteObject(ToPSFhirServices(healthcareApisServicesBySubscription), enumerateCollection: true);
110+
try
111+
{
112+
IPage<ServicesDescription> healthcareApisServicesBySubscription = this.HealthcareApisClient.Services.List();
113+
this.WriteObject(ToPSFhirServices(healthcareApisServicesBySubscription), enumerateCollection: true);
114+
}
115+
catch (ErrorDetailsException wex)
116+
{
117+
WriteError(WriteErrorforBadrequest(wex));
118+
}
97119
break;
98120
}
99121
else
100122
{
101-
IPage<ServicesDescription> healthcareApisServicesResourceGroup = this.HealthcareApisClient.Services.ListByResourceGroup(this.ResourceGroupName);
102-
this.WriteObject(ToPSFhirServices(healthcareApisServicesResourceGroup), enumerateCollection: true);
123+
try
124+
{
125+
IPage<ServicesDescription> healthcareApisServicesResourceGroup = this.HealthcareApisClient.Services.ListByResourceGroup(this.ResourceGroupName);
126+
this.WriteObject(ToPSFhirServices(healthcareApisServicesResourceGroup), enumerateCollection: true);
127+
}
128+
catch (ErrorDetailsException wex)
129+
{
130+
WriteError(WriteErrorforBadrequest(wex));
131+
}
103132
break;
104133
}
105134
}

src/HealthcareApis/HealthcareApis/HealthcareApis/NewAzureRmHealthcareApisService.cs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
2424
using Microsoft.Azure.Commands.HealthcareApis.Properties;
2525
using System;
26+
using Microsoft.Azure.PowerShell.Cmdlets.HealthcareApis.Common;
2627

2728
namespace Microsoft.Azure.Commands.HealthcareApis.Commands
2829
{
@@ -39,7 +40,6 @@ public class NewAzureRmHealthcareApisService : HealthcareApisBaseCmdlet
3940
ValueFromPipelineByPropertyName = true,
4041
HelpMessage = "HealthcareApis Service Name.")]
4142
[ValidateNotNullOrEmpty]
42-
[ValidatePattern("^[a-z0-9][a-z0-9-]{1,21}[a-z0-9]$")]
4343
[ValidateLength(2, 64)]
4444
public string Name { get; set; }
4545

@@ -70,7 +70,6 @@ public class NewAzureRmHealthcareApisService : HealthcareApisBaseCmdlet
7070
Mandatory = false,
7171
HelpMessage = "List of Access Policy Object IDs.")]
7272
[ValidateNotNullOrEmpty]
73-
[ValidatePattern("^(([0-9A-Fa-f]{8}[-]?(?:[0-9A-Fa-f]{4}[-]?){3}[0-9A-Fa-f]{12}){1})+$")]
7473
public string[] AccessPolicyObjectId { get; set; }
7574

7675
[Parameter(
@@ -83,7 +82,6 @@ public class NewAzureRmHealthcareApisService : HealthcareApisBaseCmdlet
8382
Mandatory = false,
8483
HelpMessage = "HealthcareApis Fhir Service Audience.")]
8584
[ValidateNotNullOrEmpty]
86-
[ValidatePattern("^((?:[hH][tT][tT][pP](?:[sS]|)\\:\\/\\/.+)|([0-9A-Fa-f]{8}[-]?(?:[0-9A-Fa-f]{4}[-]?){3}[0-9A-Fa-f]{12}))$")]
8785
public string Audience { get; set; }
8886

8987
[Parameter(
@@ -98,33 +96,28 @@ public class NewAzureRmHealthcareApisService : HealthcareApisBaseCmdlet
9896
[ValidateNotNullOrEmpty]
9997
public string[] CorsHeader { get; set; }
10098

101-
10299
[Parameter(
103100
Mandatory = false,
104101
HelpMessage = "HealthcareApis Fhir Service Cors Max Age. Specify how long a result from a request can be cached in seconds. Example: 600 means 10 minutes.")]
105102
[ValidateNotNullOrEmpty]
106-
[ValidateRange(0,99999)]
107103
public int CorsMaxAge { get; set; }
108104

109105
[Parameter(
110106
Mandatory = false,
111107
HelpMessage = "HealthcareApis Fhir Service List of Cors Method.")]
112108
[ValidateNotNullOrEmpty]
113-
[ValidateSet("DELETE", "GET", "OPTIONS", "PATCH", "POST", "PUT")]
114109
public string[] CorsMethod { get; set; }
115110

116111
[Parameter(
117112
Mandatory = false,
118113
HelpMessage = "HealthcareApis Fhir Service List of Cors Origin. Specify URLs of origin sites that can access this API, or use \" * \" to allow access from any site.")]
119114
[ValidateNotNullOrEmpty]
120-
[ValidatePattern("^(?:(?:(?:[hH][tT][tT][pP](?:[sS]|))\\:\\/\\/(?:[a-zA-Z0-9-]+[.]?)+(?:\\:[0-9]{1,5})?|[*]))$")]
121115
public string[] CorsOrigin { get; set; }
122116

123117
[Parameter(
124118
Mandatory = false,
125119
HelpMessage = "HealthcareApis Fhir Service CosmosOfferThroughput.")]
126120
[ValidateNotNullOrEmpty]
127-
[ValidateRange(400,10000)]
128121
public int? CosmosOfferThroughput { get; set; }
129122

130123

@@ -160,18 +153,7 @@ public override void ExecuteCmdlet()
160153

161154
RunCmdLet(() =>
162155
{
163-
if (AccessPolicyObjectId == null || AccessPolicyObjectId.Length == 0)
164-
{
165-
AccessPolicyObjectId = new string[1];
166-
string objectID = base.AccessPolicyID;
167-
AccessPolicyObjectId[0] = objectID;
168-
}
169-
170-
List<ServiceAccessPolicyEntry> accessPolicies = new List<ServiceAccessPolicyEntry>();
171-
foreach (string objectId in AccessPolicyObjectId)
172-
{
173-
accessPolicies.Add(new ServiceAccessPolicyEntry(objectId));
174-
}
156+
List<ServiceAccessPolicyEntry> accessPolicies = GetAccessPolicies();
175157

176158
ServicesDescription servicesDescription = new ServicesDescription()
177159
{
@@ -193,18 +175,45 @@ public override void ExecuteCmdlet()
193175

194176
this.EnsureNameAvailabilityOrThrow();
195177

196-
var createAccountResponse = this.HealthcareApisClient.Services.CreateOrUpdate(
197-
this.ResourceGroupName,
198-
this.Name,
199-
servicesDescription);
178+
try
179+
{
180+
var createAccountResponse = this.HealthcareApisClient.Services.CreateOrUpdate(
181+
this.ResourceGroupName,
182+
this.Name,
183+
servicesDescription);
200184

201-
var healthCareFhirService = this.HealthcareApisClient.Services.Get(this.ResourceGroupName, this.Name);
202185

203-
WriteObject(healthCareFhirService);
186+
var healthCareFhirService = this.HealthcareApisClient.Services.Get(this.ResourceGroupName, this.Name);
187+
WriteObject(healthCareFhirService);
188+
}
189+
catch (ErrorDetailsException wex)
190+
{
191+
WriteError(WriteErrorforBadrequest(wex));
192+
}
204193
}
205194
});
206195
}
207196

197+
private List<ServiceAccessPolicyEntry> GetAccessPolicies()
198+
{
199+
List<ServiceAccessPolicyEntry> accessPolicies = new List<ServiceAccessPolicyEntry>();
200+
201+
if (AccessPolicyObjectId == null || AccessPolicyObjectId.Length == 0)
202+
{
203+
string objectID = base.AccessPolicyID;
204+
accessPolicies.Add(new ServiceAccessPolicyEntry(objectID));
205+
return accessPolicies;
206+
}
207+
208+
foreach (var objectID in AccessPolicyObjectId)
209+
{
210+
HealthcareApisArgumentValidator.ValidateObjectId(objectID);
211+
accessPolicies.Add(new ServiceAccessPolicyEntry(objectID));
212+
}
213+
214+
return accessPolicies;
215+
}
216+
208217
private Kind GetKind()
209218
{
210219
if(this.Kind == null && this.FhirVersion!=null)

src/HealthcareApis/HealthcareApis/HealthcareApis/RemoveAzureRmHealthcareApisService.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Globalization;
2020
using System.Management.Automation;
2121
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
22+
using Microsoft.Azure.Management.HealthcareApis.Models;
2223

2324
namespace Microsoft.Azure.Commands.HealthcareApis.Commands
2425
{
@@ -106,10 +107,17 @@ public override void ExecuteCmdlet()
106107
&& !string.IsNullOrEmpty(name)
107108
&& ShouldProcess(name, string.Format(CultureInfo.CurrentCulture, Resources.RemoveService_ProcessMessage, name)))
108109
{
109-
this.HealthcareApisClient.Services.Delete(rgName, name);
110-
if (PassThru.IsPresent)
110+
try
111111
{
112-
WriteObject(true);
112+
this.HealthcareApisClient.Services.Delete(rgName, name);
113+
if (PassThru.IsPresent)
114+
{
115+
WriteObject(true);
116+
}
117+
}
118+
catch (ErrorDetailsException wex)
119+
{
120+
WriteError(WriteErrorforBadrequest(wex));
113121
}
114122
}
115123
});

0 commit comments

Comments
 (0)