-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #617 Closes #275 Closes #180 Closes #620 Closes #351 Closes #237 Closes #408 Closes #402 Closes #325 Closes #308 Closes #297 Closes #296
- Loading branch information
1 parent
f6cb723
commit d776e40
Showing
57 changed files
with
552 additions
and
1,539 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
64 changes: 0 additions & 64 deletions
64
src/Azure.Functions.Cli/Actions/AzureActions/BaseAzureAccountAction.cs
This file was deleted.
Oops, something went wrong.
118 changes: 113 additions & 5 deletions
118
src/Azure.Functions.Cli/Actions/AzureActions/BaseAzureAction.cs
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 |
---|---|---|
@@ -1,14 +1,122 @@ | ||
using Azure.Functions.Cli.Arm; | ||
using System; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Functions.Cli.Arm; | ||
using Azure.Functions.Cli.Common; | ||
using Azure.Functions.Cli.Interfaces; | ||
using Fclp; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Azure.Functions.Cli.Actions.AzureActions | ||
{ | ||
abstract class BaseAzureAction : BaseAction | ||
abstract class BaseAzureAction : BaseAction, IInitializableAction | ||
{ | ||
protected readonly IArmManager _armManager; | ||
public string AccessToken { get; set; } | ||
public bool ReadStdin { get; set; } | ||
|
||
protected BaseAzureAction(IArmManager armManager) | ||
public override ICommandLineParserResult ParseArgs(string[] args) | ||
{ | ||
_armManager = armManager; | ||
Parser | ||
.Setup<string>("access-token") | ||
.WithDescription("Access token to use for performing authenticated azure actions") | ||
.Callback(t => AccessToken = t); | ||
Parser | ||
.Setup<bool>("access-token-stdin") | ||
.WithDescription("Read access token from stdin e.g: az account get-access-token | func ... --access-token-stdin") | ||
.Callback(f => ReadStdin = f); | ||
|
||
return base.ParseArgs(args); | ||
} | ||
|
||
public async Task Initialize() | ||
{ | ||
if (!string.IsNullOrEmpty(AccessToken)) | ||
{ | ||
return; | ||
} | ||
else if (ReadStdin && System.Console.In != null) | ||
{ | ||
var accessToken = System.Console.In.ReadToEnd().Trim(' ', '\n', '\r', '"'); | ||
if (accessToken.StartsWith("{")) | ||
{ | ||
var json = JsonConvert.DeserializeObject<JObject>(accessToken); | ||
AccessToken = json["accessToken"].ToString(); | ||
} | ||
else | ||
{ | ||
AccessToken = accessToken; | ||
} | ||
if (string.IsNullOrEmpty(AccessToken)) | ||
{ | ||
throw new CliException("Unable to set access token from stdin."); | ||
} | ||
} | ||
else if (ReadStdin && System.Console.In == null) | ||
{ | ||
throw new CliException("Stdin unavailable"); | ||
} | ||
else | ||
{ | ||
AccessToken = await GetAccessToken(); | ||
} | ||
} | ||
|
||
private async Task<string> GetAccessToken() | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || | ||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
{ | ||
return await AzureCliGetToken(); | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
return await AzureCliGetToken(); | ||
} | ||
catch (FileNotFoundException) | ||
{ | ||
try | ||
{ | ||
return await AzurePowershellGetToken(); | ||
} | ||
catch (FileNotFoundException) | ||
{ | ||
throw new CliException("Cannot get accessToken from az cli or Azure powershell. Please make sure to have either one installed."); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private async Task<string> AzureCliGetToken() | ||
{ | ||
if (CommandChecker.CommandExists("az")) | ||
{ | ||
var az = new Executable("az", "account get-access-token --query \"accessToken\""); | ||
var stdout = new StringBuilder(); | ||
var stderr = new StringBuilder(); | ||
var exitCode = await az.RunAsync(o => stdout.AppendLine(o), e => stderr.AppendLine(e)); | ||
if (exitCode != 0) | ||
{ | ||
throw new CliException(stderr.ToString().Trim(' ', '\n', '\r')); | ||
} | ||
else | ||
{ | ||
return stdout.ToString().Trim(' ', '\n', '\r', '"'); | ||
} | ||
} | ||
else | ||
{ | ||
throw new FileNotFoundException("Cannot find az cli. Please make sure to install az cli."); | ||
} | ||
} | ||
|
||
private Task<string> AzurePowershellGetToken() | ||
{ | ||
throw new FileNotFoundException("Cannot find powershell"); | ||
} | ||
} | ||
} |
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
30 changes: 0 additions & 30 deletions
30
src/Azure.Functions.Cli/Actions/AzureActions/BasePublishUserAction.cs
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/Azure.Functions.Cli/Actions/AzureActions/DeprecatedAzureActions.cs
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,25 @@ | ||
using System.Threading.Tasks; | ||
using Azure.Functions.Cli.Common; | ||
|
||
namespace Azure.Functions.Cli.Actions.AzureActions | ||
{ | ||
[Action(Name = "enable-git-repo", Context = Context.Azure, SubContext = Context.FunctionApp, ShowInHelp = false)] | ||
[Action(Name = "get-publish-username", Context = Context.Azure, ShowInHelp = false)] | ||
[Action(Name = "list", Context = Context.Azure, SubContext = Context.Account, ShowInHelp = false)] | ||
[Action(Name = "list", Context = Context.Azure, SubContext = Context.Subscriptions, ShowInHelp = false)] | ||
[Action(Name = "list", Context = Context.Azure, SubContext = Context.FunctionApp, ShowInHelp = false)] | ||
[Action(Name = "list", Context = Context.Azure, SubContext = Context.Storage, ShowInHelp = false)] | ||
[Action(Name = "login", Context = Context.Azure, ShowInHelp = false)] | ||
[Action(Name = "logout", Context = Context.Azure, ShowInHelp = false)] | ||
[Action(Name = "set", Context = Context.Azure, SubContext = Context.Account, ShowInHelp = false)] | ||
[Action(Name = "set", Context = Context.Azure, SubContext = Context.Subscriptions, ShowInHelp = false)] | ||
[Action(Name = "set-publish-password", Context = Context.Azure, ShowInHelp = false)] | ||
[Action(Name = "set-publish-username", Context = Context.Azure, ShowInHelp = false)] | ||
internal class DeprecatedAzureActions : BaseAction | ||
{ | ||
public override Task RunAsync() | ||
{ | ||
throw new CliException("This command has been removed. Please use az-cli (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) or Azure Powershell (https://docs.microsoft.com/en-us/powershell/azure/overview) for management commands."); | ||
} | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
src/Azure.Functions.Cli/Actions/AzureActions/EnableGitRepoAction.cs
This file was deleted.
Oops, something went wrong.
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.