-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
763 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// 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. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Azure.Commands.Common.Exceptions; | ||
using Microsoft.Azure.Commands.ResourceManager.Common; | ||
using Microsoft.Azure.PowerShell.Common.Config; | ||
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes; | ||
using System.Management.Automation; | ||
|
||
namespace Microsoft.Azure.Commands.Common.Authentication.Config | ||
{ | ||
[Cmdlet("Export", AzureRMConstants.AzureRMPrefix + "Config", SupportsShouldProcess = true)] | ||
[CmdletPreview(ConfigCommandBase.PreviewMessage)] | ||
[OutputType(typeof(bool))] | ||
public class ExportConfigCommand : AzureRMCmdlet | ||
{ | ||
[Parameter(Position = 1, Mandatory = true, HelpMessage = "Specifies the path of the file to which to save the configs.")] | ||
[ValidateNotNullOrEmpty] | ||
public string Path { get; set; } | ||
|
||
[Parameter(HelpMessage = "Overwrites the given file if it exists.")] | ||
public SwitchParameter Force { get; set; } | ||
|
||
[Parameter(HelpMessage = "Returns a boolean value indicating success or failure.")] | ||
public SwitchParameter PassThru { get; set; } | ||
|
||
public override void ExecuteCmdlet() | ||
{ | ||
base.ExecuteCmdlet(); | ||
var dataStore = AzureSession.Instance.DataStore; | ||
AzureSession.Instance.TryGetComponent<IConfigManager>(nameof(IConfigManager), out var configManager); | ||
if (!dataStore.FileExists(configManager.ConfigFilePath)) | ||
{ | ||
throw new AzPSApplicationException("No configs to export. Make sure at least one config is set by `Update-AzConfig` with the `CurrentUser` scope.", ErrorKind.UserError); | ||
} | ||
|
||
Path = ResolveUserPath(Path); | ||
WriteDebugWithTimestamp($"[{nameof(ExportConfigCommand)}] Exporting configs to {Path}."); | ||
ConfirmAction( | ||
Force, | ||
$"Overwrite existing file at {Path}", | ||
$"Export configs to file at {Path}", | ||
$"all the configs at {ConfigScope.CurrentUser} scope", | ||
() => | ||
{ | ||
new JsonConfigHelper(configManager.ConfigFilePath, dataStore).ExportConfigFile(Path); | ||
WriteDebugWithTimestamp($"[{nameof(ExportConfigCommand)}] Configs are exported to {Path} successfully."); | ||
if (PassThru) | ||
{ | ||
WriteObject(true); | ||
} | ||
}, | ||
() => dataStore.FileExists(Path)); // only ask for confirmation if file exists | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// 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. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Azure.Commands.ResourceManager.Common; | ||
using Microsoft.Azure.PowerShell.Common.Config; | ||
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes; | ||
using System.Management.Automation; | ||
|
||
namespace Microsoft.Azure.Commands.Common.Authentication.Config | ||
{ | ||
[Cmdlet("Import", AzureRMConstants.AzureRMPrefix + "Config", SupportsShouldProcess = true)] | ||
[CmdletPreview(ConfigCommandBase.PreviewMessage)] | ||
[OutputType(typeof(bool))] | ||
public class ImportConfigCommand : AzureRMCmdlet | ||
{ | ||
[Parameter(Position = 1, Mandatory = true, HelpMessage = "Specifies the path to configuration saved by using Export-AzConfig.")] | ||
[ValidateNotNullOrEmpty] | ||
public string Path { get; set; } | ||
|
||
[Parameter(HelpMessage = "Returns a boolean value indicating success or failure.")] | ||
public SwitchParameter PassThru { get; set; } | ||
|
||
public override void ExecuteCmdlet() | ||
{ | ||
base.ExecuteCmdlet(); | ||
|
||
Path = ResolveUserPath(Path); | ||
WriteDebugWithTimestamp($"[{nameof(ImportConfigCommand)}] Importing configs from {Path}."); | ||
base.ConfirmAction($"Import configs from config file", Path, () => | ||
{ | ||
AzureSession.Instance.TryGetComponent<IConfigManager>(nameof(IConfigManager), out var configManager); | ||
new JsonConfigHelper(configManager.ConfigFilePath, AzureSession.Instance.DataStore).ImportConfigFile(Path); | ||
WriteDebugWithTimestamp($"[{nameof(ImportConfigCommand)}] Configs are imported from {Path} successfully. Rebuilding config manager."); | ||
configManager.BuildConfig(); | ||
WriteDebugWithTimestamp($"[{nameof(ImportConfigCommand)}] Rebuilt config manager."); | ||
if (PassThru) | ||
{ | ||
WriteObject(true); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
--- | ||
external help file: Microsoft.Azure.PowerShell.Cmdlets.Accounts.dll-Help.xml | ||
Module Name: Az.Accounts | ||
online version: https://docs.microsoft.com/powershell/module/az.accounts/export-azconfig | ||
schema: 2.0.0 | ||
--- | ||
|
||
# Export-AzConfig | ||
|
||
## SYNOPSIS | ||
Exports all the configs into a file so that it can be imported on another machine. | ||
|
||
## SYNTAX | ||
|
||
``` | ||
Export-AzConfig [-Path] <String> [-Force] [-PassThru] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] | ||
[-Confirm] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
The `Export-AzConfig` cmdlet exports all the configs that are set at the "CurrentUser" scope into a file at given path in JSON format. The file can then be imported by `Import-AzConfig` for example on another machine. | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
```powershell | ||
Export-AzConfig -Path ./config.json | ||
``` | ||
|
||
This example exports the configs to `./config.json` file which can later be imported via `Import-AzConfig`. | ||
|
||
## PARAMETERS | ||
|
||
### -DefaultProfile | ||
The credentials, account, tenant, and subscription used for communication with Azure. | ||
|
||
```yaml | ||
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer | ||
Parameter Sets: (All) | ||
Aliases: AzContext, AzureRmContext, AzureCredential | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Force | ||
Overwrites the given file if it exists. | ||
```yaml | ||
Type: System.Management.Automation.SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -PassThru | ||
Returns a boolean value indicating success or failure. | ||
```yaml | ||
Type: System.Management.Automation.SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Path | ||
Specifies the path of the file to which to save the configs. | ||
```yaml | ||
Type: System.String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 1 | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Confirm | ||
Prompts you for confirmation before running the cmdlet. | ||
```yaml | ||
Type: System.Management.Automation.SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: cf | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -WhatIf | ||
Shows what would happen if the cmdlet runs. | ||
The cmdlet is not run. | ||
```yaml | ||
Type: System.Management.Automation.SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: wi | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### CommonParameters | ||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). | ||
## INPUTS | ||
### None | ||
## OUTPUTS | ||
### System.Boolean | ||
## NOTES | ||
## RELATED LINKS | ||
[Import-AzConfig](./Import-AzConfig.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.