Skip to content

Commit 550d52b

Browse files
authored
Merge pull request #2971 from solankisamir/apim-vnet-soap
Support for ARM VNET + Internal Workloads + Soap Api's
2 parents ac9d94d + 8289738 commit 550d52b

File tree

65 files changed

+36021
-9427
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+36021
-9427
lines changed

src/ResourceManager/ApiManagement/ApiManagement.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio 2013
3-
VisualStudioVersion = 12.0.40629.0
2+
# Visual Studio 14
3+
VisualStudioVersion = 14.0.25420.1
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{95C16AED-FD57-42A0-86C3-2CF4300A4817}"
66
EndProject

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/ApiManagementClient.cs

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class ApiManagementClient
4747
private readonly AzureContext _context;
4848
private Management.ApiManagement.ApiManagementClient _client;
4949

50+
private readonly JsonSerializerSettings _jsonSerializerSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
51+
5052
static ApiManagementClient()
5153
{
5254
ConfugureMappings();
@@ -355,7 +357,7 @@ public void ApiSet(
355357
Description = description,
356358
ServiceUrl = serviceUrl,
357359
Path = urlSuffix,
358-
Protocols = Mapper.Map<IList<ApiProtocolContract>>(urlSchema),
360+
Protocols = Mapper.Map<IList<ApiProtocolContract>>(urlSchema)
359361
};
360362

361363
if (!string.IsNullOrWhiteSpace(authorizationServerId))
@@ -379,32 +381,34 @@ public void ApiSet(
379381
};
380382
}
381383

382-
Client.Apis.CreateOrUpdate(context.ResourceGroupName, context.ServiceName, id, new ApiCreateOrUpdateParameters(api), "*");
384+
// fix for issue https://github.com/Azure/azure-powershell/issues/2606
385+
var apiPatchContract = JsonConvert.SerializeObject(api, _jsonSerializerSetting);
386+
387+
Client.Apis.Patch(
388+
context.ResourceGroupName,
389+
context.ServiceName,
390+
id,
391+
new PatchParameters
392+
{
393+
RawJson = apiPatchContract
394+
},
395+
"*");
383396
}
384397

385398
public void ApiImportFromFile(
386399
PsApiManagementContext context,
387400
string apiId,
388401
PsApiManagementApiFormat specificationFormat,
389402
string specificationPath,
390-
string urlSuffix)
403+
string urlSuffix,
404+
string wsdlServiceName,
405+
string wsdlEndpointName)
391406
{
392-
string contentType;
393-
switch (specificationFormat)
394-
{
395-
case PsApiManagementApiFormat.Wadl:
396-
contentType = "application/vnd.sun.wadl+xml";
397-
break;
398-
case PsApiManagementApiFormat.Swagger:
399-
contentType = "application/vnd.swagger.doc+json";
400-
break;
401-
default:
402-
throw new ArgumentException(string.Format("Format '{0}' is not supported.", specificationFormat));
403-
}
407+
string contentType = GetHeaderValue(specificationFormat, wsdlServiceName, wsdlEndpointName, true);
404408

405409
using (var fileStream = File.OpenRead(specificationPath))
406410
{
407-
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, fileStream, urlSuffix);
411+
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, fileStream, urlSuffix, wsdlServiceName, wsdlEndpointName);
408412
}
409413
}
410414

@@ -413,20 +417,11 @@ public void ApiImportFromUrl(
413417
string apiId,
414418
PsApiManagementApiFormat specificationFormat,
415419
string specificationUrl,
416-
string urlSuffix)
420+
string urlSuffix,
421+
string wsdlServiceName,
422+
string wsdlEndpointName)
417423
{
418-
string contentType;
419-
switch (specificationFormat)
420-
{
421-
case PsApiManagementApiFormat.Wadl:
422-
contentType = "application/vnd.sun.wadl.link+json";
423-
break;
424-
case PsApiManagementApiFormat.Swagger:
425-
contentType = "application/vnd.swagger.link+json";
426-
break;
427-
default:
428-
throw new ArgumentException(string.Format("Format '{0}' is not supported.", specificationFormat));
429-
}
424+
string contentType = GetHeaderValue(specificationFormat, wsdlServiceName, wsdlEndpointName, true);
430425

431426
var jobj = JObject.FromObject(
432427
new
@@ -436,7 +431,7 @@ public void ApiImportFromUrl(
436431

437432
using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(jobj.ToString(Formatting.None))))
438433
{
439-
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, memoryStream, urlSuffix);
434+
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, memoryStream, urlSuffix, wsdlServiceName, wsdlEndpointName);
440435
}
441436
}
442437

@@ -446,21 +441,44 @@ public byte[] ApiExportToFile(
446441
PsApiManagementApiFormat specificationFormat,
447442
string saveAs)
448443
{
449-
string contentType;
450-
switch (specificationFormat)
444+
string acceptType = GetHeaderValue(specificationFormat, string.Empty, string.Empty, false);
445+
446+
var response = Client.Apis.Export(context.ResourceGroupName, context.ServiceName, apiId, acceptType);
447+
return response.Content;
448+
}
449+
450+
private string GetHeaderValue(
451+
PsApiManagementApiFormat specificationApiFormat,
452+
string wsdlServiceName,
453+
string wsdlEndpointName,
454+
bool validateWsdlParams)
455+
{
456+
string headerValue;
457+
switch (specificationApiFormat)
451458
{
452459
case PsApiManagementApiFormat.Wadl:
453-
contentType = "application/vnd.sun.wadl+xml";
460+
headerValue = "application/vnd.sun.wadl+xml";
454461
break;
455462
case PsApiManagementApiFormat.Swagger:
456-
contentType = "application/vnd.swagger.doc+json";
463+
headerValue = "application/vnd.swagger.doc+json";
464+
break;
465+
case PsApiManagementApiFormat.Wsdl:
466+
headerValue = "application/wsdl+xml";
467+
if (validateWsdlParams && string.IsNullOrEmpty(wsdlServiceName))
468+
{
469+
throw new ArgumentException(string.Format("WsdlServiceName cannot be Empty for Format : {0}", specificationApiFormat));
470+
}
471+
472+
if (validateWsdlParams && string.IsNullOrEmpty(wsdlEndpointName))
473+
{
474+
throw new ArgumentException(string.Format("WsdlEndpointName cannot be Empty for Format : {0}", specificationApiFormat));
475+
}
457476
break;
458477
default:
459-
throw new ArgumentException(string.Format("Format '{0}' is not supported.", specificationFormat));
478+
throw new ArgumentException(string.Format("Format '{0}' is not supported.", specificationApiFormat));
460479
}
461480

462-
var response = Client.Apis.Export(context.ResourceGroupName, context.ServiceName, apiId, contentType);
463-
return response.Content;
481+
return headerValue;
464482
}
465483

466484
public void ApiAddToProduct(PsApiManagementContext context, string productId, string apiId)
@@ -573,12 +591,17 @@ public void OperationSet(
573591
operationContract.Responses = Mapper.Map<IList<ResponseContract>>(responses);
574592
}
575593

576-
Client.ApiOperations.Update(
594+
var operationPatchContract = JsonConvert.SerializeObject(operationContract, _jsonSerializerSetting);
595+
596+
Client.ApiOperations.Patch(
577597
context.ResourceGroupName,
578598
context.ServiceName,
579599
apiId,
580600
operationId,
581-
new OperationCreateOrUpdateParameters(operationContract),
601+
new PatchParameters
602+
{
603+
RawJson = operationPatchContract
604+
},
582605
"*");
583606
}
584607

@@ -865,6 +888,13 @@ public void UserSet(
865888
{
866889
userUpdateParameters.State = Mapper.Map<UserStateContract>(state.Value);
867890
}
891+
else
892+
{
893+
// if state not specified, fetch state.
894+
// fix for issue https://github.com/Azure/azure-powershell/issues/2622
895+
var currentUser = Client.Users.Get(context.ResourceGroupName, context.ServiceName, userId);
896+
userUpdateParameters.State = currentUser.Value.State;
897+
}
868898

869899
Client.Users.Update(context.ResourceGroupName, context.ServiceName, userId, userUpdateParameters, "*");
870900
}

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands.ApiManagement.ServiceManagement.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
<HintPath>..\..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
6767
<Private>True</Private>
6868
</Reference>
69-
<Reference Include="Microsoft.Azure.Management.ApiManagement, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
69+
<Reference Include="Microsoft.Azure.Management.ApiManagement, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7070
<SpecificVersion>False</SpecificVersion>
71-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ApiManagement.2.0.3-preview\lib\net40\Microsoft.Azure.Management.ApiManagement.dll</HintPath>
71+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ApiManagement.3.0.0-preview\lib\net45\Microsoft.Azure.Management.ApiManagement.dll</HintPath>
7272
<Private>True</Private>
7373
</Reference>
7474
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -290,4 +290,4 @@
290290
</ItemGroup>
291291
<ItemGroup />
292292
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
293-
</Project>
293+
</Project>

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/ImportAzureApiManagementApi.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class ImportAzureApiManagementApi : AzureApiManagementCmdletBase
4141
[Parameter(
4242
ValueFromPipelineByPropertyName = true,
4343
Mandatory = true,
44-
HelpMessage = "Specification format (Wadl, Swagger). This parameter is required.")]
44+
HelpMessage = "Specification format (Wadl, Swagger, Wsdl). This parameter is required.")]
4545
[ValidateNotNullOrEmpty]
4646
public PsApiManagementApiFormat SpecificationFormat { get; set; }
4747

@@ -67,15 +67,29 @@ public class ImportAzureApiManagementApi : AzureApiManagementCmdletBase
6767
HelpMessage = "Web API Path. Last part of the API's public URL. This URL will be used by API consumers for sending requests to the web service. Must be 1 to 400 characters long. This parameter is optional. Default value is $null.")]
6868
public String Path { get; set; }
6969

70+
[Parameter(
71+
ValueFromPipelineByPropertyName = true,
72+
Mandatory = false,
73+
HelpMessage = "Local name of WSDL Service to be imported. Must be 1 to 400 characters long." +
74+
" This parameter is optional and only required for importing Wsdl . Default value is $null.")]
75+
public String WsdlServiceName { get; set; }
76+
77+
[Parameter(
78+
ValueFromPipelineByPropertyName = true,
79+
Mandatory = false,
80+
HelpMessage = "Local name of WSDL Endpoint (port) to be imported." +
81+
" Must be 1 to 400 characters long. This parameter is optional and only required for importing Wsdl. Default value is $null.")]
82+
public String WsdlEndpointName { get; set; }
83+
7084
public override void ExecuteApiManagementCmdlet()
7185
{
7286
if (ParameterSetName.Equals(FromLocalFile))
7387
{
74-
Client.ApiImportFromFile(Context, ApiId, SpecificationFormat, SpecificationPath, Path);
88+
Client.ApiImportFromFile(Context, ApiId, SpecificationFormat, SpecificationPath, Path, WsdlServiceName, WsdlEndpointName);
7589
}
7690
else if (ParameterSetName.Equals(FromUrl))
7791
{
78-
Client.ApiImportFromUrl(Context, ApiId, SpecificationFormat, SpecificationUrl, Path);
92+
Client.ApiImportFromUrl(Context, ApiId, SpecificationFormat, SpecificationUrl, Path, WsdlServiceName, WsdlEndpointName);
7993
}
8094
else
8195
{

0 commit comments

Comments
 (0)