Skip to content

added cmdlets for logger, properties, git and openIdConnect #2155

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 7 commits into from
Apr 28, 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</Reference>
<Reference Include="Microsoft.Azure.Management.ApiManagement, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ApiManagement.2.0.1-preview\lib\net40\Microsoft.Azure.Management.ApiManagement.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.ApiManagement.2.0.2-preview\lib\net40\Microsoft.Azure.Management.ApiManagement.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -150,49 +150,76 @@
<Compile Include="Commands\GetAzureApiManagementAuthorizationServer.cs" />
<Compile Include="Commands\GetAzureApiManagementCertificate.cs" />
<Compile Include="Commands\GetAzureApiManagementGroup.cs" />
<Compile Include="Commands\GetAzureApiManagementLogger.cs" />
<Compile Include="Commands\GetAzureApiManagementOpenIdConnectProvider.cs" />
<Compile Include="Commands\GetAzureApiManagementOperation.cs" />
<Compile Include="Commands\GetAzureApiManagementPolicy.cs" />
<Compile Include="Commands\GetAzureApiManagementProduct.cs" />
<Compile Include="Commands\GetAzureApiManagementProperty.cs" />
<Compile Include="Commands\GetAzureApiManagementSubscription.cs" />
<Compile Include="Commands\GetAzureApiManagementTenantSyncState.cs" />
<Compile Include="Commands\GetAzureApiManagementUser.cs" />
<Compile Include="Commands\GetAzureApiManagementUserSsoUrl.cs" />
<Compile Include="Commands\GetAzureRmApiManagementTenantGitAccess.cs" />
<Compile Include="Commands\ImportAzureApiManagementApi.cs" />
<Compile Include="Commands\NewAzureApiManagementApi.cs" />
<Compile Include="Commands\NewAzureApiManagementAuthorizationServer.cs" />
<Compile Include="Commands\NewAzureApiManagementCertificate.cs" />
<Compile Include="Commands\NewAzureApiManagementContext.cs" />
<Compile Include="Commands\NewAzureApiManagementGroup.cs" />
<Compile Include="Commands\NewAzureApiManagementLogger.cs" />
<Compile Include="Commands\NewAzureApiManagementOpenIdConnectProvider.cs" />
<Compile Include="Commands\NewAzureApiManagementOperation.cs" />
<Compile Include="Commands\NewAzureApiManagementProduct.cs" />
<Compile Include="Commands\NewAzureApiManagementSubscription.cs" />
<Compile Include="Commands\NewAzureApiManagementUser.cs" />
<Compile Include="Commands\NewAzureApiManagmentProperty.cs" />
<Compile Include="Commands\PublishAzureApiManagementTenantConfiguration.cs" />
<Compile Include="Commands\RemoveAzureApiManagementApi.cs" />
<Compile Include="Commands\RemoveAzureApiManagementApiFromProduct.cs" />
<Compile Include="Commands\RemoveAzureApiManagementAuthorizationServer.cs" />
<Compile Include="Commands\RemoveAzureApiManagementCertificate.cs" />
<Compile Include="Commands\RemoveAzureApiManagementGroup.cs" />
<Compile Include="Commands\RemoveAzureApiManagementLogger.cs" />
<Compile Include="Commands\RemoveAzureApiManagementOpenIdConnectProvider.cs" />
<Compile Include="Commands\RemoveAzureApiManagementOperation.cs" />
<Compile Include="Commands\RemoveAzureApiManagementPolicy.cs" />
<Compile Include="Commands\RemoveAzureApiManagementProduct.cs" />
<Compile Include="Commands\RemoveAzureApiManagementProductFromGroup.cs" />
<Compile Include="Commands\RemoveAzureApiManagementProperty.cs" />
<Compile Include="Commands\RemoveAzureApiManagementSubscription.cs" />
<Compile Include="Commands\RemoveAzureApiManagementUser.cs" />
<Compile Include="Commands\RemoveAzureApiManagementUserFromGroup.cs" />
<Compile Include="Commands\SaveAzureApiManagementTenantConfiguration.cs" />
<Compile Include="Commands\SetAzureApiManagementApi.cs" />
<Compile Include="Commands\SetAzureApiManagementAuthorizationServer.cs" />
<Compile Include="Commands\SetAzureApiManagementCertificate.cs" />
<Compile Include="Commands\SetAzureApiManagementGroup.cs" />
<Compile Include="Commands\SetAzureApiManagementLogger.cs" />
<Compile Include="Commands\SetAzureApiManagementOpenIdConnectProvider.cs" />
<Compile Include="Commands\SetAzureApiManagementOperation.cs" />
<Compile Include="Commands\SetAzureApiManagementPolicy.cs" />
<Compile Include="Commands\SetAzureApiManagementProduct.cs" />
<Compile Include="Commands\SetAzureApiManagementProperty.cs" />
<Compile Include="Commands\SetAzureApiManagementSubscription.cs" />
<Compile Include="Commands\SetAzureApiManagementUser.cs" />
<Compile Include="CommonConstants.cs" />
<Compile Include="Commands\SetAzureRmApiManagementTenantGitAccess.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Models\ErrorBody.cs" />
<Compile Include="Models\ErrorField.cs" />
<Compile Include="Models\PsApiManagementOperationResult.cs" />
<Compile Include="Models\PsApiManagementTenantConfigurationSyncState.cs" />
<Compile Include="Models\TenantConfigurationState.cs" />
<Compile Include="Models\PsApiManagementAccessInformation.cs" />
<Compile Include="Models\PsApiManagementAccessTokenSendingMethod.cs" />
<Compile Include="Models\PsApiManagementApi.cs" />
<Compile Include="Models\PsApiManagementApiFormat.cs" />
<Compile Include="Models\PsApiManagementAuthorizationRequestMethod.cs" />
<Compile Include="Models\PsApiManagementClientAuthenticationMethod.cs" />
<Compile Include="Models\PsApiManagementLogger.cs" />
<Compile Include="Models\PsApiManagementLoggerType.cs" />
<Compile Include="Models\PsApiManagementOpenIdConnectProvider.cs" />
<Compile Include="Models\PsApiManagementProperty.cs" />
<Compile Include="Models\PsApiManagementResponse.cs" />
<Compile Include="Models\PsApiManagementCertificate.cs" />
<Compile Include="Models\PsApiManagementContext.cs" />
Expand All @@ -209,8 +236,10 @@
<Compile Include="Models\PsApiManagementSchema.cs" />
<Compile Include="Models\PsApiManagementSubscription.cs" />
<Compile Include="Models\PsApiManagementSubscriptionState.cs" />
<Compile Include="Models\PsApiManagementTenantConfiguration.cs" />
<Compile Include="Models\PsApiManagementUser.cs" />
<Compile Include="Models\PsApiManagementUserState.cs" />
<Compile Include="Models\TenantConfigurationLongRunningOperation.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
Expand All @@ -222,6 +251,7 @@
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// // Copyright (c) Microsoft. All rights reserved.// // Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0// // Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands{ using System; using System.Management.Automation; using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models; [Cmdlet(VerbsCommon.Add, "AzureRmApiManagementApiToProduct")] [OutputType(typeof(bool))] public class AddAzureApiManagementApiToProduct : AzureApiManagementCmdletBase { [Parameter( ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Instance of PsApiManagementContext. This parameter is required.")] [ValidateNotNullOrEmpty] public PsApiManagementContext Context { get; set; } [Parameter( ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Identifier of existing Product to add API to. This parameter is required.")] [ValidateNotNullOrEmpty] public String ProductId { get; set; } [Parameter( ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Identifier of existing APIs to be added to the product. This parameter is required.")] [ValidateNotNullOrEmpty] public String ApiId { get; set; } [Parameter( ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "If specified will write true in case operation succeeds. This parameter is optional. Default value is false.")] public SwitchParameter PassThru { get; set; } public override void ExecuteApiManagementCmdlet() { Client.ApiAddToProduct(Context, ProductId, ApiId); if (PassThru) { WriteObject(true); } } }}
// // Copyright (c) Microsoft. All rights reserved.// // Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0// // Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands{ using System; using System.Management.Automation; using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models; [Cmdlet(VerbsCommon.Add, Constants.ApiManagementApiToProduct)] [OutputType(typeof(bool))] public class AddAzureApiManagementApiToProduct : AzureApiManagementCmdletBase { [Parameter( ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Instance of PsApiManagementContext. This parameter is required.")] [ValidateNotNullOrEmpty] public PsApiManagementContext Context { get; set; } [Parameter( ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Identifier of existing Product to add API to. This parameter is required.")] [ValidateNotNullOrEmpty] public String ProductId { get; set; } [Parameter( ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Identifier of existing APIs to be added to the product. This parameter is required.")] [ValidateNotNullOrEmpty] public String ApiId { get; set; } [Parameter( ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "If specified will write true in case operation succeeds. This parameter is optional. Default value is false.")] public SwitchParameter PassThru { get; set; } public override void ExecuteApiManagementCmdlet() { Client.ApiAddToProduct(Context, ProductId, ApiId); if (PassThru) { WriteObject(true); } } }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
using System.Management.Automation;
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models;

[Cmdlet(VerbsCommon.Add, "AzureRmApiManagementProductToGroup")]
[Cmdlet(VerbsCommon.Add, Constants.ApiManagementProductToGroup)]
[OutputType(typeof(bool))]
public class AddAzureApiManagementProductToGroup : AzureApiManagementCmdletBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
using System.Management.Automation;
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models;

[Cmdlet(VerbsCommon.Add, "AzureRmApiManagementUserToGroup")]
[Cmdlet(VerbsCommon.Add, Constants.ApiManagementUserToGroup)]
[OutputType(typeof(bool))]
public class AddAzureApiManagementUserToGroup : AzureApiManagementCmdletBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
// limitations under the License.
//


namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
{
using System;
using System.Management.Automation;
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement;
using ResourceManager.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models;
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Properties;

abstract public class AzureApiManagementCmdletBase : AzureRMCmdlet
{
protected static TimeSpan LongRunningOperationDefaultTimeout = TimeSpan.FromMinutes(1);
protected static TimeSpan LongRunningOperationDefaultTimeout = TimeSpan.FromSeconds(30);

private ApiManagementClient _client;

Expand Down Expand Up @@ -65,5 +68,75 @@ protected virtual void HandleException(Exception ex)
{
WriteExceptionError(ex);
}

protected void WriteProgress(TenantConfigurationLongRunningOperation operation)
{
WriteProgress(new ProgressRecord(0, operation.OperationName, operation.Status.ToString()));
}

/// <summary>
/// TODO: Revert to standard long running operation once /operationResults endpoint start returning
/// 202 Code for not Completed Operation.
/// </summary>
/// <see cref="https://msdn.microsoft.com/en-us/library/azure/dn781420.aspx#GetOperation"/>
protected TenantConfigurationLongRunningOperation WaitForOperationToComplete(TenantConfigurationLongRunningOperation longRunningOperation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHy is this not using the standard long running operation code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug and it will take 2 weeks to go out, found out during powershell testing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a link to the bug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a service side Code bug, I will add a TODO to revert to standard long running operation code

{
do
{
var retryAfter = longRunningOperation.RetryAfter == null || longRunningOperation.RetryAfter.Value < LongRunningOperationDefaultTimeout ?
LongRunningOperationDefaultTimeout : longRunningOperation.RetryAfter.Value;

WriteProgress(longRunningOperation);

TestMockSupport.Delay(retryAfter);

// the operation link is present in the first call to Operation.
// The next calls to /operationResults do not return Location header, hence preserving this value across calls
// this is the service side bug.
var operationStatusLink = longRunningOperation.OperationLink;

longRunningOperation = Client.GetLongRunningOperationStatus(longRunningOperation);
longRunningOperation.OperationLink = operationStatusLink;

WriteVerboseWithTimestamp(Resources.VerboseGetOperationStateTimeoutMessage,
longRunningOperation.OperationResult.State);
} while (longRunningOperation.OperationResult.State == TenantConfigurationState.InProgress);

return longRunningOperation;
}

protected void ExecuteTenantConfigurationLongRunningCmdletWrap(
Func<TenantConfigurationLongRunningOperation> func,
bool passThru = false,
object passThruValue = null)
{
try
{
var longRunningOperation = func();

longRunningOperation = WaitForOperationToComplete(longRunningOperation);
if (longRunningOperation.OperationResult.State != TenantConfigurationState.Succeeded)
{
var errorMessage = longRunningOperation.OperationResult.Error != null ?
longRunningOperation.OperationResult.Error.Message
: longRunningOperation.OperationName;

WriteErrorWithTimestamp(errorMessage);
WriteObject(passThruValue ?? longRunningOperation.OperationResult);
}
else if (passThru)
{
WriteObject(passThruValue ?? longRunningOperation.OperationResult);
}
}
catch (ArgumentException ex)
{
WriteError(new ErrorRecord(ex, string.Empty, ErrorCategory.InvalidArgument, null));
}
catch (Exception ex)
{
WriteExceptionError(ex);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models;
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Properties;

[Cmdlet(VerbsData.Export, "AzureRmApiManagementApi", DefaultParameterSetName = ExportContentToPipeline)]
[Cmdlet(VerbsData.Export, Constants.ApiManagementApi, DefaultParameterSetName = ExportContentToPipeline)]
[OutputType(typeof(string))]
public class ExportAzureApiManagementApi : AzureApiManagementCmdletBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
using System.Management.Automation;
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models;

[Cmdlet(VerbsCommon.Get, "AzureRmApiManagementApi", DefaultParameterSetName = AllApis)]
[OutputType(typeof(IList<PsApiManagementApi>))]
[Cmdlet(VerbsCommon.Get, Constants.ApiManagementApi, DefaultParameterSetName = AllApis)]
[OutputType(typeof(IList<PsApiManagementApi>), ParameterSetName = new [] { AllApis, FindByName, FindByProductId })]
[OutputType(typeof(PsApiManagementApi), ParameterSetName = new[] { FindById })]
public class GetAzureApiManagementApi : AzureApiManagementCmdletBase
{
private const string FindByProductId = "Find by product ID";
Expand Down
Loading