Skip to content

Support for ARM VNET + Internal Workloads + Soap Api's #2971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ResourceManager/ApiManagement/ApiManagement.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{95C16AED-FD57-42A0-86C3-2CF4300A4817}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class ApiManagementClient
private readonly AzureContext _context;
private Management.ApiManagement.ApiManagementClient _client;

private readonly JsonSerializerSettings _jsonSerializerSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };

static ApiManagementClient()
{
ConfugureMappings();
Expand Down Expand Up @@ -355,7 +357,7 @@ public void ApiSet(
Description = description,
ServiceUrl = serviceUrl,
Path = urlSuffix,
Protocols = Mapper.Map<IList<ApiProtocolContract>>(urlSchema),
Protocols = Mapper.Map<IList<ApiProtocolContract>>(urlSchema)
};

if (!string.IsNullOrWhiteSpace(authorizationServerId))
Expand All @@ -379,32 +381,34 @@ public void ApiSet(
};
}

Client.Apis.CreateOrUpdate(context.ResourceGroupName, context.ServiceName, id, new ApiCreateOrUpdateParameters(api), "*");
// fix for issue https://github.com/Azure/azure-powershell/issues/2606
var apiPatchContract = JsonConvert.SerializeObject(api, _jsonSerializerSetting);

Client.Apis.Patch(
context.ResourceGroupName,
context.ServiceName,
id,
new PatchParameters
{
RawJson = apiPatchContract
},
"*");
}

public void ApiImportFromFile(
PsApiManagementContext context,
string apiId,
PsApiManagementApiFormat specificationFormat,
string specificationPath,
string urlSuffix)
string urlSuffix,
string wsdlServiceName,
string wsdlEndpointName)
{
string contentType;
switch (specificationFormat)
{
case PsApiManagementApiFormat.Wadl:
contentType = "application/vnd.sun.wadl+xml";
break;
case PsApiManagementApiFormat.Swagger:
contentType = "application/vnd.swagger.doc+json";
break;
default:
throw new ArgumentException(string.Format("Format '{0}' is not supported.", specificationFormat));
}
string contentType = GetHeaderValue(specificationFormat, wsdlServiceName, wsdlEndpointName, true);

using (var fileStream = File.OpenRead(specificationPath))
{
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, fileStream, urlSuffix);
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, fileStream, urlSuffix, wsdlServiceName, wsdlEndpointName);
}
}

Expand All @@ -413,20 +417,11 @@ public void ApiImportFromUrl(
string apiId,
PsApiManagementApiFormat specificationFormat,
string specificationUrl,
string urlSuffix)
string urlSuffix,
string wsdlServiceName,
string wsdlEndpointName)
{
string contentType;
switch (specificationFormat)
{
case PsApiManagementApiFormat.Wadl:
contentType = "application/vnd.sun.wadl.link+json";
break;
case PsApiManagementApiFormat.Swagger:
contentType = "application/vnd.swagger.link+json";
break;
default:
throw new ArgumentException(string.Format("Format '{0}' is not supported.", specificationFormat));
}
string contentType = GetHeaderValue(specificationFormat, wsdlServiceName, wsdlEndpointName, true);

var jobj = JObject.FromObject(
new
Expand All @@ -436,7 +431,7 @@ public void ApiImportFromUrl(

using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(jobj.ToString(Formatting.None))))
{
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, memoryStream, urlSuffix);
Client.Apis.Import(context.ResourceGroupName, context.ServiceName, apiId, contentType, memoryStream, urlSuffix, wsdlServiceName, wsdlEndpointName);
}
}

Expand All @@ -446,21 +441,44 @@ public byte[] ApiExportToFile(
PsApiManagementApiFormat specificationFormat,
string saveAs)
{
string contentType;
switch (specificationFormat)
string acceptType = GetHeaderValue(specificationFormat, string.Empty, string.Empty, false);

var response = Client.Apis.Export(context.ResourceGroupName, context.ServiceName, apiId, acceptType);
return response.Content;
}

private string GetHeaderValue(
PsApiManagementApiFormat specificationApiFormat,
string wsdlServiceName,
string wsdlEndpointName,
bool validateWsdlParams)
{
string headerValue;
switch (specificationApiFormat)
{
case PsApiManagementApiFormat.Wadl:
contentType = "application/vnd.sun.wadl+xml";
headerValue = "application/vnd.sun.wadl+xml";
break;
case PsApiManagementApiFormat.Swagger:
contentType = "application/vnd.swagger.doc+json";
headerValue = "application/vnd.swagger.doc+json";
break;
case PsApiManagementApiFormat.Wsdl:
headerValue = "application/wsdl+xml";
if (validateWsdlParams && string.IsNullOrEmpty(wsdlServiceName))
{
throw new ArgumentException(string.Format("WsdlServiceName cannot be Empty for Format : {0}", specificationApiFormat));
}

if (validateWsdlParams && string.IsNullOrEmpty(wsdlEndpointName))
{
throw new ArgumentException(string.Format("WsdlEndpointName cannot be Empty for Format : {0}", specificationApiFormat));
}
break;
default:
throw new ArgumentException(string.Format("Format '{0}' is not supported.", specificationFormat));
throw new ArgumentException(string.Format("Format '{0}' is not supported.", specificationApiFormat));
}

var response = Client.Apis.Export(context.ResourceGroupName, context.ServiceName, apiId, contentType);
return response.Content;
return headerValue;
}

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

Client.ApiOperations.Update(
var operationPatchContract = JsonConvert.SerializeObject(operationContract, _jsonSerializerSetting);

Client.ApiOperations.Patch(
context.ResourceGroupName,
context.ServiceName,
apiId,
operationId,
new OperationCreateOrUpdateParameters(operationContract),
new PatchParameters
{
RawJson = operationPatchContract
},
"*");
}

Expand Down Expand Up @@ -865,6 +888,13 @@ public void UserSet(
{
userUpdateParameters.State = Mapper.Map<UserStateContract>(state.Value);
}
else
{
// if state not specified, fetch state.
// fix for issue https://github.com/Azure/azure-powershell/issues/2622
var currentUser = Client.Users.Get(context.ResourceGroupName, context.ServiceName, userId);
userUpdateParameters.State = currentUser.Value.State;
}

Client.Users.Update(context.ResourceGroupName, context.ServiceName, userId, userUpdateParameters, "*");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
<HintPath>..\..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.ApiManagement, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Reference Include="Microsoft.Azure.Management.ApiManagement, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ApiManagement.2.0.3-preview\lib\net40\Microsoft.Azure.Management.ApiManagement.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ApiManagement.3.0.0-preview\lib\net45\Microsoft.Azure.Management.ApiManagement.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down Expand Up @@ -290,4 +290,4 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ImportAzureApiManagementApi : AzureApiManagementCmdletBase
[Parameter(
ValueFromPipelineByPropertyName = true,
Mandatory = true,
HelpMessage = "Specification format (Wadl, Swagger). This parameter is required.")]
HelpMessage = "Specification format (Wadl, Swagger, Wsdl). This parameter is required.")]
[ValidateNotNullOrEmpty]
public PsApiManagementApiFormat SpecificationFormat { get; set; }

Expand All @@ -67,15 +67,29 @@ public class ImportAzureApiManagementApi : AzureApiManagementCmdletBase
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.")]
public String Path { get; set; }

[Parameter(
ValueFromPipelineByPropertyName = true,
Mandatory = false,
HelpMessage = "Local name of WSDL Service to be imported. Must be 1 to 400 characters long." +
" This parameter is optional and only required for importing Wsdl . Default value is $null.")]
public String WsdlServiceName { get; set; }

[Parameter(
ValueFromPipelineByPropertyName = true,
Mandatory = false,
HelpMessage = "Local name of WSDL Endpoint (port) to be imported." +
" Must be 1 to 400 characters long. This parameter is optional and only required for importing Wsdl. Default value is $null.")]
public String WsdlEndpointName { get; set; }

public override void ExecuteApiManagementCmdlet()
{
if (ParameterSetName.Equals(FromLocalFile))
{
Client.ApiImportFromFile(Context, ApiId, SpecificationFormat, SpecificationPath, Path);
Client.ApiImportFromFile(Context, ApiId, SpecificationFormat, SpecificationPath, Path, WsdlServiceName, WsdlEndpointName);
}
else if (ParameterSetName.Equals(FromUrl))
{
Client.ApiImportFromUrl(Context, ApiId, SpecificationFormat, SpecificationUrl, Path);
Client.ApiImportFromUrl(Context, ApiId, SpecificationFormat, SpecificationUrl, Path, WsdlServiceName, WsdlEndpointName);
}
else
{
Expand Down
Loading