Skip to content

Commit e321aab

Browse files
Fix Tenant bug for Graph Client
1 parent 19a60bb commit e321aab

9 files changed

+48
-17
lines changed

src/StorageSync/StorageSync.Test/Common/MockStorageSyncResourceManager.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
using Commands.StorageSync.Interop.Interfaces;
1818
using Microsoft.Azure.Commands.StorageSync.Common;
1919
using Microsoft.Azure.Commands.StorageSync.Interfaces;
20+
using Microsoft.Azure.Test.HttpRecorder;
21+
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
2022
using System;
2123
using System.Text.RegularExpressions;
2224

@@ -59,13 +61,14 @@ protected bool IsPlaybackMode
5961
{
6062
if (Microsoft.Azure.Test.HttpRecorder.HttpMockServer.Mode == Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode.Playback)
6163
{
62-
isPlaybackMode =true;
64+
isPlaybackMode = true;
6365
}
6466
else if (Microsoft.Azure.Test.HttpRecorder.HttpMockServer.Mode == Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode.Record)
6567
{
6668
isPlaybackMode = false;
6769

68-
} else
70+
}
71+
else
6972
{
7073
throw new NotSupportedException($"{Microsoft.Azure.Test.HttpRecorder.HttpMockServer.Mode} Mode is not supported");
7174
}
@@ -140,5 +143,19 @@ public void WaitForAccessPropogation()
140143
System.Threading.Thread.Sleep(40 * 1000);
141144
}
142145
}
146+
147+
public string GetTenantId()
148+
{
149+
string tenantId = null;
150+
151+
if (IsPlaybackMode)
152+
{
153+
if (HttpMockServer.Variables.ContainsKey(StorageSyncConstants.TenantId))
154+
{
155+
tenantId = HttpMockServer.GetVariable(StorageSyncConstants.TenantId, null);
156+
}
157+
}
158+
return tenantId;
159+
}
143160
}
144161
}

src/StorageSync/StorageSync.Test/TestController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class TestController : RMTestBase
4646
/// <summary>
4747
/// The tenant identifier key
4848
/// </summary>
49-
private const string TenantIdKey = "TenantId";
49+
private const string TenantIdKey = StorageSyncConstants.TenantId;
5050
/// <summary>
5151
/// The domain key
5252
/// </summary>

src/StorageSync/StorageSync/Common/StorageSyncClientCmdletBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public StorageSyncClientCmdletBase()
7474
/// </summary>
7575
protected virtual void InitializeComponent()
7676
{
77+
DefaultProfile.DefaultContext.Tenant.Id = StorageSyncClientWrapper.StorageSyncResourceManager.GetTenantId() ?? DefaultProfile.DefaultContext.Tenant.Id;
7778
}
7879

7980
/// <summary>

src/StorageSync/StorageSync/Common/StorageSyncClientWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public class StorageSyncClientWrapper : IStorageSyncClientWrapper
5656
public IStorageSyncManagementClient StorageSyncManagementClient { get; set; }
5757

5858
/// <summary>
59-
/// Gets or sets the storage synchronize resource manager.
59+
/// Gets or sets the storage sync resource manager.
6060
/// </summary>
61-
/// <value>The storage synchronize resource manager.</value>
61+
/// <value>The storage sync resource manager.</value>
6262
public IStorageSyncResourceManager StorageSyncResourceManager { get; set; }
6363

6464
/// <summary>

src/StorageSync/StorageSync/Common/StorageSyncConstants.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,18 @@ public class StorageSyncConstants
124124
public const string FileSyncSvcName = "FileSyncSvc";
125125

126126
/// <summary>
127-
/// The storage synchronize resource manager
127+
/// The storage sync resource manager
128128
/// </summary>
129129
public const string StorageSyncResourceManager = "StorageSyncResourceManager";
130130

131131
/// <summary>
132-
/// The synchronize server identifier
132+
/// The sync server identifier
133133
/// </summary>
134134
public const string SyncServerId = "SyncServerId";
135+
136+
/// <summary>
137+
/// The tenant identifier
138+
/// </summary>
139+
public const string TenantId = "TenantId";
135140
}
136141
}

src/StorageSync/StorageSync/Common/StorageSyncResourceManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,7 @@ public void WaitForAccessPropogation()
101101
{
102102
System.Threading.Thread.Sleep(40 * 1000);
103103
}
104+
105+
public string GetTenantId() => null;
104106
}
105107
}

src/StorageSync/StorageSync/Interfaces/IStorageSyncClientWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public interface IStorageSyncClientWrapper
3838
IStorageSyncManagementClient StorageSyncManagementClient { get; set; }
3939

4040
/// <summary>
41-
/// Gets or sets the storage synchronize resource manager.
41+
/// Gets or sets the storage sync resource manager.
4242
/// </summary>
43-
/// <value>The storage synchronize resource manager.</value>
43+
/// <value>The storage sync resource manager.</value>
4444
IStorageSyncResourceManager StorageSyncResourceManager { get; set; }
4545

4646
/// <summary>

src/StorageSync/StorageSync/Interfaces/IStorageSyncResourceManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,11 @@ public interface IStorageSyncResourceManager
6565
/// Waits for access propogation.
6666
/// </summary>
6767
void WaitForAccessPropogation();
68+
69+
/// <summary>
70+
/// Gets the tenant identifier.
71+
/// </summary>
72+
/// <returns>System.String.</returns>
73+
string GetTenantId();
6874
}
6975
}

src/StorageSync/StorageSync/Properties/StorageSyncResources.Designer.cs

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)