Skip to content

Commit 09a71d5

Browse files
committed
Merge pull request #53 from MabOneSdk/pragrawa
Pragrawa
2 parents c97c5c3 + eabf082 commit 09a71d5

File tree

52 files changed

+2106
-912
lines changed

Some content is hidden

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

52 files changed

+2106
-912
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
7+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
8+
</dependentAssembly>
9+
</assemblyBinding>
10+
</runtime>
11+
</configuration>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 System;
16+
using System.Management.Automation;
17+
using System.Collections.Generic;
18+
using System.Xml;
19+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
20+
using Microsoft.Azure.Common.Authentication;
21+
using Microsoft.Azure.Common.Authentication.Models;
22+
using System.Threading;
23+
using Hyak.Common;
24+
using Microsoft.Azure.Commands.AzureBackup.Properties;
25+
using System.Net;
26+
using Microsoft.WindowsAzure.Management.Scheduler;
27+
using Microsoft.Azure.Management.BackupServices;
28+
using Microsoft.Azure.Management.BackupServices.Models;
29+
30+
namespace Microsoft.Azure.Commands.AzureBackup.ClientAdapter
31+
{
32+
public partial class AzureBackupClientAdapter
33+
{
34+
/// <summary>
35+
/// Cloud credentials for client calls
36+
/// </summary>
37+
private SubscriptionCloudCredentials cloudCreds { get; set; }
38+
39+
/// <summary>
40+
/// Base URI for client calls
41+
/// </summary>
42+
private Uri baseURI { get; set; }
43+
44+
/// <summary>
45+
/// ResourceGroup context for the operation
46+
/// </summary>
47+
private string resourceGroupName { get; set; }
48+
49+
/// <summary>
50+
/// Resource context for the operation
51+
/// </summary>
52+
private string resourceName { get; set; }
53+
54+
/// <summary>
55+
/// Client request id.
56+
/// </summary>
57+
private string clientRequestId;
58+
59+
/// <summary>
60+
/// Azure backup client.
61+
/// </summary>
62+
private BackupServicesManagementClient azureBackupClient;
63+
64+
/// <summary>
65+
/// Cancellation Token Source
66+
/// </summary>
67+
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
68+
private CancellationToken CmdletCancellationToken;
69+
70+
/// <summary>
71+
/// Get Azure backup client.
72+
/// </summary>
73+
private BackupServicesManagementClient AzureBackupClient
74+
{
75+
get
76+
{
77+
if (this.azureBackupClient == null)
78+
{
79+
this.azureBackupClient = AzureSession.ClientFactory.CreateCustomClient<BackupServicesManagementClient>(resourceName, resourceGroupName, cloudCreds, baseURI);
80+
}
81+
82+
return this.azureBackupClient;
83+
}
84+
}
85+
86+
public AzureBackupClientAdapter(SubscriptionCloudCredentials creds, Uri baseUri, string rgName, string rName)
87+
{
88+
cloudCreds = creds;
89+
baseURI = baseUri;
90+
resourceGroupName = rgName;
91+
resourceName = rName;
92+
93+
RefreshClientRequestId();
94+
95+
// Temp code to be able to test internal env.
96+
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
97+
}
98+
99+
public void RefreshClientRequestId()
100+
{
101+
clientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-PS";
102+
}
103+
104+
public string GetClientRequestId()
105+
{
106+
return clientRequestId;
107+
}
108+
109+
internal CustomRequestHeaders GetCustomRequestHeaders()
110+
{
111+
var hdrs = new CustomRequestHeaders()
112+
{
113+
// ClientRequestId is a unique ID for every request to backend service.
114+
ClientRequestId = this.clientRequestId,
115+
};
116+
117+
return hdrs;
118+
}
119+
}
120+
}
121+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 System;
16+
using System.Management.Automation;
17+
using System.Collections.Generic;
18+
using System.Xml;
19+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
20+
using Microsoft.Azure.Common.Authentication;
21+
using Microsoft.Azure.Common.Authentication.Models;
22+
using System.Threading;
23+
using Hyak.Common;
24+
using Microsoft.Azure.Commands.AzureBackup.Properties;
25+
using System.Net;
26+
using System.Linq;
27+
using Microsoft.WindowsAzure.Management.Scheduler;
28+
using Microsoft.Azure.Management.BackupServices;
29+
using Microsoft.Azure.Management.BackupServices.Models;
30+
31+
namespace Microsoft.Azure.Commands.AzureBackup.ClientAdapter
32+
{
33+
public partial class AzureBackupClientAdapter
34+
{
35+
/// <summary>
36+
/// Gets all containers in the vault
37+
/// </summary>
38+
/// <param name="filter"></param>
39+
/// <returns></returns>
40+
public IEnumerable<ContainerInfo> ListContainers(string filter)
41+
{
42+
var listResponse = AzureBackupClient.Container.ListAsync(filter, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
43+
return listResponse.Objects;
44+
}
45+
46+
/// <summary>
47+
/// Register container
48+
/// </summary>
49+
/// <param name="request"></param>
50+
/// <returns></returns>
51+
public Guid RegisterContainer(RegisterContainerRequestInput request)
52+
{
53+
var response = AzureBackupClient.Container.RegisterAsync(request, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
54+
return response.OperationId;
55+
}
56+
57+
/// <summary>
58+
/// UnRegister container
59+
/// </summary>
60+
/// <param name="request"></param>
61+
/// <returns></returns>
62+
public Guid UnRegisterContainer(UnregisterContainerRequestInput request)
63+
{
64+
var response = AzureBackupClient.Container.UnregisterAsync(request, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
65+
return response.OperationId;
66+
}
67+
68+
/// <summary>
69+
/// Refresh container list in service
70+
/// </summary>
71+
/// <returns></returns>
72+
public Guid RefreshContainers()
73+
{
74+
var response = AzureBackupClient.Container.RefreshAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result;
75+
return response.OperationId;
76+
}
77+
}
78+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 System;
16+
using System.Management.Automation;
17+
using System.Collections.Generic;
18+
using System.Xml;
19+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
20+
using Microsoft.Azure.Common.Authentication;
21+
using Microsoft.Azure.Common.Authentication.Models;
22+
using System.Threading;
23+
using Hyak.Common;
24+
using Microsoft.Azure.Commands.AzureBackup.Properties;
25+
using System.Net;
26+
using Microsoft.WindowsAzure.Management.Scheduler;
27+
using Microsoft.Azure.Management.BackupServices;
28+
using Microsoft.Azure.Management.BackupServices.Models;
29+
30+
namespace Microsoft.Azure.Commands.AzureBackup.ClientAdapter
31+
{
32+
public partial class AzureBackupClientAdapter
33+
{
34+
/// <summary>
35+
/// Lists datasources in the vault
36+
/// </summary>
37+
/// <param name="query"></param>
38+
/// <returns></returns>
39+
public IEnumerable<DataSourceInfo> ListDataSources(DataSourceQueryParameter query)
40+
{
41+
var response = AzureBackupClient.DataSource.ListAsync(query, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
42+
return (response != null) ? response.DataSources.Objects : null;
43+
}
44+
45+
/// <summary>
46+
/// Lists protectable objects in the vault
47+
/// </summary>
48+
/// <param name="query"></param>
49+
/// <returns></returns>
50+
public IEnumerable<ProtectableObjectInfo> ListProtectableObjects(POQueryParameter query)
51+
{
52+
var response = AzureBackupClient.ProtectableObject.ListAsync(query, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
53+
return (response != null) ? response.ProtectableObject.Objects : null;
54+
}
55+
56+
/// <summary>
57+
/// Dsiable protection
58+
/// </summary>
59+
/// <param name="containerName"></param>
60+
/// <param name="dsType"></param>
61+
/// <param name="dsId"></param>
62+
/// <param name="request"></param>
63+
/// <returns></returns>
64+
public Guid DisableProtection(string containerName, string dsType, string dsId, RemoveProtectionRequestInput request)
65+
{
66+
var response = AzureBackupClient.DataSource.DisableProtectionAsync(GetCustomRequestHeaders(), containerName, dsType, dsId, request, CmdletCancellationToken).Result;
67+
return response.OperationId;
68+
}
69+
70+
/// <summary>
71+
/// Enable Protection
72+
/// </summary>
73+
/// <param name="request"></param>
74+
/// <returns></returns>
75+
public Guid EnableProtection(SetProtectionRequestInput request)
76+
{
77+
var response = AzureBackupClient.DataSource.EnableProtectionAsync(GetCustomRequestHeaders(), request, CmdletCancellationToken).Result;
78+
return response.OperationId;
79+
}
80+
81+
/// <summary>
82+
/// Trigger backup on a DS
83+
/// </summary>
84+
/// <param name="containerName"></param>
85+
/// <param name="dsType"></param>
86+
/// <param name="dsId"></param>
87+
/// <returns></returns>
88+
public Guid TriggerBackup(string containerName, string dsType, string dsId)
89+
{
90+
var response = AzureBackupClient.BackUp.TriggerBackUpAsync(GetCustomRequestHeaders(), containerName, dsType, dsId, CmdletCancellationToken).Result;
91+
return response.OperationId;
92+
}
93+
94+
/// <summary>
95+
/// Lists recovery points for specified item
96+
/// </summary>
97+
/// <param name="containerName"></param>
98+
/// <param name="dsType"></param>
99+
/// <param name="dsId"></param>
100+
/// <returns></returns>
101+
public IEnumerable<RecoveryPointInfo> ListRecoveryPoints(string containerName, string dsType, string dsId)
102+
{
103+
var response = AzureBackupClient.RecoveryPoint.ListAsync(GetCustomRequestHeaders(), containerName, dsType, dsId, CmdletCancellationToken).Result;
104+
return (response != null) ? response.RecoveryPoints.Objects : null;
105+
}
106+
}
107+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 System;
16+
using System.Management.Automation;
17+
using System.Collections.Generic;
18+
using System.Xml;
19+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
20+
using Microsoft.Azure.Common.Authentication;
21+
using Microsoft.Azure.Common.Authentication.Models;
22+
using System.Threading;
23+
using Hyak.Common;
24+
using Microsoft.Azure.Commands.AzureBackup.Properties;
25+
using System.Net;
26+
using Microsoft.WindowsAzure.Management.Scheduler;
27+
using Microsoft.Azure.Management.BackupServices;
28+
using Microsoft.Azure.Management.BackupServices.Models;
29+
using Mgmt = Microsoft.Azure.Management.BackupServices.Models;
30+
31+
namespace Microsoft.Azure.Commands.AzureBackup.ClientAdapter
32+
{
33+
public partial class AzureBackupClientAdapter
34+
{
35+
public IEnumerable<Mgmt.Job> ListJobs(JobQueryParameter queryParams)
36+
{
37+
var response = AzureBackupClient.Job.ListAsync(queryParams, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
38+
return response.Jobs.Objects;
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)