Skip to content

Commit 02c496c

Browse files
authored
Merge pull request #2 from Azure/master
Sync
2 parents 07c1914 + 751c9bb commit 02c496c

File tree

394 files changed

+2516934
-49964
lines changed

Some content is hidden

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

394 files changed

+2516934
-49964
lines changed

ChangeLog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 1.2.1 - January 2019
2+
#### Az.Accounts
3+
* Release with correct version of Authentication
4+
5+
#### Az.AnalysisServices
6+
* Release with updated Authentication dependency
7+
8+
#### Az.RecoveryServices
9+
* Release with updated Authentication dependency
10+
111
## 1.2.0 - January 2019
212
#### Az.Accounts
313
* Add interactive and username/password authentication for Windows PowerShell 5.1 only

documentation/development-docs/generate-format.ps1xml-file.md

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,18 @@ namespace Microsoft.Azure.Commands.Profile.Models
180180

181181
// code omitted for brevity
182182
183-
[Ps1Xml(Label = "Subscription Id", Target = ViewControl.Table)]
183+
[Ps1Xml(Label = "SubscriptionId", Target = ViewControl.Table)]
184184
public string Id { get; set; }
185185

186-
[Ps1Xml(Label = "Subscription Name", Target = ViewControl.Table)]
186+
[Ps1Xml(Label = "Name", Target = ViewControl.Table)]
187187
public string Name { get; set; }
188188

189189
[Ps1Xml(Label = "State", Target = ViewControl.Table)]
190190
public string State { get; set; }
191191

192192
public string SubscriptionId { get { return Id; } }
193193

194-
[Ps1Xml(Label = "Tenant Id", Target = ViewControl.Table)]
194+
[Ps1Xml(Label = "TenantId", Target = ViewControl.Table)]
195195
public string TenantId
196196
{
197197
get
@@ -260,8 +260,8 @@ To specify what goes into the table view - use the **ScriptBlock** attribute pro
260260
{
261261
// code omitted for brevity
262262
263-
[Ps1Xml(Label = "Account Id", Target = ViewControl.Table, ScriptBlock = "$_.Account.Id")]
264-
[Ps1Xml(Label = "Account Type", Target = ViewControl.Table, ScriptBlock = "$_.Account.Type")]
263+
[Ps1Xml(Label = "Account.Id", Target = ViewControl.Table, ScriptBlock = "$_.Account.Id")]
264+
[Ps1Xml(Label = "Account.Type", Target = ViewControl.Table, ScriptBlock = "$_.Account.Type")]
265265
public IAzureAccount Account { get; set; }
266266

267267
// code omitted for brevity
@@ -272,8 +272,8 @@ Note: **$_** symbol in PowerShell means the same as **this** key word means in C
272272

273273
These two attribute will result in 2 column in the table view:
274274
```Ps
275-
Account Id Account Type
276-
========== ============
275+
Account.Id Account.Type
276+
========== ============
277277
```
278278
## GroupBy a property.
279279

@@ -284,7 +284,7 @@ public class PSAzureSubscription : IAzureSubscription
284284

285285
// code omitted for brevity
286286
287-
[Ps1Xml(Label = "Subscription Id", Target = ViewControl.Table, GroupByThis = true)]
287+
[Ps1Xml(Label = "SubscriptionId", Target = ViewControl.Table, GroupByThis = true)]
288288
public string Id { get; set; }
289289

290290
// code omitted for brevity
@@ -298,7 +298,7 @@ public class PSAzureSubscription : IAzureSubscription
298298

299299
// code omitted for brevity
300300
301-
[Ps1Xml(Label = "Subscription Name", Target = ViewControl.Table, Position = 0)]
301+
[Ps1Xml(Label = "Name", Target = ViewControl.Table, Position = 0)]
302302
public string Name { get; set; }
303303

304304
// code omitted for brevity
@@ -309,53 +309,70 @@ This will place the column at the very beginning of the table.
309309

310310
# How to generate format.ps1xml file.
311311

312-
1. First of all you need to [build](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/azure-powershell-developer-guide.md#building-the-environment) PowerShell Azure:
313-
314-
```Powershell
315-
PS E:\git\azure-powershell> msbuild build.proj /p:SkipHelp=true
316-
```
317-
318-
* After the build is completed you can find build artifacts in the ```.\artifacts\Debug``` folder:
319-
320-
```Powershell
321-
PS E:\git\azure-powershell> ls .\artifacts\Debug\
312+
## Let's consider how to generate a format.ps1xml file for the Az.Storage and Az.Account modules.
313+
1. Start PowerShell 6
314+
2. Build and import the FormatPs1XmlGenerator module.
315+
* Go to the generator directory
316+
```Powershell
317+
PS C:\Users\you> cd E:\git\azure-powershell\tools\FormatPs1XmlGenerator\
318+
```
319+
* Build the generator solution
320+
```Powershell
321+
PS E:\git\azure-powershell\tools\FormatPs1XmlGenerator> dotnet build
322+
```
323+
* Import the generator module
324+
```Powershell
325+
PS E:\git\azure-powershell\tools\FormatPs1XmlGenerator> Import-Module .\FormatPs1XmlGenerator\bin\Debug\FormatPs1XmlGenerator.psd1
326+
```
327+
328+
3. Build the Az.Storage module.
329+
* Go to the Storage directory
330+
```Powershell
331+
PS C:\Users\you>cd E:\git\azure-powershell\src\Storage
332+
```
333+
* Build the module
334+
```Powershell
335+
PS E:\git\azure-powershell\src\Storage>dotnet build
336+
```
337+
* Go to the repository root folder
338+
```Powershell
339+
PS E:\git\azure-powershell\src\Storage>cd E:\git\azure-powershell\
340+
```
341+
* Check the artifacts folder - all built modules should be there. Since Az.Storage depends on the Az.Accounts module both Az.Accounts and Az.Storage modules should be there:
342+
```Powershell
343+
PS E:\git\azure-powershell> ls .\artifacts\Debug\
322344

323345

324346
Directory: E:\git\azure-powershell\artifacts\Debug
325347

326348

327-
Mode LastWriteTime Length Name
328-
---- ------------- ------ ----
329-
d----- 4/25/2018 4:37 PM ResourceManager
330-
d----- 4/25/2018 4:35 PM ServiceManagement
331-
d----- 4/25/2018 4:35 PM Storage
332-
-a---- 4/25/2018 4:31 PM 11384 Az.psd1
333-
-a---- 4/25/2018 4:50 PM 8708 Az.psm1
334-
335-
```
336-
337-
2. Import the **RepoTask cmdlets**:
338-
339-
```PowerShell
340-
PS E:\git\azure-powershell> Import-Module E:\git\azure-powershell\tools\RepoTasks\RepoTasks.Cmdlets\bin\Debug\RepoTasks.Cmdlets.dll
341-
```
342-
3. Run the **New-FormatPs1Xml** cmdlet.
343-
* The cmdlet has one required argument **-ModulePath** - a path to a module manifest (psd1) file. Since in our example we are using the Get-AzSubscription cmdlet from the Az.Accounts module we need to specify path to the Az.Accounts module manifest which is
344-
```
345-
E:\git\azure-powershell\artifacts\Debug\Az.Accounts\Az.Accounts.psd1
346-
```
347-
* Also with the cmdlet we need to use **-OnlyMarkedProperties** switch.
348-
* You may also want to specify an output path for the generated file with the **-OutputPath** argument. If not specified this is current folder.
349-
350-
```
351-
PS E:\git\azure-powershell> New-FormatPs1Xml -ModulePath .\artifacts\Debug\Az.Accounts\Az.Accounts.psd1 -OnlyMarkedProperties
352-
353-
E:\git\azure-powershell\Microsoft.Azure.Commands.Profile.generated.format.ps1xml
354-
```
355-
* After a successful run the cmdlet outputs the full path to the generated format.ps1xml file.
349+
Mode LastWriteTime Length Name
350+
---- ------------- ------ ----
351+
d----- 1/29/2019 2:18 PM Az.Accounts
352+
d----- 1/29/2019 2:18 PM Az.Storage
353+
```
354+
4. Run the **New-FormatPs1Xml** cmdlet.
355+
* The cmdlet has one required parameter **-ModulePath** - a path to a module manifest (psd1) file.
356+
* Also with the cmdlet we need to use **-OnlyMarkedProperties** switch.
357+
* You may also want to specify an output path for the generated file with the **-OutputPath** argument. If not specified this is current folder.
358+
* After a successful run the cmdlet outputs the full path to the generated format.ps1xml file.
359+
360+
* Below is an example of how to generate a format.ps1xml file for the ```Az.Storage``` module:
361+
```Powershell
362+
PS E:\git\azure-powershell> New-FormatPs1Xml -OnlyMarkedProperties -ModulePath .\artifacts\Debug\Az.Storage\Az.Storage.psd1
363+
E:\git\azure-powershell\Microsoft.Azure.PowerShell.Cmdlets.Storage.Management.generated.format.ps1xml
364+
E:\git\azure-powershell\Microsoft.Azure.PowerShell.Cmdlets.Storage.generated.format.ps1xml
365+
```
366+
* Below is an example of how to generate a format.ps1xml file for the ```Az.Account``` module:
367+
```powershell
368+
PS E:\git\azure-powershell> New-FormatPs1Xml -OnlyMarkedProperties -ModulePath .\artifacts\Debug\Az.Accounts\Az.Accounts.psd1
369+
E:\git\azure-powershell\Microsoft.Azure.PowerShell.Cmdlets.Accounts.generated.format.ps1xml
370+
PS E:\git\azure-powershell>
371+
```
356372

357373
# How to test the format.ps1xml file.
358374

375+
## Let's take a look at how to check the newly created format.ps1xml file for the ```Az.Account``` module.
359376
**Note:** All the paths used in the example in the section are under **_azure-powershell/artifacts/Debug_**
360377

361378
1. **Copy** the generated format.ps1xml file to the built module folder (this is where your module manifest file psd1 is located). In our example the module folder is
@@ -396,7 +413,7 @@ PS C:\> Import-Module E:\git\azure-powershell\artifacts\Debug\Az.Accounts\Az.Acc
396413
```Powershell
397414
PS C:\> Get-AzSubscription
398415

399-
Subscription Id Subscription Name State Tenant Id
416+
SubscriptionId Name State TenantId
400417
--------------- ----------------- ----- ---------
401418
c9cbd920-c00c-427c-852b-c329e824c3a8 Azure SDK Powershell Test Enabled 72f988bf-86f1-41af-91ab-7a64d1d63df5
402419
6b085460-5f21-477e-ba44-4cd9fbd030ef Azure SDK Infrastructure Enabled 72f988bf-86f1-41af-91ab-7a64d1d63df5

src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,24 @@ public override void ExecuteCmdlet()
229229
Path = "/oauth2/token"
230230
};
231231

232+
var envSecret = System.Environment.GetEnvironmentVariable(MSISecretVariable);
233+
232234
var msiSecret = this.IsBound(nameof(ManagedServiceSecret))
233235
? ManagedServiceSecret.ConvertToString()
234-
: System.Environment.GetEnvironmentVariable(MSISecretVariable);
236+
: envSecret;
237+
238+
var envUri = System.Environment.GetEnvironmentVariable(MSIEndpointVariable);
235239

236240
var suppliedUri = this.IsBound(nameof(ManagedServiceHostName))
237241
? builder.Uri.ToString()
238-
: System.Environment.GetEnvironmentVariable(MSIEndpointVariable);
242+
: envUri;
243+
244+
if (!this.IsBound(nameof(ManagedServiceHostName)) && !string.IsNullOrWhiteSpace(envUri)
245+
&& !this.IsBound(nameof(ManagedServiceSecret)) && !string.IsNullOrWhiteSpace(envSecret))
246+
{
247+
// set flag indicating this is AppService Managed Identity ad hoc mode
248+
azureAccount.SetProperty(AuthenticationFactory.AppServiceManagedIdentityFlag, "the value not used");
249+
}
239250

240251
if (!string.IsNullOrWhiteSpace(msiSecret))
241252
{

src/Accounts/Accounts/Az.Accounts.psd1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# RootModule = ''
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.2.0'
15+
ModuleVersion = '1.2.1'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core', 'Desktop'
@@ -141,9 +141,7 @@ PrivateData = @{
141141
# IconUri = ''
142142

143143
# ReleaseNotes of this module
144-
ReleaseNotes = '* Add interactive and username/password authentication for Windows PowerShell 5.1 only
145-
* Update incorrect online help URLs
146-
* Add warning message in PS Core for Uninstall-AzureRm'
144+
ReleaseNotes = '* Release with correct version of Authentication'
147145

148146
# Prerelease string of this module
149147
# Prerelease = ''

src/Accounts/Accounts/AzureRmAlias/Mappings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,7 @@
16941694
"New-AzOperationalInsightsWindowsPerformanceCounterDataSource": "New-AzureRmOperationalInsightsWindowsPerformanceCounterDataSource",
16951695
"New-AzOperationalInsightsLinuxPerformanceObjectDataSource": "New-AzureRmOperationalInsightsLinuxPerformanceObjectDataSource",
16961696
"New-AzOperationalInsightsLinuxSyslogDataSource": "New-AzureRmOperationalInsightsLinuxSyslogDataSource",
1697+
"New-AzOperationalInsightsApplicationInsightsDataSource": "New-AzureRmOperationalInsightsApplicationInsightsDataSource",
16971698
"Disable-AzOperationalInsightsLinuxSyslogCollection": "Disable-AzureRmOperationalInsightsLinuxSyslogCollection",
16981699
"New-AzOperationalInsightsWindowsEventDataSource": "New-AzureRmOperationalInsightsWindowsEventDataSource",
16991700
"Get-AzOperationalInsightsSavedSearch": "Get-AzureRmOperationalInsightsSavedSearch",

src/Accounts/Accounts/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
## Upcoming Release
2121
* Update to latest version of ClientRuntime
2222

23+
## Version 1.2.1
24+
* Release with correct version of Authentication
25+
* Enable MSI Authentication in Azure Functions and WebApps
26+
2327
## Version 1.2.0
2428
* Add interactive and username/password authentication for Windows PowerShell 5.1 only
2529
* Update incorrect online help URLs

src/Accounts/Accounts/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
// You can specify all the values or you can default the Build and Revision Numbers
4444
// by using the '*' as shown below:
4545

46-
[assembly: AssemblyVersion("1.2.0")]
47-
[assembly: AssemblyFileVersion("1.2.0")]
46+
[assembly: AssemblyVersion("1.2.1")]
47+
[assembly: AssemblyFileVersion("1.2.1")]
4848
#if SIGN
4949
[assembly: InternalsVisibleTo("Microsoft.Azure.PowerShell.Cmdlets.Accounts.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
5050
[assembly: InternalsVisibleTo("Microsoft.WindowsAzure.Commands.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]

src/Accounts/Authentication.Test/AuthenticationFactoryTests.cs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Commands.Common.Authentication.Factories;
17-
using Microsoft.Azure.Commands.Common.Authentication.Models;
1817
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1918
using System;
2019
using System.Collections.Generic;
@@ -25,8 +24,6 @@
2524
using Microsoft.Azure.Commands.Common.Authentication.Test;
2625
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2726
using Xunit.Abstractions;
28-
using Microsoft.Rest.Azure;
29-
using Microsoft.Azure.Commands.ResourceManager.Common;
3027

3128
namespace Common.Authentication.Test
3229
{
@@ -180,7 +177,7 @@ public void CanAuthenticateUsingMSIDefault()
180177
IRenewableToken token = (IRenewableToken) authFactory.Authenticate(account, environment, tenant, null, null, null);
181178
_output.WriteLine($"Received access token for default Uri ${token.AccessToken}");
182179
Assert.Equal(expectedAccessToken, token.AccessToken);
183-
Assert.Equal(3600, Math.Round(token.ExpiresOn.DateTime.Subtract(DateTime.UtcNow).TotalSeconds));
180+
Assert.Equal(3600, Math.Round(token.ExpiresOn.Subtract(DateTimeOffset.Now).TotalSeconds));
184181
var account2 = new AzureAccount
185182
{
186183
Id = userId,
@@ -230,7 +227,7 @@ public void CanAuthenticateUsingMSIResourceId()
230227
IRenewableToken token = (IRenewableToken) authFactory.Authenticate(account, environment, tenant, null, null, null);
231228
_output.WriteLine($"Received access token for default Uri ${token.AccessToken}");
232229
Assert.Equal(expectedAccessToken, token.AccessToken);
233-
Assert.Equal(3600, Math.Round(token.ExpiresOn.DateTime.Subtract(DateTime.UtcNow).TotalSeconds));
230+
Assert.Equal(3600, Math.Round(token.ExpiresOn.Subtract(DateTimeOffset.Now).TotalSeconds));
234231
var account2 = new AzureAccount
235232
{
236233
Id = userId,
@@ -279,7 +276,7 @@ public void CanAuthenticateUsingMSIClientId()
279276
IRenewableToken token = (IRenewableToken) authFactory.Authenticate(account, environment, tenant, null, null, null);
280277
_output.WriteLine($"Received access token for default Uri ${token.AccessToken}");
281278
Assert.Equal(expectedAccessToken, token.AccessToken);
282-
Assert.Equal(3600, Math.Round(token.ExpiresOn.DateTime.Subtract(DateTime.UtcNow).TotalSeconds));
279+
Assert.Equal(3600, Math.Round(token.ExpiresOn.Subtract(DateTimeOffset.Now).TotalSeconds));
283280
var account2 = new AzureAccount
284281
{
285282
Id = userId,
@@ -328,7 +325,7 @@ public void CanAuthenticateUsingMSIObjectId()
328325
IRenewableToken token = (IRenewableToken) authFactory.Authenticate(account, environment, tenant, null, null, null);
329326
_output.WriteLine($"Received access token for default Uri ${token.AccessToken}");
330327
Assert.Equal(expectedAccessToken, token.AccessToken);
331-
Assert.Equal(3600, Math.Round(token.ExpiresOn.DateTime.Subtract(DateTime.UtcNow).TotalSeconds));
328+
Assert.Equal(3600, Math.Round(token.ExpiresOn.Subtract(DateTimeOffset.Now).TotalSeconds));
332329
var account2 = new AzureAccount
333330
{
334331
Id = userId,
@@ -351,7 +348,6 @@ void ResponseRedactionWorks()
351348

352349
void VerifyToken(IAccessToken checkToken, string expectedAccessToken, string expectedUserId, string expectedTenant)
353350
{
354-
355351
Assert.True(checkToken is RawAccessToken);
356352
Assert.Equal(expectedAccessToken, checkToken.AccessToken);
357353
Assert.Equal(expectedUserId, checkToken.UserId);
@@ -363,5 +359,45 @@ void VerifyToken(IAccessToken checkToken, string expectedAccessToken, string exp
363359
});
364360
}
365361

362+
[Fact]
363+
[Trait(Category.AcceptanceType, Category.CheckIn)]
364+
public void AppServiceManagedIdentity()
365+
{
366+
AzureSessionInitializer.InitializeAzureSession();
367+
var tenant = Guid.NewGuid().ToString();
368+
var userId = Guid.NewGuid().ToString();
369+
var environment = AzureEnvironment.PublicEnvironments["AzureCloud"];
370+
var account = new AzureAccount
371+
{
372+
Id = userId,
373+
Type = AzureAccount.AccountType.ManagedService
374+
};
375+
const string resource = @"https://management.azure.com/";
376+
const string endpoint = @"http://127.0.0.1:41217/MSI/token/";
377+
var expectedUri = $"{endpoint}?resource={resource}&api-version=2017-09-01";
378+
account.SetProperty(AzureAccount.Property.MSILoginUri , endpoint);
379+
account.SetProperty(AzureAccount.Property.MSILoginSecret , @"bar");
380+
const string expectedAccessToken = "foo";
381+
var expectedExpiresOn = DateTimeOffset.Parse("1/23/2019 7:15:42 AM +00:00");
382+
var responses = new Dictionary<string, ManagedServiceAppServiceTokenInfo>(StringComparer.OrdinalIgnoreCase)
383+
{
384+
{
385+
expectedUri,
386+
new ManagedServiceAppServiceTokenInfo()
387+
{
388+
AccessToken = expectedAccessToken,
389+
ExpiresOn = expectedExpiresOn,
390+
Resource = resource,
391+
TokenType = "Bearer",
392+
}
393+
}
394+
};
395+
AzureSession.Instance.RegisterComponent(HttpClientOperationsFactory.Name, () => TestHttpOperationsFactory.Create(responses, _output), true);
396+
var msat = new ManagedServiceAppServiceAccessToken(account, environment, tenant);
397+
Assert.Equal(expectedUri, msat.RequestUris.Peek());
398+
var accessToken = msat.AccessToken;
399+
Assert.Equal(expectedAccessToken, accessToken);
400+
Assert.Equal(expectedExpiresOn, msat.ExpiresOn);
401+
}
366402
}
367403
}

0 commit comments

Comments
 (0)