From a006a0a46c534d902bc268c396aa660929b2cc84 Mon Sep 17 00:00:00 2001 From: amgrobelny-box Date: Mon, 4 Dec 2017 19:37:53 -0600 Subject: [PATCH] Added new --token feature, fixed collaboration command bugs, fixed progress bar for uploads, added more error messaging on config and private key failure, updated Box SDK, and bumped to next minor version, v1.1.0 --- BoxCLI/BoxCLI.csproj | 2 +- BoxCLI/BoxCLIInfo.cs | 2 +- .../BoxHome/BoxHomeFiles/BoxEnvironments.cs | 68 +++++++++++++------ .../BoxHome/Models/BoxHomeDefaultSettings.cs | 2 +- .../BoxPlatform/Service/BoxPlatformService.cs | 4 +- .../Service/BoxPlatformServiceBuilder.cs | 13 ++-- .../Service/IBoxPlatformServiceBuilder.cs | 2 +- .../CommandOptions/ProvideTokenOption.cs | 11 +++ BoxCLI/CommandUtilities/GeneralUtilities.cs | 10 +++ BoxCLI/CommandUtilities/ProgressBar.cs | 5 +- BoxCLI/Commands/BoxBaseCommand.cs | 20 ++++-- BoxCLI/Commands/BoxItemCommandBase.cs | 37 +++------- BoxCLI/Commands/CollaborationCommand.cs | 1 + BoxCLI/Commands/CollaborationOnItemCommand.cs | 3 +- .../CollaborationAddCommand.cs | 18 ++--- .../CollaborationDeleteCommand.cs | 54 +++++++-------- .../CollaborationGetCommand.cs | 2 +- .../CollaborationGetPendingCommand.cs | 2 +- .../CollaborationListCommand.cs | 2 +- .../CollaborationListForGroupCommand.cs | 4 +- .../CollaborationSubCommandBase.cs | 26 +++++-- .../CollaborationUpdateCommand.cs | 19 ++---- .../FilesCollaborationSubCommandFactory.cs | 6 +- .../FoldersCollaborationSubCommandFactory.cs | 4 ++ .../CommentCreateCommand.cs | 2 +- .../CommentDeleteCommand.cs | 2 +- .../CommentSubCommands/CommentGetCommand.cs | 2 +- .../CommentSubCommands/CommentListCommand.cs | 4 +- .../CommentUpdateCommand.cs | 2 +- ...eEnvironmentUpdatePrivateKeyPathCommand.cs | 9 ++- .../ConfigureEnvironmentsAddCommand.cs | 8 ++- ...EnvironmentsUpdateConfigFilePathCommand.cs | 9 ++- .../EventSubCommands/EventGetCommand.cs | 4 +- .../EventSubCommands/EventPollCommand.cs | 2 +- .../EventSubCommands/EventSubCommandBase.cs | 4 +- .../FileSubCommand/FileDeleteCommand.cs | 2 +- .../FileSubCommand/FileDownloadCommand.cs | 2 +- .../Commands/FileSubCommand/FileGetCommand.cs | 2 +- .../FileSubCommand/FileLockCommand.cs | 2 +- .../FileSubCommand/FileRenameCommand.cs | 2 +- .../FileSubCommand/FileSubCommandBase.cs | 6 +- .../FileSubCommand/FileUnlockCommand.cs | 2 +- .../FileSubCommand/FileUpdateCommand.cs | 2 +- .../FileSubCommand/FileUpdateLockCommand.cs | 2 +- .../FileVersionDeleteCommand.cs | 4 +- .../FileVersionListCommand.cs | 2 +- .../FileVersionPromoteCommand.cs | 2 +- .../FolderChangeUploadEmailCommand.cs | 2 +- .../FolderSubCommands/FolderCreateCommand.cs | 4 +- .../FolderSubCommands/FolderDeleteCommand.cs | 2 +- .../FolderDownloadCommand.cs | 2 +- .../FolderSubCommands/FolderGetCommand.cs | 2 +- .../FolderListItemsCommand.cs | 4 +- .../FolderSubCommands/FolderRenameCommand.cs | 2 +- .../FolderSubCommands/FolderSubCommandBase.cs | 12 ++-- .../FolderSubCommands/FolderUpdateCommand.cs | 4 +- .../FolderSubCommands/FolderUploadCommand.cs | 2 +- .../GroupSubCommands/GroupCreateCommand.cs | 4 +- .../GroupSubCommands/GroupDeleteCommand.cs | 4 +- .../GroupSubCommands/GroupGetCommand.cs | 2 +- .../GroupSubCommands/GroupListCommand.cs | 4 +- .../GroupMembershipCreateCommand.cs | 2 +- .../GroupMembershipDeleteCommand.cs | 2 +- .../GroupMembershipGetCommand.cs | 2 +- .../GroupMembershipListCommand.cs | 5 +- .../GroupMembershipUpdateCommand.cs | 2 +- .../GroupSubCommands/GroupSubCommandBase.cs | 4 +- .../GroupSubCommands/GroupUpdateCommand.cs | 2 +- .../MetadataCreateCommand.cs | 2 +- .../MetadataGetAllCommand.cs | 2 +- .../MetadataSubCommands/MetadataGetCommand.cs | 2 +- .../MetadataSubCommandBase.cs | 4 +- .../MetadataUpdateCommand.cs | 2 +- .../MetadataTemplateCreateCommand.cs | 2 +- .../MetadataTemplateGetCommand.cs | 2 +- .../MetadataTemplateListCommand.cs | 2 +- .../MetadataTemplateSubCommandBase.cs | 13 +++- BoxCLI/Commands/SearchCommand.cs | 2 +- .../SharedLinkCreateCommand.cs | 4 +- .../SharedLinkDeleteCommand.cs | 2 +- .../SharedLinkGetCommand.cs | 2 +- .../SharedLinkSubCommandBase.cs | 4 +- .../SharedLinkUpdateCommand.cs | 2 +- .../TaskAssignmentCreateCommand.cs | 2 +- .../TaskAssignmentDeleteCommand.cs | 2 +- .../TaskAssignmentGetCommand.cs | 2 +- .../TaskAssignmentListCommand.cs | 4 +- .../TaskAssignmentUpdateCommand.cs | 2 +- .../TaskSubCommands/TaskCreateCommand.cs | 2 +- .../TaskSubCommands/TaskDeleteCommand.cs | 2 +- .../TaskSubCommands/TaskGetCommand.cs | 2 +- .../TaskSubCommands/TaskListCommand.cs | 4 +- .../TaskSubCommands/TaskUpdateCommand.cs | 2 +- .../TrashSubCommands/TrashDeleteCommand.cs | 2 +- .../TrashSubCommands/TrashGetCommand.cs | 2 +- .../TrashSubCommands/TrashListCommand.cs | 4 +- .../TrashSubCommands/TrashRestoreCommand.cs | 2 +- .../UserAddEmailAliasCommand.cs | 2 +- .../UserSubCommands/UserChangeLoginCommand.cs | 2 +- .../UserSubCommands/UserCreateCommand.cs | 3 +- .../UserSubCommands/UserDeleteCommand.cs | 2 +- .../UserDeleteEmailAliasCommand.cs | 2 +- .../UserSubCommands/UserGetCommand.cs | 29 ++------ .../UserGetEmailAliasesCommand.cs | 2 +- .../UserSubCommands/UserInviteCommand.cs | 2 +- .../UserSubCommands/UserListCommand.cs | 4 +- .../UserMoveRootContentCommand.cs | 2 +- .../UserSubCommands/UserSearchCommand.cs | 5 +- .../UserSubCommands/UserSubCommandBase.cs | 13 +++- .../UserSubCommands/UserUpdateCommand.cs | 2 +- .../WebhooksCreateCommand.cs | 4 +- .../WebhooksDeleteCommand.cs | 2 +- .../WebhooksSubComands/WebhooksGetCommand.cs | 8 +-- .../WebhooksSubComands/WebhooksListCommand.cs | 4 +- .../WebhooksSubCommandBase.cs | 8 +-- .../WebhooksUpdateCommand.cs | 4 +- BoxCLI/Program.cs | 27 +++++++- CHANGELOG.md | 10 +++ 118 files changed, 398 insertions(+), 284 deletions(-) create mode 100644 BoxCLI/CommandUtilities/CommandOptions/ProvideTokenOption.cs diff --git a/BoxCLI/BoxCLI.csproj b/BoxCLI/BoxCLI.csproj index 7f5c5514..2b364f63 100644 --- a/BoxCLI/BoxCLI.csproj +++ b/BoxCLI/BoxCLI.csproj @@ -7,7 +7,7 @@ BoxCLI - + diff --git a/BoxCLI/BoxCLIInfo.cs b/BoxCLI/BoxCLIInfo.cs index 5f9cb680..1bda159a 100644 --- a/BoxCLI/BoxCLIInfo.cs +++ b/BoxCLI/BoxCLIInfo.cs @@ -4,6 +4,6 @@ public class BoxCLIInfo { public const string ProductTitle = "Box CLI"; - public const string Version = "1.0.2"; + public const string Version = "1.1.0"; } } \ No newline at end of file diff --git a/BoxCLI/BoxHome/BoxHomeFiles/BoxEnvironments.cs b/BoxCLI/BoxHome/BoxHomeFiles/BoxEnvironments.cs index a9e8709d..f4bef80e 100644 --- a/BoxCLI/BoxHome/BoxHomeFiles/BoxEnvironments.cs +++ b/BoxCLI/BoxHome/BoxHomeFiles/BoxEnvironments.cs @@ -25,9 +25,12 @@ public BoxEnvironments(string fileName, IBoxHome home) _boxHome = home; _boxHomeEnvironmentsFileName = fileName; } - public bool VerifyBoxConfigFile(string filePath) + public bool VerifyBoxConfigFile(string filePath, bool ignoreFilePathTranslation = false) { - filePath = GeneralUtilities.TranslatePath(filePath); + if (!ignoreFilePathTranslation) + { + filePath = GeneralUtilities.TranslatePath(filePath); + } Reporter.WriteInformation($"Looking for file at this path {filePath}"); if (File.Exists(filePath)) { @@ -71,6 +74,7 @@ public bool VerifyBoxConfigFile(string filePath) } else { + Reporter.WriteError($"Couldn't open config file at this path: {filePath}"); return false; } } @@ -95,28 +99,35 @@ public BoxHomeConfigModel RevalidateExistingConfigFile(string filePath, string p { return TranslateConfigFileToEnvironment(filePath, privateKeyPath); } - public BoxHomeConfigModel TranslateConfigFileToEnvironment(string filePath, string privateKeyPath = "") + public BoxHomeConfigModel TranslateConfigFileToEnvironment(string filePath, string privateKeyPath = "", bool ignoreFilePathTranslation = false) { - filePath = GeneralUtilities.TranslatePath(filePath); + if (!ignoreFilePathTranslation) + { + filePath = GeneralUtilities.TranslatePath(filePath); + } var translatedConfig = new BoxHomeConfigModel(); if (File.Exists(filePath)) { var config = DeserializeBoxConfigFile(filePath); if (!string.IsNullOrEmpty(privateKeyPath)) { - var potentialPathFromOptions = GeneralUtilities.TranslatePath(privateKeyPath); - if (File.Exists(potentialPathFromOptions)) + if (!ignoreFilePathTranslation) { - translatedConfig.PrivateKeyPath = potentialPathFromOptions; + privateKeyPath = GeneralUtilities.TranslatePath(privateKeyPath); + } + if (File.Exists(privateKeyPath)) + { + translatedConfig.PrivateKeyPath = privateKeyPath; } else { - throw new Exception("Couldn't access the private key file from the path provided."); + throw new Exception($"Couldn't access the private key file from the path provided: {privateKeyPath}."); } } else if (!string.IsNullOrEmpty(config.AppSettings.AppAuth.PrivateKey)) { Reporter.WriteInformation("Detected private key value in config..."); + Reporter.WriteInformation("Calculating between in-line private key or separate private key file..."); var pattern = @"^-----BEGIN ENCRYPTED PRIVATE KEY-----\n"; var regex = new Regex(pattern); if (regex.IsMatch(config.AppSettings.AppAuth.PrivateKey)) @@ -127,11 +138,19 @@ public BoxHomeConfigModel TranslateConfigFileToEnvironment(string filePath, stri else { Reporter.WriteInformation("Attempting to resolve file path for private key."); - var potentialPath = GeneralUtilities.TranslateDependentPath(config.AppSettings.AppAuth.PrivateKey, filePath); - Reporter.WriteInformation($"Found {potentialPath}."); - if (File.Exists(potentialPath)) + var privateKeyPathInline = config.AppSettings.AppAuth.PrivateKey; + if (!ignoreFilePathTranslation) + { + privateKeyPathInline = GeneralUtilities.TranslateDependentPath(privateKeyPathInline, filePath); + } + Reporter.WriteInformation($"Path to private key file identified: {privateKeyPathInline}."); + if (File.Exists(privateKeyPathInline)) { - translatedConfig.PrivateKeyPath = potentialPath; + translatedConfig.PrivateKeyPath = privateKeyPathInline; + } + else + { + throw new Exception($"Unable to open private key file at {privateKeyPathInline}"); } } } @@ -145,7 +164,7 @@ public BoxHomeConfigModel TranslateConfigFileToEnvironment(string filePath, stri } else { - Reporter.WriteError("Couldn't open file..."); + throw new Exception($"Couldn't open config file at {filePath}"); } return translatedConfig; } @@ -303,7 +322,8 @@ public bool UpdatePrivateKeyPath(string existingName, string newPath) this.SerializeBoxEnvironmentFile(environments); return true; } - public bool UpdateConfigFilePath(string existingName, string newPath, string newPemPath = "") + public bool UpdateConfigFilePath(string existingName, string newPath, string newPemPath = "", + bool ignoreFilePathTranslation = false) { var environments = DeserializeBoxEnvironmentFile(); var foundEnv = new BoxHomeConfigModel(); @@ -312,18 +332,24 @@ public bool UpdateConfigFilePath(string existingName, string newPath, string new { throw new Exception("Couldn't find that environment"); } - var translatePath = GeneralUtilities.TranslatePath(newPath); - if (this.VerifyBoxConfigFile(translatePath)) + if (!ignoreFilePathTranslation) + { + newPath = GeneralUtilities.TranslatePath(newPath); + } + if (this.VerifyBoxConfigFile(newPath)) { BoxHomeConfigModel env; if (!string.IsNullOrEmpty(newPemPath)) { - var translatePemPath = GeneralUtilities.TranslatePath(newPemPath); - env = this.TranslateConfigFileToEnvironment(translatePath, translatePemPath); + if (!ignoreFilePathTranslation) + { + newPemPath = GeneralUtilities.TranslatePath(newPemPath); + } + env = this.TranslateConfigFileToEnvironment(newPath, newPemPath, ignoreFilePathTranslation: ignoreFilePathTranslation); } else { - env = this.TranslateConfigFileToEnvironment(translatePath); + env = this.TranslateConfigFileToEnvironment(newPath, ignoreFilePathTranslation: ignoreFilePathTranslation); } foundEnv.BoxConfigFilePath = env.BoxConfigFilePath; foundEnv.ClientId = env.ClientId; @@ -500,7 +526,7 @@ public bool DeleteEnvironment(string name) throw new Exception("Couldn't find this environment."); } } - public bool UpdateEnvironmentFilePath(string path, string envName) + public bool UpdateEnvironmentFilePath(string path, string envName, bool ignoreFilePathTranslation = false) { var environments = DeserializeBoxEnvironmentFile(); var foundEnv = new BoxHomeConfigModel(); @@ -511,7 +537,7 @@ public bool UpdateEnvironmentFilePath(string path, string envName) } if (this.VerifyBoxConfigFile(path)) { - var newEnv = this.TranslateConfigFileToEnvironment(path); + var newEnv = this.TranslateConfigFileToEnvironment(path, ignoreFilePathTranslation: ignoreFilePathTranslation); newEnv.AdminAsUserId = (string.IsNullOrEmpty(foundEnv.AdminAsUserId)) ? "" : foundEnv.AdminAsUserId; newEnv.DefaultAsUserId = (string.IsNullOrEmpty(foundEnv.DefaultAsUserId)) ? "" : foundEnv.DefaultAsUserId; newEnv.UseDefaultAsUser = foundEnv.UseDefaultAsUser; diff --git a/BoxCLI/BoxHome/Models/BoxHomeDefaultSettings.cs b/BoxCLI/BoxHome/Models/BoxHomeDefaultSettings.cs index cbe101e7..8b7fbf90 100644 --- a/BoxCLI/BoxHome/Models/BoxHomeDefaultSettings.cs +++ b/BoxCLI/BoxHome/Models/BoxHomeDefaultSettings.cs @@ -18,6 +18,6 @@ public class BoxHomeDefaultSettings [JsonProperty(PropertyName = "autoSave")] public bool AutoSave { get; set; } = false; [JsonProperty(PropertyName = "outputJson")] - public bool OutputJson { get; set; } = false; + public bool OutputJson { get; set; } = true; } } \ No newline at end of file diff --git a/BoxCLI/BoxPlatform/Service/BoxPlatformService.cs b/BoxCLI/BoxPlatform/Service/BoxPlatformService.cs index 81d56fd2..c2ed9880 100644 --- a/BoxCLI/BoxPlatform/Service/BoxPlatformService.cs +++ b/BoxCLI/BoxPlatform/Service/BoxPlatformService.cs @@ -34,8 +34,8 @@ public BoxClient AsUserClient(string asUserId) } public BoxClient ClientFromToken(string token) { - var auth = new OAuthSession(token, "", 3600, "bearer"); - return new BoxClient(this.BoxPlatformConfig, auth); + var auth = new OAuthSession(token, "1", 3600, "bearer"); + return new BoxClient(new BoxConfig("", "", new Uri("http://localhost")), auth); } public async Task BustCache() diff --git a/BoxCLI/BoxPlatform/Service/BoxPlatformServiceBuilder.cs b/BoxCLI/BoxPlatform/Service/BoxPlatformServiceBuilder.cs index 8d00aba4..05e33485 100644 --- a/BoxCLI/BoxPlatform/Service/BoxPlatformServiceBuilder.cs +++ b/BoxCLI/BoxPlatform/Service/BoxPlatformServiceBuilder.cs @@ -95,12 +95,15 @@ public void SetIterators() BoxService.BoxCollectionsIterators = BoxIterators; } - public IBoxPlatformService Build() + public IBoxPlatformService Build(bool isTokenCall = false) { - SetConfig(); - SetCache(); - SetAuthorizedClient(); - SetIterators(); + if (!isTokenCall) + { + SetConfig(); + SetCache(); + SetAuthorizedClient(); + SetIterators(); + } return BoxService; } } diff --git a/BoxCLI/BoxPlatform/Service/IBoxPlatformServiceBuilder.cs b/BoxCLI/BoxPlatform/Service/IBoxPlatformServiceBuilder.cs index c1a92645..efcd8fc3 100644 --- a/BoxCLI/BoxPlatform/Service/IBoxPlatformServiceBuilder.cs +++ b/BoxCLI/BoxPlatform/Service/IBoxPlatformServiceBuilder.cs @@ -4,6 +4,6 @@ namespace BoxCLI.BoxPlatform.Service { public interface IBoxPlatformServiceBuilder { - IBoxPlatformService Build(); + IBoxPlatformService Build(bool isTokenCall = false); } } \ No newline at end of file diff --git a/BoxCLI/CommandUtilities/CommandOptions/ProvideTokenOption.cs b/BoxCLI/CommandUtilities/CommandOptions/ProvideTokenOption.cs new file mode 100644 index 00000000..64c76147 --- /dev/null +++ b/BoxCLI/CommandUtilities/CommandOptions/ProvideTokenOption.cs @@ -0,0 +1,11 @@ +using System; +using Microsoft.Extensions.CommandLineUtils; + +namespace BoxCLI.CommandUtilities.CommandOptions +{ + public static class ProvideTokenOption + { + public static CommandOption ConfigureOption(CommandLineApplication command) + => command.Option("--token ", "Provide a token to perform this call", CommandOptionType.SingleValue); + } +} diff --git a/BoxCLI/CommandUtilities/GeneralUtilities.cs b/BoxCLI/CommandUtilities/GeneralUtilities.cs index a268d89a..fc6def7b 100644 --- a/BoxCLI/CommandUtilities/GeneralUtilities.cs +++ b/BoxCLI/CommandUtilities/GeneralUtilities.cs @@ -129,6 +129,11 @@ public static string TranslateDependentPath(string path, string containerPath) path = path.Substring(match.Length - 1); } + if (path.StartsWith("/")) + { + return path; + } + if (!path.StartsWith(Path.DirectorySeparatorChar.ToString()) && !path.StartsWith("~") && !path.StartsWith("..") && !path.StartsWith($".{Path.DirectorySeparatorChar}") && !winDirectoryRegex.IsMatch(path)) { @@ -188,6 +193,11 @@ public static string TranslatePath(string path) path = path.Substring(match.Length - 1); } + if (path.StartsWith("/")) + { + return path; + } + if (!path.StartsWith(Path.DirectorySeparatorChar.ToString()) && !path.StartsWith("~") && !path.StartsWith("..") && !path.StartsWith($".{Path.DirectorySeparatorChar}") && !winDirectoryRegex.IsMatch(path)) { diff --git a/BoxCLI/CommandUtilities/ProgressBar.cs b/BoxCLI/CommandUtilities/ProgressBar.cs index 1de97545..805171d3 100644 --- a/BoxCLI/CommandUtilities/ProgressBar.cs +++ b/BoxCLI/CommandUtilities/ProgressBar.cs @@ -13,7 +13,10 @@ public static void UpdateProgress(string item, int progress, int total) lock (_sync) { Console.CursorLeft = 0; - Console.Write(item + " [" + new string('=', percentage / 2) + "] " + percentage + "%"); + var spaces = new string(' ', 100 - percentage); + var equals = new string('=', percentage); + var output = $"{item} [{equals}{spaces}] {percentage}%"; + Console.Write(output); } } } diff --git a/BoxCLI/Commands/BoxBaseCommand.cs b/BoxCLI/Commands/BoxBaseCommand.cs index 419cff47..8b39e6c8 100644 --- a/BoxCLI/Commands/BoxBaseCommand.cs +++ b/BoxCLI/Commands/BoxBaseCommand.cs @@ -34,6 +34,7 @@ public abstract class BoxBaseCommand : HelpCommandBaseAsync protected readonly IBoxPlatformServiceBuilder _boxPlatformBuilder; protected readonly LocalizedStringsResource _names; protected CommandOption _json; + protected CommandOption _oneUseToken; public BoxBaseCommand(IBoxPlatformServiceBuilder boxPlatformBuilder, IBoxHome boxHome, LocalizedStringsResource names) { @@ -48,6 +49,7 @@ public override void Configure(CommandLineApplication command) { base.Configure(command); _json = OutputJsonOption.ConfigureOption(command); + _oneUseToken = ProvideTokenOption.ConfigureOption(command); } protected virtual void CheckForId(string id, CommandLineApplication app, string message = "") @@ -132,14 +134,18 @@ protected virtual string ConstructDownloadsPath(string fileName, string filePath } protected virtual BoxClient ConfigureBoxClient(string oneCallAsUserId = null, - bool returnServiceAccount = false, bool asAdmin = false) + bool asAdmin = false, string oneCallWithToken = null) { - var Box = _boxPlatformBuilder.Build(); - if (!string.IsNullOrEmpty(oneCallAsUserId) && !returnServiceAccount) + var Box = _boxPlatformBuilder.Build(!string.IsNullOrEmpty(oneCallWithToken)); + if (!string.IsNullOrEmpty(oneCallWithToken)) + { + return Box.ClientFromToken(oneCallWithToken); + } + else if (!string.IsNullOrEmpty(oneCallAsUserId)) { return Box.AsUserClient(oneCallAsUserId); } - else if (asAdmin && !returnServiceAccount) + else if (asAdmin) { if (string.IsNullOrEmpty(this._environments.GetAdminAsUserIdSetting())) { @@ -147,7 +153,7 @@ protected virtual BoxClient ConfigureBoxClient(string oneCallAsUserId = null, } return Box.AsUserClient(this._environments.GetAdminAsUserIdSetting()); } - else if (this._environments.GetUserSessionEnabledSetting() && !returnServiceAccount) + else if (this._environments.GetUserSessionEnabledSetting()) { Reporter.WriteInformation("User session enabled..."); var expiresAt = this._environments.GetUserSessionExpirationSetting(); @@ -175,9 +181,9 @@ protected virtual BoxClient ConfigureBoxClient(string oneCallAsUserId = null, } } - protected virtual IBoxCollectionsIterators GetIterators() + protected virtual IBoxCollectionsIterators GetIterators(bool isTokenCall = false) { - var box = _boxPlatformBuilder.Build(); + var box = _boxPlatformBuilder.Build(isTokenCall); return box.BoxCollectionsIterators; } diff --git a/BoxCLI/Commands/BoxItemCommandBase.cs b/BoxCLI/Commands/BoxItemCommandBase.cs index 66241870..fe79b446 100644 --- a/BoxCLI/Commands/BoxItemCommandBase.cs +++ b/BoxCLI/Commands/BoxItemCommandBase.cs @@ -174,7 +174,7 @@ protected List ReadCustomFile(string path) protected async Task UploadFile(string path, string parentId = "", string fileName = "", string fileId = "", bool isNewVersion = false, bool idOnly = false) { - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); path = GeneralUtilities.TranslatePath(path); var file = new FileInfo(path); @@ -189,11 +189,11 @@ protected async Task UploadFile(string path, string parentId = "", stri if (file.Length >= MINIUMUM_CHUNKED_UPLOAD_FILE_SIZE && isNewVersion) { - return await this.ChunkedUpload(path, fileName, parentId, file.Length, fileId, true, idOnly: idOnly); + return await this.ChunkedUpload(path, fileName, parentId, file.Length, boxClient, fileId, true, idOnly: idOnly); } else if (file.Length >= MINIUMUM_CHUNKED_UPLOAD_FILE_SIZE) { - return await this.ChunkedUpload(path, fileName, parentId, file.Length, idOnly: idOnly); + return await this.ChunkedUpload(path, fileName, parentId, file.Length, boxClient, idOnly: idOnly); } else { @@ -302,9 +302,8 @@ protected async Task ProcessFileUploadsFromFile(string path, string asUser = "", } private async Task ChunkedUpload(string path, string fileName, string parentFolderId, - long fileSize, string fileId = "", bool isNewVersion = false, bool idOnly = false) + long fileSize, BoxClient boxClient, string fileId = "", bool isNewVersion = false, bool idOnly = false) { - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); using (var fileInMemoryStream = File.Open(path, FileMode.Open)) { if (!idOnly) @@ -354,31 +353,17 @@ private async Task ChunkedUpload(string path, string fileName, string p Reporter.WriteInformation(""); Reporter.WriteInformation("Attempting to commit..."); } - const int retryCount = 5; - var retryInterval = boxSessionParts.Count() * 100; + // const int retryCount = 5; + // var retryInterval = boxSessionParts.Count() * 100; // Commit if (!string.IsNullOrEmpty(fileId)) { - //TODO: Fix after SDK update - var command = boxClient.ResourcePlugins.Get(); - var response = - await Box.V2.Utility.Retry.ExecuteAsync( - async () => - await command.CommitSessionAsync(commitUri, completeFileSha, sessionPartsForCommit), - TimeSpan.FromMilliseconds(retryInterval), retryCount); - - return response; + return await boxClient.FilesManager.CommitFileVersionSessionAsync(commitUri, completeFileSha, sessionPartsForCommit); } else { - var response = - await Box.V2.Utility.Retry.ExecuteAsync( - async () => - await boxClient.FilesManager.CommitSessionAsync(commitUri, completeFileSha, sessionPartsForCommit), - TimeSpan.FromMilliseconds(retryInterval), retryCount); - - return response; + return await boxClient.FilesManager.CommitSessionAsync(commitUri, completeFileSha, sessionPartsForCommit); } } } @@ -494,7 +479,7 @@ private async Task> UploadPartsInSessionAsync( return ret; } - protected async Task ProcessBulkDownload(string path, string asUser = "", bool isNewVersion = false) + protected async Task ProcessBulkDownload(string path, bool isNewVersion = false) { try { @@ -511,7 +496,7 @@ protected async Task ProcessFolderBulkDownload(string path, string asUser = "", { try { - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); path = GeneralUtilities.TranslatePath(path); var idsList = this.ReadFileForIds(path); var fileList = new List(); @@ -537,7 +522,7 @@ protected async Task ProcessFolderBulkDownload(string path, string asUser = "", } protected async Task BulkDownload(List files, string fileName = "") { - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); using (var archive = ZipArchive.Create()) { Reporter.WriteInformation("Created zip archive..."); diff --git a/BoxCLI/Commands/CollaborationCommand.cs b/BoxCLI/Commands/CollaborationCommand.cs index a1287c18..ea7a08d2 100644 --- a/BoxCLI/Commands/CollaborationCommand.cs +++ b/BoxCLI/Commands/CollaborationCommand.cs @@ -21,6 +21,7 @@ public override void Configure(CommandLineApplication command) command.Command(base._names.SubCommandNames.Update, _subCommands.CreateSubCommand(_names.SubCommandNames.Update).Configure); command.Command(base._names.SubCommandNames.GetPending, _subCommands.CreateSubCommand(_names.SubCommandNames.GetPending).Configure); command.Command(base._names.SubCommandNames.ListForGroup, _subCommands.CreateSubCommand(_names.SubCommandNames.ListForGroup).Configure); + command.Command(base._names.SubCommandNames.Delete, _subCommands.CreateSubCommand(_names.SubCommandNames.Delete).Configure); command.OnExecute(async () => { diff --git a/BoxCLI/Commands/CollaborationOnItemCommand.cs b/BoxCLI/Commands/CollaborationOnItemCommand.cs index e115669e..0df39a83 100644 --- a/BoxCLI/Commands/CollaborationOnItemCommand.cs +++ b/BoxCLI/Commands/CollaborationOnItemCommand.cs @@ -19,6 +19,7 @@ public override void Configure(CommandLineApplication command) command.Command(base._names.SubCommandNames.List, _subCommands.CreateSubCommand(_names.SubCommandNames.List).Configure); command.Command(base._names.SubCommandNames.Add, _subCommands.CreateSubCommand(_names.SubCommandNames.Add).Configure); command.Command(base._names.SubCommandNames.Update, _subCommands.CreateSubCommand(_names.SubCommandNames.Update).Configure); + command.Command(base._names.SubCommandNames.Delete, _subCommands.CreateSubCommand(_names.SubCommandNames.Delete).Configure); command.OnExecute(async () => { @@ -34,7 +35,7 @@ protected async override Task Execute() } private readonly ISubCommandFactory _subCommands; - public CollaborationOnItemCommand(IBoxPlatformServiceBuilder boxPlatformBuilder, IBoxHome boxHome, SubCommandFactory factory, + public CollaborationOnItemCommand(IBoxPlatformServiceBuilder boxPlatformBuilder, IBoxHome boxHome, SubCommandFactory factory, LocalizedStringsResource names, BoxType t = BoxType.enterprise) : base(boxPlatformBuilder, boxHome, names) { diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationAddCommand.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationAddCommand.cs index 48c91a25..a995577a 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationAddCommand.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationAddCommand.cs @@ -84,10 +84,10 @@ private async Task RunCreate() { json = true; } - await base.ProcessCollaborationsFromFile(_id.Value, _path.Value(), base._t, _asUser.Value(), json: json); + await base.ProcessCollaborationsFromFile(_id.Value, _path.Value(), base._t, json: json); } base.CheckForValue(this._id.Value, this._app, "An ID is required for this command."); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); BoxType type; if (base._t == BoxType.enterprise) { @@ -104,16 +104,10 @@ private async Task RunCreate() } else { - var roles = new Dictionary() - { - {"editor", this._editor.HasValue()}, - {"viewer", this._viewer.HasValue()}, - {"uploader", this._uploader.HasValue()}, - {"previewer uploader", this._previewerUploader.HasValue()}, - {"viewer uploader", this._viewerUploader.HasValue()}, - {"co-owner", this._coowner.HasValue()}, - }; - role = base.ProcessRoleOptions(roles); + role = base.ProcessRoleOptions(editor: this._editor, viewer: this._viewer, + uploader: this._uploader, previewerUploader: this._previewerUploader, + viewerUploader: this._viewerUploader, coOwner: this._coowner, + previewer: this._previewer); } var collabRequest = new BoxCollaborationRequest(); if (this._canViewPath.HasValue()) diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationDeleteCommand.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationDeleteCommand.cs index ba8901e5..f5e4231f 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationDeleteCommand.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationDeleteCommand.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using BoxCLI.BoxHome; using BoxCLI.BoxPlatform.Service; @@ -44,26 +44,26 @@ private async Task RunDelete() base.CheckForValue(this._id.Value, this._app, "A collaboration ID is required for this command."); bool collabDeleted = false; - if (this._dontPrompt.HasValue()) - { - collabDeleted = await this.DeleteCollaboration(); - } - else - { - Reporter.WriteWarningNoNewLine("Are you sure you want to delete this collaboration? y/N "); - var yNKey = "n"; - yNKey = Console.ReadLine().ToLower(); - if (yNKey != "y") - { - Reporter.WriteInformation("Aborted collaboration deletion."); - return; - } - else - { - collabDeleted = await this.DeleteCollaboration(); - } - } - if(collabDeleted) + if (this._dontPrompt.HasValue()) + { + collabDeleted = await this.DeleteCollaboration(); + } + else + { + Reporter.WriteWarningNoNewLine("Are you sure you want to delete this collaboration? y/N "); + var yNKey = "n"; + yNKey = Console.ReadLine().ToLower(); + if (yNKey != "y") + { + Reporter.WriteInformation("Aborted collaboration deletion."); + return; + } + else + { + collabDeleted = await this.DeleteCollaboration(); + } + } + if (collabDeleted) { Reporter.WriteSuccess($"Collaboration {this._id.Value} successfully removed"); } @@ -71,12 +71,12 @@ private async Task RunDelete() { Reporter.WriteSuccess($"Couldn't remove collaboration {this._id.Value}"); } - } - - private async Task DeleteCollaboration() - { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); - return await boxClient.CollaborationsManager.RemoveCollaborationAsync(this._id.Value); + } + + private async Task DeleteCollaboration() + { + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + return await boxClient.CollaborationsManager.RemoveCollaborationAsync(this._id.Value); } } } \ No newline at end of file diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationGetCommand.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationGetCommand.cs index 4a506561..342ff63a 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationGetCommand.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationGetCommand.cs @@ -44,7 +44,7 @@ protected async override Task Execute() private async Task RunGet() { base.CheckForValue(this._id.Value, this._app, "A collaboration ID is required for this command."); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var result = await boxClient.CollaborationsManager.GetCollaborationAsync(this._id.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationGetPendingCommand.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationGetPendingCommand.cs index 9baf910e..26df115b 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationGetPendingCommand.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationGetPendingCommand.cs @@ -45,7 +45,7 @@ protected async override Task Execute() private async Task RunGetPending() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var collabs = await boxClient.CollaborationsManager.GetPendingCollaborationAsync(); if (_save.HasValue()) { diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationListCommand.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationListCommand.cs index d1edd381..8d983ac0 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationListCommand.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationListCommand.cs @@ -50,7 +50,7 @@ protected async override Task Execute() private async Task RunList() { base.CheckForValue(this._id.Value, this._app, "An ID is required for this command."); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (_save.HasValue()) { var fileName = $"{base._names.CommandNames.Collaborations}-{base._names.SubCommandNames.List}-{DateTime.Now.ToString(GeneralUtilities.GetDateFormatString())}"; diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationListForGroupCommand.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationListForGroupCommand.cs index cc3cef97..4a9e93e9 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationListForGroupCommand.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationListForGroupCommand.cs @@ -51,8 +51,8 @@ protected async override Task Execute() private async Task RunListGroups() { base.CheckForValue(this._id.Value, this._app, "A group ID is required for this command."); - var BoxCollectionsIterators = base.GetIterators(); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (_save.HasValue()) { BoxCollection collabs; diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationSubCommandBase.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationSubCommandBase.cs index 472fba0b..97460e9d 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationSubCommandBase.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationSubCommandBase.cs @@ -29,9 +29,9 @@ public override void Configure(CommandLineApplication command) base.Configure(command); } - protected async Task ProcessCollaborationsFromFile(string id, string path, BoxType t, string asUser = "", bool json = false) + protected async Task ProcessCollaborationsFromFile(string id, string path, BoxType t, bool json = false) { - var boxClient = base.ConfigureBoxClient(asUser); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); @@ -67,9 +67,27 @@ protected virtual void PrintCollaborations(BoxCollection colla } } - protected virtual string ProcessRoleOptions(Dictionary possibleRoles) + protected virtual string ProcessRoleOptions(CommandOption editor, CommandOption viewer, + CommandOption uploader, CommandOption previewerUploader, CommandOption viewerUploader, + CommandOption coOwner, CommandOption previewer, CommandOption owner = null) { - var result = possibleRoles.First(x => x.Value == true); + bool isOwnerRole = false; + if (owner != null) + { + isOwnerRole = owner.HasValue(); + } + var roles = new Dictionary() + { + {BoxCollaborationRoles.Editor, editor.HasValue()}, + {BoxCollaborationRoles.Viewer, viewer.HasValue()}, + {BoxCollaborationRoles.Uploader, uploader.HasValue()}, + {BoxCollaborationRoles.PreviewerUploader, previewerUploader.HasValue()}, + {BoxCollaborationRoles.ViewerUploader, viewerUploader.HasValue()}, + {BoxCollaborationRoles.CoOwner, coOwner.HasValue()}, + {BoxCollaborationRoles.Owner, isOwnerRole}, + {BoxCollaborationRoles.Previewer, previewer.HasValue()}, + }; + var result = roles.First(x => x.Value == true); return result.Key.ToLower(); } } diff --git a/BoxCLI/Commands/CollaborationSubCommands/CollaborationUpdateCommand.cs b/BoxCLI/Commands/CollaborationSubCommands/CollaborationUpdateCommand.cs index 9e1d2d3b..0fd31d64 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/CollaborationUpdateCommand.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/CollaborationUpdateCommand.cs @@ -74,10 +74,10 @@ private async Task RunUpdate() { json = true; } - await base.ProcessCollaborationsFromFile(_id.Value, _path.Value(), base._t, _asUser.Value(), json: json); + await base.ProcessCollaborationsFromFile(_id.Value, _path.Value(), base._t, json: json); } base.CheckForValue(this._id.Value, this._app, "A collaboration ID is required for this command."); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); string role; if (this._role.HasValue()) { @@ -85,17 +85,10 @@ private async Task RunUpdate() } else { - var roles = new Dictionary() - { - {"editor", this._editor.HasValue()}, - {"viewer", this._viewer.HasValue()}, - {"uploader", this._uploader.HasValue()}, - {"previewer uploader", this._previewerUploader.HasValue()}, - {"viewer uploader", this._viewerUploader.HasValue()}, - {"co-owner", this._coowner.HasValue()}, - {"owner", this._owner.HasValue()}, - }; - role = base.ProcessRoleOptions(roles); + role = base.ProcessRoleOptions(editor: this._editor, viewer: this._viewer, + uploader: this._uploader, previewerUploader: this._previewerUploader, + viewerUploader: this._viewerUploader, coOwner: this._coowner, owner: this._owner, + previewer: this._previewer); } var collabRequest = new BoxCollaborationRequest(); diff --git a/BoxCLI/Commands/CollaborationSubCommands/FilesCollaborationSubCommandFactory.cs b/BoxCLI/Commands/CollaborationSubCommands/FilesCollaborationSubCommandFactory.cs index 2a3790a2..675b9067 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/FilesCollaborationSubCommandFactory.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/FilesCollaborationSubCommandFactory.cs @@ -14,7 +14,7 @@ public FilesCollaborationSubCommandFactory(IBoxPlatformServiceBuilder builder, I public override ISubCommand CreateSubCommand(string commandName) { - if (commandName == base._names.SubCommandNames.List) + if (commandName == base._names.SubCommandNames.List) { return new CollaborationListCommand(_boxPlatformBuilder, _boxHome, _names, BoxType.file); } @@ -26,6 +26,10 @@ public override ISubCommand CreateSubCommand(string commandName) { return new CollaborationUpdateCommand(_boxPlatformBuilder, _boxHome, _names, BoxType.file); } + else if (commandName == base._names.SubCommandNames.Delete) + { + return new CollaborationDeleteCommand(_boxPlatformBuilder, _boxHome, _names, BoxType.enterprise); + } else { throw new Exception("Command not registered."); diff --git a/BoxCLI/Commands/CollaborationSubCommands/FoldersCollaborationSubCommandFactory.cs b/BoxCLI/Commands/CollaborationSubCommands/FoldersCollaborationSubCommandFactory.cs index 4248ebfa..0d3b31a4 100644 --- a/BoxCLI/Commands/CollaborationSubCommands/FoldersCollaborationSubCommandFactory.cs +++ b/BoxCLI/Commands/CollaborationSubCommands/FoldersCollaborationSubCommandFactory.cs @@ -26,6 +26,10 @@ public override ISubCommand CreateSubCommand(string commandName) { return new CollaborationUpdateCommand(_boxPlatformBuilder, _boxHome, _names, BoxType.folder); } + else if (commandName == base._names.SubCommandNames.Delete) + { + return new CollaborationDeleteCommand(_boxPlatformBuilder, _boxHome, _names, BoxType.enterprise); + } else { throw new Exception("Command not registered."); diff --git a/BoxCLI/Commands/CommentSubCommands/CommentCreateCommand.cs b/BoxCLI/Commands/CommentSubCommands/CommentCreateCommand.cs index 34a436eb..c1854705 100644 --- a/BoxCLI/Commands/CommentSubCommands/CommentCreateCommand.cs +++ b/BoxCLI/Commands/CommentSubCommands/CommentCreateCommand.cs @@ -58,7 +58,7 @@ private async Task RunCreate() { throw new Exception("The type must be either file or comment for this command."); } - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var commentCreate = new BoxCommentRequest(); commentCreate.Item = new BoxRequestEntity() { diff --git a/BoxCLI/Commands/CommentSubCommands/CommentDeleteCommand.cs b/BoxCLI/Commands/CommentSubCommands/CommentDeleteCommand.cs index 50dfa1f5..14b2f999 100644 --- a/BoxCLI/Commands/CommentSubCommands/CommentDeleteCommand.cs +++ b/BoxCLI/Commands/CommentSubCommands/CommentDeleteCommand.cs @@ -83,7 +83,7 @@ private async Task RunDelete() private async Task DeleteComment() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); return await boxClient.CommentsManager.DeleteAsync(this._commentId.Value); } } diff --git a/BoxCLI/Commands/CommentSubCommands/CommentGetCommand.cs b/BoxCLI/Commands/CommentSubCommands/CommentGetCommand.cs index 2a4552ff..4b6cddfb 100644 --- a/BoxCLI/Commands/CommentSubCommands/CommentGetCommand.cs +++ b/BoxCLI/Commands/CommentSubCommands/CommentGetCommand.cs @@ -44,7 +44,7 @@ protected async override Task Execute() private async Task RunGet() { base.CheckForValue(this._id.Value, this._app, "A comment ID is required for this call."); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var comment = await boxClient.CommentsManager.GetInformationAsync(this._id.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/CommentSubCommands/CommentListCommand.cs b/BoxCLI/Commands/CommentSubCommands/CommentListCommand.cs index c35e5307..e1831741 100644 --- a/BoxCLI/Commands/CommentSubCommands/CommentListCommand.cs +++ b/BoxCLI/Commands/CommentSubCommands/CommentListCommand.cs @@ -52,8 +52,8 @@ protected async override Task Execute() private async Task RunList() { base.CheckForValue(this._fileId.Value, this._app, "A file ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); - var BoxCollectionsIterators = base.GetIterators(); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); var comments = await boxClient.FilesManager.GetCommentsAsync(this._fileId.Value); if (_save.HasValue()) { diff --git a/BoxCLI/Commands/CommentSubCommands/CommentUpdateCommand.cs b/BoxCLI/Commands/CommentSubCommands/CommentUpdateCommand.cs index 2aaa4c1c..400234a4 100644 --- a/BoxCLI/Commands/CommentSubCommands/CommentUpdateCommand.cs +++ b/BoxCLI/Commands/CommentSubCommands/CommentUpdateCommand.cs @@ -46,7 +46,7 @@ protected async override Task Execute() private async Task RunUpdate() { base.CheckForValue(this._commentId.Value, this._app, "A comment ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var commentUpdate = new BoxCommentRequest(); if (this._message.HasValue()) diff --git a/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentUpdatePrivateKeyPathCommand.cs b/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentUpdatePrivateKeyPathCommand.cs index 0cf64f47..04996de5 100644 --- a/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentUpdatePrivateKeyPathCommand.cs +++ b/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentUpdatePrivateKeyPathCommand.cs @@ -8,6 +8,7 @@ public class ConfigureEnvironmentsUpdatePrivateKeyPathCommand : ConfigureEnviron { private CommandArgument _existingName; private CommandArgument _newPath; + private CommandOption _disableFilePathTranslation; private CommandLineApplication _app; public ConfigureEnvironmentsUpdatePrivateKeyPathCommand(IBoxHome boxHome) : base(boxHome) { @@ -21,6 +22,9 @@ public override void Configure(CommandLineApplication command) "The name of the existing environment to update."); _newPath = command.Argument("newPath", "The new path to your private key file."); + _disableFilePathTranslation = command.Option("--disable-file-path-translation", + "Disable file path translation.", + CommandOptionType.NoValue); command.OnExecute(() => { return this.Execute(); @@ -38,12 +42,13 @@ private void RunUpdate() { base.CheckForValue(this._existingName.Value, this._app, "An existing environment name is required for this command."); base.CheckForValue(this._newPath.Value, this._app, "A new private key path is required for this command."); - var result = base._environments.UpdateEnvironmentFilePath(this._existingName.Value, this._newPath.Value); + var result = base._environments.UpdateEnvironmentFilePath(this._existingName.Value, + this._newPath.Value, ignoreFilePathTranslation: this._disableFilePathTranslation.HasValue()); if (result) { Reporter.WriteSuccess("Successfully updated the private key path."); } - else + else { Reporter.WriteError("Couldn't update the private key path."); } diff --git a/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsAddCommand.cs b/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsAddCommand.cs index 51f06d1f..0a973539 100644 --- a/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsAddCommand.cs +++ b/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsAddCommand.cs @@ -11,6 +11,7 @@ public class ConfigureEnvironmentsAddCommand : ConfigureEnvironmentsSubCommandBa private CommandOption _environmentName; private CommandOption _pemPath; private CommandOption _setAsCurrent; + private CommandOption _disableFilePathTranslation; private CommandLineApplication _app; public ConfigureEnvironmentsAddCommand(IBoxHome boxHome) : base(boxHome) { @@ -31,6 +32,9 @@ public override void Configure(CommandLineApplication command) _setAsCurrent = command.Option("--set-as-current", "Set this new environment as your current environment.", CommandOptionType.NoValue); + _disableFilePathTranslation = command.Option("--disable-file-path-translation", + "Disable file path translation.", + CommandOptionType.NoValue); command.OnExecute(() => { return this.Execute(); @@ -46,9 +50,9 @@ protected override int Execute() private void SetConfigFile(string filePath, string environmentName) { - if (base._environments.VerifyBoxConfigFile(filePath)) + if (base._environments.VerifyBoxConfigFile(filePath, this._disableFilePathTranslation.HasValue())) { - var env = base._environments.TranslateConfigFileToEnvironment(filePath, this._pemPath.Value()); + var env = base._environments.TranslateConfigFileToEnvironment(filePath, this._pemPath.Value(), this._disableFilePathTranslation.HasValue()); env.Name = environmentName; var set = base._environments.AddNewEnvironment(env); if (set == true) diff --git a/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsUpdateConfigFilePathCommand.cs b/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsUpdateConfigFilePathCommand.cs index dba96119..d597b495 100644 --- a/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsUpdateConfigFilePathCommand.cs +++ b/BoxCLI/Commands/ConfigureSubCommands/ConfigureEnvironmentsSubCommands/ConfigureEnvironmentsUpdateConfigFilePathCommand.cs @@ -9,6 +9,7 @@ public class ConfigureEnvironmentsUpdateConfigFilePathCommand : ConfigureEnviron private CommandArgument _existingName; private CommandArgument _newPath; private CommandOption _pemPath; + private CommandOption _disableFilePathTranslation; private CommandLineApplication _app; public ConfigureEnvironmentsUpdateConfigFilePathCommand(IBoxHome boxHome) : base(boxHome) { @@ -25,6 +26,9 @@ public override void Configure(CommandLineApplication command) _pemPath = command.Option("--private-key-path ", "Provide a path to your application private key.", CommandOptionType.SingleValue); + _disableFilePathTranslation = command.Option("--disable-file-path-translation", + "Disable file path translation.", + CommandOptionType.NoValue); command.OnExecute(() => { return this.Execute(); @@ -42,12 +46,13 @@ private void RunUpdate() { base.CheckForValue(this._existingName.Value, this._app, "An existing environment name is required for this command."); base.CheckForValue(this._newPath.Value, this._app, "A new Box configuration file path is required for this command."); - var result = base._environments.UpdateConfigFilePath(this._existingName.Value, this._newPath.Value, this._pemPath.Value()); + var result = base._environments.UpdateConfigFilePath(this._existingName.Value, this._newPath.Value, + this._pemPath.Value(), ignoreFilePathTranslation: this._disableFilePathTranslation.HasValue()); if (result) { Reporter.WriteSuccess("Successfully updated the Box configuration file path."); } - else + else { Reporter.WriteError("Couldn't update the Box configuration file path."); } diff --git a/BoxCLI/Commands/EventSubCommands/EventGetCommand.cs b/BoxCLI/Commands/EventSubCommands/EventGetCommand.cs index 9665f26d..47db6c92 100644 --- a/BoxCLI/Commands/EventSubCommands/EventGetCommand.cs +++ b/BoxCLI/Commands/EventSubCommands/EventGetCommand.cs @@ -54,8 +54,8 @@ protected async override Task Execute() private async Task RunGet() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); - var BoxCollectionsIterators = base.GetIterators(); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); if (this._enterprise.HasValue()) { var createdBefore = DateTime.Now; diff --git a/BoxCLI/Commands/EventSubCommands/EventPollCommand.cs b/BoxCLI/Commands/EventSubCommands/EventPollCommand.cs index 2e6cc984..e7b528ab 100644 --- a/BoxCLI/Commands/EventSubCommands/EventPollCommand.cs +++ b/BoxCLI/Commands/EventSubCommands/EventPollCommand.cs @@ -38,7 +38,7 @@ private async Task RunPoll() { Reporter.WriteSuccess("Poll started..."); Reporter.WriteInformation("Press Ctrl+C to stop polling."); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._enterprise.HasValue()) { await base.PollEnterpriseEvents(); diff --git a/BoxCLI/Commands/EventSubCommands/EventSubCommandBase.cs b/BoxCLI/Commands/EventSubCommands/EventSubCommandBase.cs index fb169c35..df096d8b 100644 --- a/BoxCLI/Commands/EventSubCommands/EventSubCommandBase.cs +++ b/BoxCLI/Commands/EventSubCommands/EventSubCommandBase.cs @@ -46,7 +46,7 @@ protected virtual void PrintEvent(BoxEnterpriseEvent evt) protected async virtual Task PollEnterpriseEvents() { - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var events = await boxClient.EventsManager.EnterpriseEventsAsync(createdAfter: DateTime.Now.AddMinutes(-15)); foreach (var evt in events.Entries) { @@ -62,7 +62,7 @@ protected async virtual Task PollEnterpriseEvents() protected async virtual Task PollForMoreEnterpriseEvents(string nextStream) { await Task.Delay(60000); - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var moreEvents = await boxClient.EventsManager.EnterpriseEventsAsync(streamPosition: nextStream); foreach (var evt in moreEvents.Entries) { diff --git a/BoxCLI/Commands/FileSubCommand/FileDeleteCommand.cs b/BoxCLI/Commands/FileSubCommand/FileDeleteCommand.cs index 5c441f55..f52ae687 100644 --- a/BoxCLI/Commands/FileSubCommand/FileDeleteCommand.cs +++ b/BoxCLI/Commands/FileSubCommand/FileDeleteCommand.cs @@ -80,7 +80,7 @@ private async Task RunDelete() private async Task DeleteFile() { var fileDeleted = false; - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._force.HasValue()) { fileDeleted = await boxClient.FilesManager.DeleteAsync(this._fileId.Value, this._etag.Value()); diff --git a/BoxCLI/Commands/FileSubCommand/FileDownloadCommand.cs b/BoxCLI/Commands/FileSubCommand/FileDownloadCommand.cs index bfa42eb7..94521c24 100644 --- a/BoxCLI/Commands/FileSubCommand/FileDownloadCommand.cs +++ b/BoxCLI/Commands/FileSubCommand/FileDownloadCommand.cs @@ -49,7 +49,7 @@ private async Task RunDownload() { if(this._bulkPath.HasValue()) { - await base.ProcessBulkDownload(this._bulkPath.Value(), this._asUser.Value()); + await base.ProcessBulkDownload(this._bulkPath.Value()); return; } if (this._multiId.HasValue()) diff --git a/BoxCLI/Commands/FileSubCommand/FileGetCommand.cs b/BoxCLI/Commands/FileSubCommand/FileGetCommand.cs index 96713d9a..e9a5783c 100644 --- a/BoxCLI/Commands/FileSubCommand/FileGetCommand.cs +++ b/BoxCLI/Commands/FileSubCommand/FileGetCommand.cs @@ -40,7 +40,7 @@ protected async override Task Execute() private async Task RunGet() { base.CheckForFileId(this._fileId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var fileInfo = await boxClient.FilesManager.GetInformationAsync(this._fileId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/FileSubCommand/FileLockCommand.cs b/BoxCLI/Commands/FileSubCommand/FileLockCommand.cs index 0b0d8c86..72a93421 100644 --- a/BoxCLI/Commands/FileSubCommand/FileLockCommand.cs +++ b/BoxCLI/Commands/FileSubCommand/FileLockCommand.cs @@ -50,7 +50,7 @@ protected async override Task Execute() private async Task RunLock() { base.CheckForFileId(this._fileId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var lockRequest = new BoxFileLockRequest(); var boxLock = new BoxFileLock(); if (this._preventDownload.HasValue()) diff --git a/BoxCLI/Commands/FileSubCommand/FileRenameCommand.cs b/BoxCLI/Commands/FileSubCommand/FileRenameCommand.cs index 406f5a53..0771e3b5 100644 --- a/BoxCLI/Commands/FileSubCommand/FileRenameCommand.cs +++ b/BoxCLI/Commands/FileSubCommand/FileRenameCommand.cs @@ -49,7 +49,7 @@ protected async override Task Execute() private async Task RunRename() { base.CheckForFileId(this._fileId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var fileRequest = base.ConfigureFileRequest(this._fileId.Value, fileName: this._fileName.Value, description: this._description.Value()); BoxFile renamedFile; if (this._etag.HasValue()) diff --git a/BoxCLI/Commands/FileSubCommand/FileSubCommandBase.cs b/BoxCLI/Commands/FileSubCommand/FileSubCommandBase.cs index 9107536e..bbb2f85c 100644 --- a/BoxCLI/Commands/FileSubCommand/FileSubCommandBase.cs +++ b/BoxCLI/Commands/FileSubCommand/FileSubCommandBase.cs @@ -60,7 +60,7 @@ protected void CheckForParentFolderId(string id, CommandLineApplication app) protected async Task MoveFile(string fileId, string parentId, string etag = "") { - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var fileRequest = this.ConfigureFileRequest(fileId, parentId); if (!string.IsNullOrEmpty(etag)) { @@ -74,14 +74,14 @@ protected async Task MoveFile(string fileId, string parentId, string et protected async Task CopyFile(string fileId, string parentId, string fileVersionId = "") { - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var fileRequest = this.ConfigureFileRequest(fileId, parentId); return await boxClient.FilesManager.CopyAsync(fileRequest); } protected async Task DownloadFile(string fileId, string fileVersionId = "") { - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var fileInfo = await boxClient.FilesManager.GetInformationAsync(fileId); Stream boxFileStream; if (!string.IsNullOrEmpty(fileVersionId)) diff --git a/BoxCLI/Commands/FileSubCommand/FileUnlockCommand.cs b/BoxCLI/Commands/FileSubCommand/FileUnlockCommand.cs index ef130db4..cbd00f3d 100644 --- a/BoxCLI/Commands/FileSubCommand/FileUnlockCommand.cs +++ b/BoxCLI/Commands/FileSubCommand/FileUnlockCommand.cs @@ -38,7 +38,7 @@ protected async override Task Execute() private async Task RunUnlock() { base.CheckForFileId(this._fileId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var unlocked = await boxClient.FilesManager.UnLock(this._fileId.Value); if(unlocked) { diff --git a/BoxCLI/Commands/FileSubCommand/FileUpdateCommand.cs b/BoxCLI/Commands/FileSubCommand/FileUpdateCommand.cs index 83c92433..e9a840af 100644 --- a/BoxCLI/Commands/FileSubCommand/FileUpdateCommand.cs +++ b/BoxCLI/Commands/FileSubCommand/FileUpdateCommand.cs @@ -50,7 +50,7 @@ protected async override Task Execute() private async Task RunUpdate() { base.CheckForFileId(this._fileId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var fileRequest = base.ConfigureFileRequest(this._fileId.Value, fileName: this._fileName.Value(), description: this._description.Value()); BoxFile updatedFile; if (this._etag.HasValue()) diff --git a/BoxCLI/Commands/FileSubCommand/FileUpdateLockCommand.cs b/BoxCLI/Commands/FileSubCommand/FileUpdateLockCommand.cs index 425a7bfc..06b845a9 100644 --- a/BoxCLI/Commands/FileSubCommand/FileUpdateLockCommand.cs +++ b/BoxCLI/Commands/FileSubCommand/FileUpdateLockCommand.cs @@ -50,7 +50,7 @@ protected async override Task Execute() private async Task RunLock() { base.CheckForFileId(this._fileId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var lockRequest = new BoxFileLockRequest(); var boxLock = new BoxFileLock(); if (this._preventDownload.HasValue()) diff --git a/BoxCLI/Commands/FileVersionSubCommands/FileVersionDeleteCommand.cs b/BoxCLI/Commands/FileVersionSubCommands/FileVersionDeleteCommand.cs index 4fa12107..88853a86 100644 --- a/BoxCLI/Commands/FileVersionSubCommands/FileVersionDeleteCommand.cs +++ b/BoxCLI/Commands/FileVersionSubCommands/FileVersionDeleteCommand.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using BoxCLI.BoxHome; using BoxCLI.BoxPlatform.Service; @@ -82,7 +82,7 @@ private async Task RunDelete() private async Task DeleteFileVersion() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._etag.HasValue()) { return await boxClient.FilesManager.DeleteOldVersionAsync(this._fileId.Value, this._fileVersionId.Value, this._etag.Value()); diff --git a/BoxCLI/Commands/FileVersionSubCommands/FileVersionListCommand.cs b/BoxCLI/Commands/FileVersionSubCommands/FileVersionListCommand.cs index 0bdebb78..03b15035 100644 --- a/BoxCLI/Commands/FileVersionSubCommands/FileVersionListCommand.cs +++ b/BoxCLI/Commands/FileVersionSubCommands/FileVersionListCommand.cs @@ -40,7 +40,7 @@ protected async override Task Execute() private async Task RunList() { base.CheckForFileId(this._fileId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var fileVersions = await boxClient.FilesManager.ViewVersionsAsync(this._fileId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/FileVersionSubCommands/FileVersionPromoteCommand.cs b/BoxCLI/Commands/FileVersionSubCommands/FileVersionPromoteCommand.cs index 1e12af12..c31eb423 100644 --- a/BoxCLI/Commands/FileVersionSubCommands/FileVersionPromoteCommand.cs +++ b/BoxCLI/Commands/FileVersionSubCommands/FileVersionPromoteCommand.cs @@ -44,7 +44,7 @@ private async Task RunPromote() { base.CheckForFileId(this._fileId.Value, this._app); base.CheckForFileVersionId(this._fileVersionId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var promotedFile = await boxClient.FilesManager.PromoteVersionAsync(this._fileId.Value, this._fileVersionId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/FolderSubCommands/FolderChangeUploadEmailCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderChangeUploadEmailCommand.cs index 6db121d0..f5fd3bea 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderChangeUploadEmailCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderChangeUploadEmailCommand.cs @@ -46,7 +46,7 @@ protected async override Task Execute() private async Task RunChange() { base.CheckForId(this._folderId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var email = new BoxFolderRequest() { Id = this._folderId.Value, diff --git a/BoxCLI/Commands/FolderSubCommands/FolderCreateCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderCreateCommand.cs index 8e5f245a..af357479 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderCreateCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderCreateCommand.cs @@ -62,12 +62,12 @@ protected async Task RunCreate() { json = true; } - await this.CreateFoldersFromFile(this._bulkPath.Value(), base._asUser.Value(), this._save.HasValue(), + await this.CreateFoldersFromFile(this._bulkPath.Value(), this._save.HasValue(), this._filePath.Value(), this._fileFormat.Value(), json: json); return; } base.CheckForParentId(this._parentFolderId.Value, this._app); - var BoxClient = base.ConfigureBoxClient(base._asUser.Value()); + var BoxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var folderRequest = new BoxFolderRequest(); folderRequest.Parent = new BoxItemRequest(); folderRequest.Parent.Id = this._parentFolderId.Value; diff --git a/BoxCLI/Commands/FolderSubCommands/FolderDeleteCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderDeleteCommand.cs index 918a67c3..352a9d24 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderDeleteCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderDeleteCommand.cs @@ -83,7 +83,7 @@ protected async Task RunDelete() private async Task DeleteFolder() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var folderDeleted = await boxClient.FoldersManager.DeleteAsync(this._folderId.Value, this._recursive.HasValue(), this._etag.Value()); if (this._force.HasValue()) { diff --git a/BoxCLI/Commands/FolderSubCommands/FolderDownloadCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderDownloadCommand.cs index 25845b47..c55380a4 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderDownloadCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderDownloadCommand.cs @@ -54,7 +54,7 @@ private async Task RunDownload() await base.ProcessFolderBulkDownload(this._bulkPath.Value(), this._asUser.Value(), fileName); return; } - var BoxClient = base.ConfigureBoxClient(base._asUser.Value()); + var BoxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._multiId.HasValue()) { var ids = this._folderId.Value; diff --git a/BoxCLI/Commands/FolderSubCommands/FolderGetCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderGetCommand.cs index 1312c096..f20fa9da 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderGetCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderGetCommand.cs @@ -42,7 +42,7 @@ protected async override Task Execute() protected async Task RunGet() { base.CheckForId(this._folderId.Value, this._app); - var BoxClient = base.ConfigureBoxClient(base._asUser.Value()); + var BoxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var folder = await BoxClient.FoldersManager.GetInformationAsync(this._folderId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/FolderSubCommands/FolderListItemsCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderListItemsCommand.cs index 0a5fe386..cd4ec5ef 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderListItemsCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderListItemsCommand.cs @@ -52,7 +52,7 @@ protected async override Task Execute() protected async Task RunGetItems() { base.CheckForId(this._folderId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._save.HasValue()) { Reporter.WriteInformation("Saving file..."); @@ -79,7 +79,7 @@ protected async Task RunGetItems() base.OutputJson(result); return; } - var BoxCollectionsIterators = base.GetIterators(); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); await BoxCollectionsIterators.ListOffsetCollectionToConsole((offset) => { return boxClient.FoldersManager.GetFolderItemsAsync(this._folderId.Value, 1000, offset: (int)offset); diff --git a/BoxCLI/Commands/FolderSubCommands/FolderRenameCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderRenameCommand.cs index 9253cdba..be731a2a 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderRenameCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderRenameCommand.cs @@ -52,7 +52,7 @@ protected async Task RunRename() { base.CheckForId(this._folderId.Value, this._app); base.CheckForValue(this._folderName.Value, _app, "A name value is required to rename a folder."); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var folderRenameRequest = new BoxFolderRequest() { Name = this._folderName.Value, diff --git a/BoxCLI/Commands/FolderSubCommands/FolderSubCommandBase.cs b/BoxCLI/Commands/FolderSubCommands/FolderSubCommandBase.cs index d788f427..127dc9d4 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderSubCommandBase.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderSubCommandBase.cs @@ -53,7 +53,7 @@ public override void Configure(CommandLineApplication command) protected async virtual Task MoveFolder(string folderId, string parentFolderId, string etag = "") { - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var folderRequest = new BoxFolderRequest() { Id = folderId, @@ -66,7 +66,7 @@ protected async virtual Task MoveFolder(string folderId, string paren } protected async virtual Task CopyFolder(string folderId, string parentFolderId, string name = "") { - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var folderRequest = new BoxFolderRequest() { Id = folderId, @@ -95,10 +95,10 @@ protected async virtual Task UploadFolder(string path, string folderId) await Task.WhenAll(taskList); } - protected async virtual Task CreateFoldersFromFile(string path, string asUser = "", + protected async virtual Task CreateFoldersFromFile(string path, bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { - var boxClient = base.ConfigureBoxClient(asUser); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); @@ -151,10 +151,10 @@ protected async virtual Task CreateFoldersFromFile(string path, string asUser = } } - protected async virtual Task UpdateFoldersFromFile(string path, string asUser = "", + protected async virtual Task UpdateFoldersFromFile(string path, bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { - var boxClient = base.ConfigureBoxClient(asUser); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); diff --git a/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs index 3f8e98f4..d815636b 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderUpdateCommand.cs @@ -90,12 +90,12 @@ private async Task RunUpdate() { json = true; } - await this.UpdateFoldersFromFile(this._bulkFilePath.Value(), base._asUser.Value(), this._save.HasValue(), + await this.UpdateFoldersFromFile(this._bulkFilePath.Value(), this._save.HasValue(), this._filePath.Value(), this._fileFormat.Value(), json: json); return; } base.CheckForId(this._folderId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var folderUpdateRequest = new BoxFolderRequest(); folderUpdateRequest.Id = this._folderId.Value; if (this._parentFolderId.HasValue()) diff --git a/BoxCLI/Commands/FolderSubCommands/FolderUploadCommand.cs b/BoxCLI/Commands/FolderSubCommands/FolderUploadCommand.cs index 9cca0c7c..1c234d22 100644 --- a/BoxCLI/Commands/FolderSubCommands/FolderUploadCommand.cs +++ b/BoxCLI/Commands/FolderSubCommands/FolderUploadCommand.cs @@ -63,7 +63,7 @@ protected async Task RunUpload() // return; // } base.CheckForValue(this._folderPath.Value, _app, "A path to a local folder is required"); - var BoxClient = base.ConfigureBoxClient(base._asUser.Value()); + var BoxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); string name; if (this._alternativeFolderName.HasValue()) { diff --git a/BoxCLI/Commands/GroupSubCommands/GroupCreateCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupCreateCommand.cs index f9778209..2fe65b01 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupCreateCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupCreateCommand.cs @@ -64,11 +64,11 @@ private async Task RunCreate() { json = true; } - await base.CreateGroupsFromFile(this._bulkPath.Value(), this._asUser.Value(), this._save.HasValue(), json: json); + await base.CreateGroupsFromFile(this._bulkPath.Value(), this._save.HasValue(), json: json); return; } base.CheckForValue(this._name.Value, this._app, "A group name is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var groupRequest = new BoxGroupRequest(); groupRequest.Name = this._name.Value; if (this._inviteLevel.HasValue()) diff --git a/BoxCLI/Commands/GroupSubCommands/GroupDeleteCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupDeleteCommand.cs index 093174b5..31c636da 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupDeleteCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupDeleteCommand.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using BoxCLI.BoxHome; using BoxCLI.BoxPlatform.Service; @@ -74,7 +74,7 @@ private async Task RunDelete() private async Task DeleteGroup() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); return await boxClient.GroupsManager.DeleteAsync(this._groupId.Value); } } diff --git a/BoxCLI/Commands/GroupSubCommands/GroupGetCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupGetCommand.cs index b15dd0f5..e76c0a96 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupGetCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupGetCommand.cs @@ -41,7 +41,7 @@ protected async override Task Execute() private async Task RunGet() { base.CheckForValue(this._groupId.Value, this._app, "A group ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var group = await boxClient.GroupsManager.GetGroupAsync(_groupId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/GroupSubCommands/GroupListCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupListCommand.cs index d22935b5..8e0b5b24 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupListCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupListCommand.cs @@ -47,7 +47,7 @@ protected async override Task Execute() private async Task RunList() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (_save.HasValue()) { var fileName = $"{base._names.CommandNames.Groups}-{base._names.SubCommandNames.List}-{DateTime.Now.ToString(GeneralUtilities.GetDateFormatString())}"; @@ -63,7 +63,7 @@ private async Task RunList() base.OutputJson(saveGroups); return; } - var BoxCollectionsIterators = base.GetIterators(); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); await BoxCollectionsIterators.ListOffsetCollectionToConsole((offset) => { return boxClient.GroupsManager.GetAllGroupsAsync(limit: 100, offset: (int)offset); diff --git a/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipCreateCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipCreateCommand.cs index 897b70fa..1dd6c129 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipCreateCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipCreateCommand.cs @@ -62,7 +62,7 @@ private async Task RunCreate() { role = "member"; } - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var memberRequest = new BoxGroupMembershipRequest(); memberRequest.Group = new BoxGroupRequest(); memberRequest.Group.Id = this._groupId.Value; diff --git a/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipDeleteCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipDeleteCommand.cs index a229705a..cd58161f 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipDeleteCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipDeleteCommand.cs @@ -39,7 +39,7 @@ protected async override Task Execute() private async Task RunDelete() { base.CheckForValue(this._membershipId.Value, this._app, "A group memebership ID is required for this command."); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var result = await boxClient.GroupsManager.DeleteGroupMembershipAsync(this._membershipId.Value); if(result) { diff --git a/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipGetCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipGetCommand.cs index 8a533317..1bc7c193 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipGetCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipGetCommand.cs @@ -41,7 +41,7 @@ protected async override Task Execute() private async Task RunGet() { base.CheckForValue(this._membershipId.Value, this._app, "A group memebership ID is required for this command."); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var membership = await boxClient.GroupsManager.GetGroupMembershipAsync(_membershipId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipListCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipListCommand.cs index 7b52a504..6161626d 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipListCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipListCommand.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; using Box.V2.Models; using BoxCLI.BoxHome; @@ -51,9 +52,9 @@ protected async override Task Execute() private async Task RunList() { base.CheckForValue(this._id.Value, this._app, "A group ID or user ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); - var BoxCollectionsIterators = base.GetIterators(); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); if (this._listGroups.HasValue()) { if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) diff --git a/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipUpdateCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipUpdateCommand.cs index 234da276..6a961258 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipUpdateCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupMembershipSubCommands/GroupMembershipUpdateCommand.cs @@ -60,7 +60,7 @@ private async Task RunCreate() { role = "member"; } - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var memberRequest = new BoxGroupMembershipRequest(); if (!string.IsNullOrEmpty(role)) { diff --git a/BoxCLI/Commands/GroupSubCommands/GroupSubCommandBase.cs b/BoxCLI/Commands/GroupSubCommands/GroupSubCommandBase.cs index 046188e7..38c09d67 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupSubCommandBase.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupSubCommandBase.cs @@ -68,10 +68,10 @@ protected virtual void PrintGroup(BoxGroup g) Reporter.WriteInformation($"Name: {g.Name}"); } - protected async Task CreateGroupsFromFile(string path, string asUser = "", + protected async Task CreateGroupsFromFile(string path, bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { - var boxClient = base.ConfigureBoxClient(asUser); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); diff --git a/BoxCLI/Commands/GroupSubCommands/GroupUpdateCommand.cs b/BoxCLI/Commands/GroupSubCommands/GroupUpdateCommand.cs index 26605dd7..9cbd4f8c 100644 --- a/BoxCLI/Commands/GroupSubCommands/GroupUpdateCommand.cs +++ b/BoxCLI/Commands/GroupSubCommands/GroupUpdateCommand.cs @@ -49,7 +49,7 @@ protected async override Task Execute() private async Task RunUpdate() { base.CheckForValue(this._id.Value, this._app, "A group ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var groupRequest = new BoxGroupRequest(); if (this._name.HasValue()) { diff --git a/BoxCLI/Commands/MetadataSubCommands/MetadataCreateCommand.cs b/BoxCLI/Commands/MetadataSubCommands/MetadataCreateCommand.cs index 4cd5ff26..77b4b0fa 100644 --- a/BoxCLI/Commands/MetadataSubCommands/MetadataCreateCommand.cs +++ b/BoxCLI/Commands/MetadataSubCommands/MetadataCreateCommand.cs @@ -68,7 +68,7 @@ private async Task RunCreate() base.CheckForId(this._id.Value, this._app); base.CheckForScope(this._scope.Value, this._app); base.CheckForTemplate(this._template.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); Dictionary metadata; if (this._keyVal.HasValue()) { diff --git a/BoxCLI/Commands/MetadataSubCommands/MetadataGetAllCommand.cs b/BoxCLI/Commands/MetadataSubCommands/MetadataGetAllCommand.cs index 5f7938e0..6beca2b5 100644 --- a/BoxCLI/Commands/MetadataSubCommands/MetadataGetAllCommand.cs +++ b/BoxCLI/Commands/MetadataSubCommands/MetadataGetAllCommand.cs @@ -49,7 +49,7 @@ protected async override Task Execute() private async Task RunGetAll() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._save.HasValue()) { var fileName = $"{base._names.CommandNames.Metadata}-{base._names.SubCommandNames.GetAll}-{DateTime.Now.ToString(GeneralUtilities.GetDateFormatString())}"; diff --git a/BoxCLI/Commands/MetadataSubCommands/MetadataGetCommand.cs b/BoxCLI/Commands/MetadataSubCommands/MetadataGetCommand.cs index b3f91bd6..901fcc6d 100644 --- a/BoxCLI/Commands/MetadataSubCommands/MetadataGetCommand.cs +++ b/BoxCLI/Commands/MetadataSubCommands/MetadataGetCommand.cs @@ -51,7 +51,7 @@ private async Task RunGet() base.CheckForId(this._id.Value, this._app); base.CheckForScope(this._scope.Value, this._app); base.CheckForTemplate(this._template.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); Dictionary metadata; if (base._t == BoxType.file) { diff --git a/BoxCLI/Commands/MetadataSubCommands/MetadataSubCommandBase.cs b/BoxCLI/Commands/MetadataSubCommands/MetadataSubCommandBase.cs index 2f6d3f78..87effda0 100644 --- a/BoxCLI/Commands/MetadataSubCommands/MetadataSubCommandBase.cs +++ b/BoxCLI/Commands/MetadataSubCommands/MetadataSubCommandBase.cs @@ -134,10 +134,10 @@ protected virtual List ReadMetadataCsvFile(string filePath) return allMetadataOnItem; } - protected async virtual Task AddMetadataToItemFromFile(string path, string asUser = "", string type = "", + protected async virtual Task AddMetadataToItemFromFile(string path, string type = "", bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { - var boxClient = base.ConfigureBoxClient(asUser); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); diff --git a/BoxCLI/Commands/MetadataSubCommands/MetadataUpdateCommand.cs b/BoxCLI/Commands/MetadataSubCommands/MetadataUpdateCommand.cs index 45592c54..7e7082a2 100644 --- a/BoxCLI/Commands/MetadataSubCommands/MetadataUpdateCommand.cs +++ b/BoxCLI/Commands/MetadataSubCommands/MetadataUpdateCommand.cs @@ -70,7 +70,7 @@ private async Task RunUpdate() base.CheckForId(this._id.Value, this._app); base.CheckForScope(this._scope.Value, this._app); base.CheckForTemplate(this._template.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var updates = ProcessMetadataUpdate(); Dictionary metadata; if (base._t == BoxType.file) diff --git a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateCreateCommand.cs b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateCreateCommand.cs index 5ea91c12..84fa6ca2 100644 --- a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateCreateCommand.cs +++ b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateCreateCommand.cs @@ -78,7 +78,7 @@ private async Task RunCreate() } base.CheckForScope(this._scope.Value, this._app); base.CheckForName(this._name.Value, this._app); - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var template = new BoxMetadataTemplate(); template.Scope = this._scope.Value; template.DisplayName = this._name.Value; diff --git a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateGetCommand.cs b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateGetCommand.cs index 6c0fd0b6..751b4561 100644 --- a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateGetCommand.cs +++ b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateGetCommand.cs @@ -46,7 +46,7 @@ private async Task RunGet() { base.CheckForScope(this._scope.Value, this._app); base.CheckForTemplate(this._template.Value, this._app); - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var template = await boxClient.MetadataManager.GetMetadataTemplate(this._scope.Value, this._template.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateListCommand.cs b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateListCommand.cs index ef2d6491..b30ee7cb 100644 --- a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateListCommand.cs +++ b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateListCommand.cs @@ -50,7 +50,7 @@ protected async override Task Execute() private async Task RunList() { - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._save.HasValue()) { var dateString = DateTime.Now.ToString(GeneralUtilities.GetDateFormatString()); diff --git a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateSubCommandBase.cs b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateSubCommandBase.cs index 8e79c581..63c573d7 100644 --- a/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateSubCommandBase.cs +++ b/BoxCLI/Commands/MetadataTemplateSubCommands/MetadataTemplateSubCommandBase.cs @@ -9,6 +9,7 @@ using BoxCLI.BoxPlatform.Service; using BoxCLI.CommandUtilities; using BoxCLI.CommandUtilities.CommandModels; +using BoxCLI.CommandUtilities.CommandOptions; using BoxCLI.CommandUtilities.CsvModels; using BoxCLI.CommandUtilities.Globalization; using CsvHelper; @@ -18,11 +19,21 @@ namespace BoxCLI.Commands.MetadataTemplateSubCommands { public class MetadataTemplateSubCommandBase : BoxBaseCommand { + private CommandLineApplication _app; + protected CommandOption _asUser; + public MetadataTemplateSubCommandBase(IBoxPlatformServiceBuilder boxPlatformBuilder, IBoxHome boxHome, LocalizedStringsResource names) : base(boxPlatformBuilder, boxHome, names) { } + public override void Configure(CommandLineApplication command) + { + _app = command; + _asUser = AsUserOption.ConfigureOption(command); + base.Configure(command); + } + protected virtual void CheckForScope(string scope, CommandLineApplication app) { if (string.IsNullOrEmpty(scope)) @@ -205,7 +216,7 @@ protected virtual List ReadMetadataTemplateCsvFile(string f protected async virtual Task CreateMetadataTemplatesFromFile(string filePath, string filePathFields = "", bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (!string.IsNullOrEmpty(filePath)) { filePath = GeneralUtilities.TranslatePath(filePath); diff --git a/BoxCLI/Commands/SearchCommand.cs b/BoxCLI/Commands/SearchCommand.cs index ac22558e..203bb2c4 100644 --- a/BoxCLI/Commands/SearchCommand.cs +++ b/BoxCLI/Commands/SearchCommand.cs @@ -166,7 +166,7 @@ protected async override Task Execute() mdFilters.Add(mdRequest); } } - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); BoxCollection result; if (mdFilters.Count() > 0) { diff --git a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkCreateCommand.cs b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkCreateCommand.cs index 9c27539c..d4b70867 100644 --- a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkCreateCommand.cs +++ b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkCreateCommand.cs @@ -66,7 +66,7 @@ private async Task RunCreate() { json = true; } - await base.ProcessSharedLinksFromFile(_id.Value, _path.Value(), base._t, _asUser.Value(), json: json); + await base.ProcessSharedLinksFromFile(_id.Value, _path.Value(), base._t, json: json); return; } base.CheckForId(this._id.Value, this._app); @@ -78,7 +78,7 @@ private async Task RunCreate() throw new Exception("You must provide an item type for this command: choose file or folder"); } } - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var sharedLinkRequest = new BoxSharedLinkRequest(); if (this._access.HasValue()) { diff --git a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkDeleteCommand.cs b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkDeleteCommand.cs index 8f8b9352..25708916 100644 --- a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkDeleteCommand.cs +++ b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkDeleteCommand.cs @@ -61,7 +61,7 @@ private async Task RunDelete() throw new Exception("You must provide an item type for this command: choose file or folder"); } } - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (base._t == BoxType.file || (this._type != null && this._type.Value == SharedLinkSubCommandBase.BOX_FILE)) { BoxFile sharedLinkDeleted; diff --git a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkGetCommand.cs b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkGetCommand.cs index 07cfd80c..a3c7e472 100644 --- a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkGetCommand.cs +++ b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkGetCommand.cs @@ -56,7 +56,7 @@ protected async override Task Execute() private async Task RunGet() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var fields = new List() { "shared_link" diff --git a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkSubCommandBase.cs b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkSubCommandBase.cs index 138f076b..0ec649c4 100644 --- a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkSubCommandBase.cs +++ b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkSubCommandBase.cs @@ -29,9 +29,9 @@ public override void Configure(CommandLineApplication command) base.Configure(command); } - protected async Task ProcessSharedLinksFromFile(string id, string path, BoxType t, string asUser = "", bool json = false) + protected async Task ProcessSharedLinksFromFile(string id, string path, BoxType t, bool json = false) { - var boxClient = base.ConfigureBoxClient(asUser); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); diff --git a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkUpdateCommand.cs b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkUpdateCommand.cs index 67aa8441..49a81d9b 100644 --- a/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkUpdateCommand.cs +++ b/BoxCLI/Commands/SharedLinkSubCommands/SharedLinkUpdateCommand.cs @@ -64,7 +64,7 @@ private async Task RunUpdate() throw new Exception("You must provide an item type for this command: choose file or folder"); } } - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (base._t == BoxType.file || (this._type != null && this._type.Value == SharedLinkSubCommandBase.BOX_FILE)) { var fileRequest = new BoxFileRequest(); diff --git a/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentCreateCommand.cs b/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentCreateCommand.cs index ca90a061..a351faba 100644 --- a/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentCreateCommand.cs +++ b/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentCreateCommand.cs @@ -54,7 +54,7 @@ private async Task RunCreate() Reporter.WriteError("You must include a user ID or login for this command."); return; } - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var taskAssignmentCreate = new BoxTaskAssignmentRequest(); taskAssignmentCreate.Task = new BoxTaskRequest(); taskAssignmentCreate.Task.Id = this._taskId.Value; diff --git a/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentDeleteCommand.cs b/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentDeleteCommand.cs index 68fd0d26..1d2a64b0 100644 --- a/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentDeleteCommand.cs +++ b/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentDeleteCommand.cs @@ -40,7 +40,7 @@ protected async override Task Execute() private async Task RunDelete() { base.CheckForValue(this._taskAssignmentId.Value, this._app, "A task assignment ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); bool deleted; try { diff --git a/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentGetCommand.cs b/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentGetCommand.cs index 75824331..471251e6 100644 --- a/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentGetCommand.cs +++ b/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentGetCommand.cs @@ -43,7 +43,7 @@ protected async override Task Execute() private async Task RunGet() { base.CheckForValue(this._taskAssignmentId.Value, this._app, "A task assignment ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var taskAssignment = await boxClient.TasksManager.GetTaskAssignmentAsync(this._taskAssignmentId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentListCommand.cs b/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentListCommand.cs index a2c4d5a3..194af8c0 100644 --- a/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentListCommand.cs +++ b/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentListCommand.cs @@ -52,8 +52,8 @@ protected async override Task Execute() private async Task RunList() { base.CheckForValue(this._taskId.Value, this._app, "A task ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); - var BoxCollectionsIterators = base.GetIterators(); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); var taskAssignments = await boxClient.TasksManager.GetAssignmentsAsync(this._taskId.Value); if (_save.HasValue()) { diff --git a/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentUpdateCommand.cs b/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentUpdateCommand.cs index 859a7810..4764354e 100644 --- a/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentUpdateCommand.cs +++ b/BoxCLI/Commands/TaskAssignmentsSubCommands/TaskAssignmentUpdateCommand.cs @@ -53,7 +53,7 @@ protected async override Task Execute() private async Task RunUpdate() { base.CheckForValue(this._taskAssignmentId.Value, this._app, "A task assignment ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var taskAssignmentUpdate = new BoxTaskAssignmentUpdateRequest(); taskAssignmentUpdate.Id = this._taskAssignmentId.Value; if (this._completed.HasValue()) diff --git a/BoxCLI/Commands/TaskSubCommands/TaskCreateCommand.cs b/BoxCLI/Commands/TaskSubCommands/TaskCreateCommand.cs index 2e52d5e2..a56badb6 100644 --- a/BoxCLI/Commands/TaskSubCommands/TaskCreateCommand.cs +++ b/BoxCLI/Commands/TaskSubCommands/TaskCreateCommand.cs @@ -50,7 +50,7 @@ protected async override Task Execute() private async Task RunCreate() { base.CheckForValue(this._fileId.Value, this._app, "A file ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var taskRequest = new BoxTaskCreateRequest(); taskRequest.Item = new BoxRequestEntity() { diff --git a/BoxCLI/Commands/TaskSubCommands/TaskDeleteCommand.cs b/BoxCLI/Commands/TaskSubCommands/TaskDeleteCommand.cs index 1c82ed2c..2d121a56 100644 --- a/BoxCLI/Commands/TaskSubCommands/TaskDeleteCommand.cs +++ b/BoxCLI/Commands/TaskSubCommands/TaskDeleteCommand.cs @@ -42,7 +42,7 @@ protected async override Task Execute() private async Task RunDelete() { base.CheckForValue(this._taskId.Value, this._app, "A task ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); bool deleted; try { diff --git a/BoxCLI/Commands/TaskSubCommands/TaskGetCommand.cs b/BoxCLI/Commands/TaskSubCommands/TaskGetCommand.cs index c944100b..0ed08857 100644 --- a/BoxCLI/Commands/TaskSubCommands/TaskGetCommand.cs +++ b/BoxCLI/Commands/TaskSubCommands/TaskGetCommand.cs @@ -42,7 +42,7 @@ protected async override Task Execute() private async Task RunGet() { base.CheckForValue(this._taskId.Value, this._app, "A task ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var task = await boxClient.TasksManager.GetTaskAsync(this._taskId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { diff --git a/BoxCLI/Commands/TaskSubCommands/TaskListCommand.cs b/BoxCLI/Commands/TaskSubCommands/TaskListCommand.cs index 104f7669..0a13a11d 100644 --- a/BoxCLI/Commands/TaskSubCommands/TaskListCommand.cs +++ b/BoxCLI/Commands/TaskSubCommands/TaskListCommand.cs @@ -52,8 +52,8 @@ protected async override Task Execute() public async Task RunList() { base.CheckForId(this._fileId.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); - var BoxCollectionsIterators = base.GetIterators(); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); var tasks = await boxClient.FilesManager.GetFileTasks(this._fileId.Value); if (_save.HasValue()) { diff --git a/BoxCLI/Commands/TaskSubCommands/TaskUpdateCommand.cs b/BoxCLI/Commands/TaskSubCommands/TaskUpdateCommand.cs index 5271eac9..232cd99c 100644 --- a/BoxCLI/Commands/TaskSubCommands/TaskUpdateCommand.cs +++ b/BoxCLI/Commands/TaskSubCommands/TaskUpdateCommand.cs @@ -47,7 +47,7 @@ protected async override Task Execute() private async Task RunUpdate() { base.CheckForValue(this._taskId.Value, this._app, "A task ID is required for this command"); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var taskRequest = new BoxTaskUpdateRequest(); if (this._message.HasValue()) { diff --git a/BoxCLI/Commands/TrashSubCommands/TrashDeleteCommand.cs b/BoxCLI/Commands/TrashSubCommands/TrashDeleteCommand.cs index 1eb73dfd..6eedf5ad 100644 --- a/BoxCLI/Commands/TrashSubCommands/TrashDeleteCommand.cs +++ b/BoxCLI/Commands/TrashSubCommands/TrashDeleteCommand.cs @@ -79,7 +79,7 @@ private async Task RunDelete() private async Task DeleteItem() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._type.Value == base._names.CommandNames.Files) { return await boxClient.FilesManager.PurgeTrashedAsync(this._itemId.Value); diff --git a/BoxCLI/Commands/TrashSubCommands/TrashGetCommand.cs b/BoxCLI/Commands/TrashSubCommands/TrashGetCommand.cs index 7fda1a16..ae9a63d0 100644 --- a/BoxCLI/Commands/TrashSubCommands/TrashGetCommand.cs +++ b/BoxCLI/Commands/TrashSubCommands/TrashGetCommand.cs @@ -45,7 +45,7 @@ private async Task RunGet() { base.CheckForId(this._itemId.Value, this._app); base.CheckForType(this._type.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._type.Value == base._names.CommandNames.Files) { var item = await boxClient.FilesManager.GetTrashedAsync(this._itemId.Value); diff --git a/BoxCLI/Commands/TrashSubCommands/TrashListCommand.cs b/BoxCLI/Commands/TrashSubCommands/TrashListCommand.cs index 1b23a1c2..d14c5540 100644 --- a/BoxCLI/Commands/TrashSubCommands/TrashListCommand.cs +++ b/BoxCLI/Commands/TrashSubCommands/TrashListCommand.cs @@ -47,8 +47,8 @@ protected async override Task Execute() public async Task RunList() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); - var BoxCollectionsIterators = base.GetIterators(); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { var items = boxClient.FoldersManager.GetTrashItemsAsync(limit: 1000, autoPaginate: true); diff --git a/BoxCLI/Commands/TrashSubCommands/TrashRestoreCommand.cs b/BoxCLI/Commands/TrashSubCommands/TrashRestoreCommand.cs index 3cb63a4f..0bd5f28f 100644 --- a/BoxCLI/Commands/TrashSubCommands/TrashRestoreCommand.cs +++ b/BoxCLI/Commands/TrashSubCommands/TrashRestoreCommand.cs @@ -45,7 +45,7 @@ private async Task RunRestore() { base.CheckForId(this._itemId.Value, this._app); base.CheckForType(this._type.Value, this._app); - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._type.Value == base._names.CommandNames.Files) { var item = await boxClient.FilesManager.RestoreTrashedAsync(new BoxFileRequest() { Id = this._itemId.Value }); diff --git a/BoxCLI/Commands/UserSubCommands/UserAddEmailAliasCommand.cs b/BoxCLI/Commands/UserSubCommands/UserAddEmailAliasCommand.cs index 9a054e6e..77b265e2 100644 --- a/BoxCLI/Commands/UserSubCommands/UserAddEmailAliasCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserAddEmailAliasCommand.cs @@ -46,7 +46,7 @@ private async Task RunAddEmailAlias() { base.CheckForValue(this._userEmail.Value, this._app, "A user email is required for this command"); base.CheckForId(this._userId.Value, this._app); - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var alias = await boxClient.UsersManager.AddEmailAliasAsync(this._userId.Value, this._userEmail.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) diff --git a/BoxCLI/Commands/UserSubCommands/UserChangeLoginCommand.cs b/BoxCLI/Commands/UserSubCommands/UserChangeLoginCommand.cs index f06d9202..969ef28e 100644 --- a/BoxCLI/Commands/UserSubCommands/UserChangeLoginCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserChangeLoginCommand.cs @@ -46,7 +46,7 @@ private async Task RunChangeEmail() { base.CheckForValue(this._userEmail.Value, this._app, "A user email is required for this command"); base.CheckForId(this._userId.Value, this._app); - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var user = await boxClient.UsersManager.ChangeUsersLoginAsync(this._userId.Value, this._userEmail.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) diff --git a/BoxCLI/Commands/UserSubCommands/UserCreateCommand.cs b/BoxCLI/Commands/UserSubCommands/UserCreateCommand.cs index eb95eba7..332666ba 100644 --- a/BoxCLI/Commands/UserSubCommands/UserCreateCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserCreateCommand.cs @@ -33,6 +33,7 @@ public class UserCreateCommand : UserSubCommandBase private CommandOption _isPasswordResetRequired; private CommandOption _appUser; private CommandOption _idOnly; + private CommandLineApplication _app; private IBoxHome _home; @@ -78,7 +79,7 @@ protected async override Task Execute() private async Task RunCreate() { - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._path.HasValue()) { var json = false; diff --git a/BoxCLI/Commands/UserSubCommands/UserDeleteCommand.cs b/BoxCLI/Commands/UserSubCommands/UserDeleteCommand.cs index 75f612ff..32d25edb 100644 --- a/BoxCLI/Commands/UserSubCommands/UserDeleteCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserDeleteCommand.cs @@ -48,7 +48,7 @@ protected async override Task Execute() private async Task RunDelete() { - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (this._path.HasValue()) { var path = GeneralUtilities.TranslatePath(this._path.Value()); diff --git a/BoxCLI/Commands/UserSubCommands/UserDeleteEmailAliasCommand.cs b/BoxCLI/Commands/UserSubCommands/UserDeleteEmailAliasCommand.cs index af39acd9..0812c352 100644 --- a/BoxCLI/Commands/UserSubCommands/UserDeleteEmailAliasCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserDeleteEmailAliasCommand.cs @@ -43,7 +43,7 @@ private async Task RunDeleteEmailAlias() { base.CheckForId(this._aliasId.Value, this._app); base.CheckForId(this._userId.Value, this._app); - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var alias = await boxClient.UsersManager.DeleteEmailAliasAsync(this._userId.Value, this._aliasId.Value); diff --git a/BoxCLI/Commands/UserSubCommands/UserGetCommand.cs b/BoxCLI/Commands/UserSubCommands/UserGetCommand.cs index eeb8f6d2..69d1c7d1 100644 --- a/BoxCLI/Commands/UserSubCommands/UserGetCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserGetCommand.cs @@ -13,7 +13,6 @@ namespace BoxCLI.Commands.UserSubCommands public class UserGetCommand : UserSubCommandBase { private CommandArgument _userId; - private CommandOption _asUser; private CommandLineApplication _app; private IBoxHome _home; @@ -29,7 +28,6 @@ public override void Configure(CommandLineApplication command) command.Description = "Get information about a Box user."; _userId = command.Argument("userId", "Id of user to manage, use 'me' for the current user"); - _asUser = AsUserOption.ConfigureOption(command); command.OnExecute(async () => { return await this.Execute(); @@ -46,29 +44,14 @@ protected async override Task Execute() public async Task RunGet() { var id = this._userId.Value; - BoxClient boxClient; - if (id == "me") + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + var user = await boxClient.UsersManager.GetUserInformationAsync(id); + if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { - boxClient = base.ConfigureBoxClient(this._asUser.Value()); - } - else - { - boxClient = base.ConfigureBoxClient(returnServiceAccount: true); - } - try - { - var user = await boxClient.UsersManager.GetUserInformationAsync(id); - if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) - { - base.OutputJson(user); - return; - } - base.PrintUserInfo(user); - } - catch (Exception e) - { - Reporter.WriteError(e.Message); + base.OutputJson(user); + return; } + base.PrintUserInfo(user); } } } \ No newline at end of file diff --git a/BoxCLI/Commands/UserSubCommands/UserGetEmailAliasesCommand.cs b/BoxCLI/Commands/UserSubCommands/UserGetEmailAliasesCommand.cs index e97635be..b6c420a9 100644 --- a/BoxCLI/Commands/UserSubCommands/UserGetEmailAliasesCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserGetEmailAliasesCommand.cs @@ -42,7 +42,7 @@ protected async override Task Execute() private async Task RunGetEmailAliases() { base.CheckForId(this._userId.Value, this._app); - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var alias = await boxClient.UsersManager.GetEmailAliasesAsync(this._userId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) diff --git a/BoxCLI/Commands/UserSubCommands/UserInviteCommand.cs b/BoxCLI/Commands/UserSubCommands/UserInviteCommand.cs index 6f63cc8b..d499f9ee 100644 --- a/BoxCLI/Commands/UserSubCommands/UserInviteCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserInviteCommand.cs @@ -46,7 +46,7 @@ private async Task RunInvite() { base.CheckForValue(this._userEmail.Value, this._app, "A user email is required for this command"); base.CheckForValue(this._enterpriseId.Value, this._app, "An enterprise id is required for this command"); - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); BoxUserInviteRequest userInviteRequest = new BoxUserInviteRequest() { Enterprise = new BoxRequestEntity() diff --git a/BoxCLI/Commands/UserSubCommands/UserListCommand.cs b/BoxCLI/Commands/UserSubCommands/UserListCommand.cs index f20e24c4..17dd51d4 100644 --- a/BoxCLI/Commands/UserSubCommands/UserListCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserListCommand.cs @@ -55,8 +55,8 @@ protected async override Task Execute() public async Task RunList() { - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); - var BoxCollectionsIterators = base.GetIterators(); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); var fileName = $"{base._names.CommandNames.Users}-{base._names.SubCommandNames.List}-{DateTime.Now.ToString(GeneralUtilities.GetDateFormatString())}"; var fields = base.ProcessFields(this._fieldsOption.Value(), base._fields); if (this._save.HasValue()) diff --git a/BoxCLI/Commands/UserSubCommands/UserMoveRootContentCommand.cs b/BoxCLI/Commands/UserSubCommands/UserMoveRootContentCommand.cs index 3c54b09b..3abac4a9 100644 --- a/BoxCLI/Commands/UserSubCommands/UserMoveRootContentCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserMoveRootContentCommand.cs @@ -48,7 +48,7 @@ private async Task RunMoveRoot() { base.CheckForId(this._userId.Value, this._app); base.CheckForId(this._newUserId.Value, this._app); - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); BoxFolder folder; if (this._notify.HasValue()) { diff --git a/BoxCLI/Commands/UserSubCommands/UserSearchCommand.cs b/BoxCLI/Commands/UserSubCommands/UserSearchCommand.cs index 6c887977..ff64c852 100644 --- a/BoxCLI/Commands/UserSubCommands/UserSearchCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserSearchCommand.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; using Box.V2.Models; using BoxCLI.BoxHome; @@ -44,8 +45,8 @@ protected async override Task Execute() private async Task RunSearch(string userName, bool managedOnly = false) { - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); - var BoxCollectionsIterators = base.GetIterators(); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); if (string.IsNullOrEmpty(userName)) { Reporter.WriteWarning("A user name is required to search."); diff --git a/BoxCLI/Commands/UserSubCommands/UserSubCommandBase.cs b/BoxCLI/Commands/UserSubCommands/UserSubCommandBase.cs index 16102c2d..0314fc51 100644 --- a/BoxCLI/Commands/UserSubCommands/UserSubCommandBase.cs +++ b/BoxCLI/Commands/UserSubCommands/UserSubCommandBase.cs @@ -22,6 +22,8 @@ namespace BoxCLI.Commands.UserSubCommands public class UserSubCommandBase : BoxBaseCommand { protected readonly List _fields; + protected CommandOption _asUser; + private CommandLineApplication _app; public UserSubCommandBase(IBoxPlatformServiceBuilder boxPlatformBuilder, IBoxHome home, LocalizedStringsResource names) : base(boxPlatformBuilder, home, names) @@ -52,6 +54,13 @@ public UserSubCommandBase(IBoxPlatformServiceBuilder boxPlatformBuilder, IBoxHom }; } + public override void Configure(CommandLineApplication command) + { + _app = command; + _asUser = AsUserOption.ConfigureOption(command); + base.Configure(command); + } + public virtual void PrintUserInfo(BoxUser user, bool json = false) { if (json) @@ -59,7 +68,7 @@ public virtual void PrintUserInfo(BoxUser user, bool json = false) base.OutputJson(user); return; } - else + else { this.PrintUserInfo(user); } @@ -121,7 +130,7 @@ protected void PrintAliases(BoxCollection aliases) protected async Task CreateUsersFromFile(string path, string asUser = "", bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); path = GeneralUtilities.TranslatePath(path); try { diff --git a/BoxCLI/Commands/UserSubCommands/UserUpdateCommand.cs b/BoxCLI/Commands/UserSubCommands/UserUpdateCommand.cs index 6a273de6..fc9d12fb 100644 --- a/BoxCLI/Commands/UserSubCommands/UserUpdateCommand.cs +++ b/BoxCLI/Commands/UserSubCommands/UserUpdateCommand.cs @@ -76,7 +76,7 @@ protected async override Task Execute() private async Task RunUpdate() { base.CheckForUserId(this._userId.Value, this._app); - var boxClient = base.ConfigureBoxClient(returnServiceAccount: true); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var userRequest = base.CreateUserRequest(this._name.Value(), this._userId.Value, this._role.Value(), this._enterprise.HasValue(), this._language.Value(), this._jobTitle.Value(), this._phoneNumber.Value(), this._address.Value(), this._spaceAmount.Value(), this._status.Value(), this._syncDisable.HasValue(), this._syncEnable.HasValue(), this._isExemptFromDeviceLimits.HasValue(), diff --git a/BoxCLI/Commands/WebhooksSubComands/WebhooksCreateCommand.cs b/BoxCLI/Commands/WebhooksSubComands/WebhooksCreateCommand.cs index c0c55a97..73ceb675 100644 --- a/BoxCLI/Commands/WebhooksSubComands/WebhooksCreateCommand.cs +++ b/BoxCLI/Commands/WebhooksSubComands/WebhooksCreateCommand.cs @@ -64,7 +64,7 @@ private async Task RunCreate() { json = true; } - await base.CreateWebhooksFromFile(_path.Value(), _asUser.Value(), this._save.HasValue(), json: json); + await base.CreateWebhooksFromFile(_path.Value(), this._save.HasValue(), json: json); return; } base.CheckForValue(this._id.Value, this._app, "A Box item ID is required for this call."); @@ -72,7 +72,7 @@ private async Task RunCreate() base.CheckForValue(this._triggers.Value, this._app, "Triggers are required for this call."); base.CheckForValue(this._address.Value, this._app, "A webhook handler URL is required for this call."); - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var type = base.ProcessType(this._type.Value); var webhookRequest = new BoxWebhookRequest(); diff --git a/BoxCLI/Commands/WebhooksSubComands/WebhooksDeleteCommand.cs b/BoxCLI/Commands/WebhooksSubComands/WebhooksDeleteCommand.cs index 37a37ace..6964386f 100644 --- a/BoxCLI/Commands/WebhooksSubComands/WebhooksDeleteCommand.cs +++ b/BoxCLI/Commands/WebhooksSubComands/WebhooksDeleteCommand.cs @@ -44,7 +44,7 @@ protected async override Task Execute() private async Task RunDelete() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (!string.IsNullOrEmpty(_path.Value())) { var path = GeneralUtilities.TranslatePath(_path.Value()); diff --git a/BoxCLI/Commands/WebhooksSubComands/WebhooksGetCommand.cs b/BoxCLI/Commands/WebhooksSubComands/WebhooksGetCommand.cs index 406c4c1a..29fe2d24 100644 --- a/BoxCLI/Commands/WebhooksSubComands/WebhooksGetCommand.cs +++ b/BoxCLI/Commands/WebhooksSubComands/WebhooksGetCommand.cs @@ -36,14 +36,14 @@ public override void Configure(CommandLineApplication command) protected async override Task Execute() { - await this.RunGet(_webhookId.Value, base._asUser.Value()); + await this.RunGet(); return await base.Execute(); } - private async Task RunGet(string id, string asUser) + private async Task RunGet() { - var boxClient = base.ConfigureBoxClient(asUser); - var webhook = await boxClient.WebhooksManager.GetWebhookAsync(id); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + var webhook = await boxClient.WebhooksManager.GetWebhookAsync(this._webhookId.Value); if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting()) { base.OutputJson(webhook); diff --git a/BoxCLI/Commands/WebhooksSubComands/WebhooksListCommand.cs b/BoxCLI/Commands/WebhooksSubComands/WebhooksListCommand.cs index df8863ad..0ed11cc3 100644 --- a/BoxCLI/Commands/WebhooksSubComands/WebhooksListCommand.cs +++ b/BoxCLI/Commands/WebhooksSubComands/WebhooksListCommand.cs @@ -49,8 +49,8 @@ protected async override Task Execute() public async Task RunList() { - var boxClient = base.ConfigureBoxClient(base._asUser.Value()); - var BoxCollectionsIterators = base.GetIterators(); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); + var BoxCollectionsIterators = base.GetIterators(!String.IsNullOrEmpty(base._oneUseToken.Value())); if (_save.HasValue()) { var fileName = $"{base._names.CommandNames.Webhooks}-{base._names.SubCommandNames.List}-{DateTime.Now.ToString(GeneralUtilities.GetDateFormatString())}"; diff --git a/BoxCLI/Commands/WebhooksSubComands/WebhooksSubCommandBase.cs b/BoxCLI/Commands/WebhooksSubComands/WebhooksSubCommandBase.cs index f08adf7c..8a4b1bf2 100644 --- a/BoxCLI/Commands/WebhooksSubComands/WebhooksSubCommandBase.cs +++ b/BoxCLI/Commands/WebhooksSubComands/WebhooksSubCommandBase.cs @@ -27,10 +27,10 @@ public override void Configure(CommandLineApplication command) base.Configure(command); } - protected async Task CreateWebhooksFromFile(string path, string asUser = "", + protected async Task CreateWebhooksFromFile(string path, bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { - var boxClient = base.ConfigureBoxClient(asUser); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); @@ -84,10 +84,10 @@ protected async Task CreateWebhooksFromFile(string path, string asUser = "", } } - protected async Task UpdateWebhooksFromFile(string path, string asUser = "", + protected async Task UpdateWebhooksFromFile(string path, bool save = false, string overrideSavePath = "", string overrideSaveFileFormat = "", bool json = false) { - var boxClient = base.ConfigureBoxClient(asUser); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: this._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); if (!string.IsNullOrEmpty(path)) { path = GeneralUtilities.TranslatePath(path); diff --git a/BoxCLI/Commands/WebhooksSubComands/WebhooksUpdateCommand.cs b/BoxCLI/Commands/WebhooksSubComands/WebhooksUpdateCommand.cs index cd04509b..df23a631 100644 --- a/BoxCLI/Commands/WebhooksSubComands/WebhooksUpdateCommand.cs +++ b/BoxCLI/Commands/WebhooksSubComands/WebhooksUpdateCommand.cs @@ -59,12 +59,12 @@ private async Task RunUpdate() { json = true; } - await base.UpdateWebhooksFromFile(_path.Value(), _asUser.Value(), this._save.HasValue(), json: json); + await base.UpdateWebhooksFromFile(_path.Value(), this._save.HasValue(), json: json); return; } base.CheckForValue(this._id.Value, this._app, "A webhook ID is required for this call."); - var boxClient = base.ConfigureBoxClient(this._asUser.Value()); + var boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value()); var webhookRequest = new BoxWebhookRequest(); webhookRequest.Id = this._id.Value; if (this._triggers.HasValue()) diff --git a/BoxCLI/Program.cs b/BoxCLI/Program.cs index dde40050..62798c5f 100755 --- a/BoxCLI/Program.cs +++ b/BoxCLI/Program.cs @@ -21,6 +21,7 @@ using BoxCLI.Commands.ConfigureSubCommands; using BoxCLI.CommandUtilities.Exceptions; using Newtonsoft.Json.Linq; +using Box.V2.Exceptions; namespace BoxCLI { @@ -29,6 +30,8 @@ class Program static public IConfigurationRoot Configuration { get; set; } static public IServiceProvider Services { get; set; } + static private CommandLineApplication _app; + static int Main(string[] args) { var builder = new ConfigurationBuilder(); @@ -38,15 +41,37 @@ static int Main(string[] args) ConfigureServices(serviceCollection); Services = serviceCollection.BuildServiceProvider(); - try { var app = new CommandLineApplication(); var root = Services.GetService(); + _app = app; root.Configure(app); return app.Execute(args); } + catch (AggregateException aggEx) + { + if (aggEx.InnerException.GetType() == typeof(BoxSessionInvalidatedException)) + { + Reporter.WriteError("Token not valid."); + Reporter.WriteError("Please try another token with the --token option."); + } + else if (aggEx != null && !string.IsNullOrEmpty(aggEx.Message)) + { + Reporter.WriteError(GeneralUtilities.FormatErrorResponseFromAPI(aggEx.InnerException)); + } + if (aggEx.InnerException != null) + { + if (aggEx.InnerException.GetType() == typeof(NoEnvironmentsFoundException)) + { + Reporter.WriteError("It looks like you haven't configured the Box CLI yet."); + Reporter.WriteError("Use this command to start using the CLI: box configure environments add"); + Reporter.WriteError("Or, supply a token with your command with --token."); + } + } + return 1; + } catch (Exception ex) { if (ex != null && !string.IsNullOrEmpty(ex.Message)) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b0dafb9..687587bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 1.1.0 +- Added new feature on all commands for using an individual token. Add the `--token` option to perform an individual command with the Box CLI using a specific token you provide. The feature is most useful when paired with the Developer Token you can generate through the Box Developer Console. When working with an application you create in the Box Developer Console, you will not need to authorize the application into a Box Enterprise before working with the Developer Token. For example usage: `box users get me --token `. Certain commands may fail based on the permissions of the user to which the token you use belongs. +- Fixed a bug preventing `previewer` being used when adding or updating a collaboration. +- Added the following commands: `box collaborations delete`, `box folders collaborations delete`, `box files collaborations delete`. +- Improved error messaging for failure on registering a configuration file and private key file with the Box CLI when creating a new CLI `environment`. +- Added `--disable-file-path-translation` to the following commands: `box configure environments add`, `box configure environments update-config-file-path`, `box configure environments update-private-key-path`. This option ignores any additional processing on trying to resolve the file paths you provide when creating and updating Box CLI `environments`. +- Fixed visual bug with upload progress tracker. +- Updated Box .Net SDK to v3.3.0. +- Changed Box CLI output to JSON by default with no existing `.box` directory. + ## 1.0.2 - Added shared link commands for Create, Get, Update, and Delete. Located as standalone commands under `box shared-links` as well as under `box folders shared-links` and `box files shared-links`. - Fixed UTF-8 issue obscuring characters when saving CSV reports.