This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from LuccaSA/async
Add command to auto-decompress
- Loading branch information
Showing
6 changed files
with
161 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Google.Apis.Auth.OAuth2; | ||
using Google.Cloud.Storage.V1; | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace TCC.Lib.Helpers | ||
{ | ||
public static class GoogleAuthHelper | ||
{ | ||
public static async Task<GoogleCredential> GetGoogleClientAsync(string googleStorageCredential, CancellationToken token) | ||
{ | ||
if (File.Exists(googleStorageCredential)) | ||
{ | ||
return await GoogleCredential.FromFileAsync(googleStorageCredential, token); | ||
} | ||
else | ||
{ | ||
var decodedJson = Encoding.UTF8.GetString(Convert.FromBase64String(googleStorageCredential)); | ||
return GoogleCredential.FromJson(decodedJson); | ||
} | ||
} | ||
|
||
public static async Task<StorageClient> GetGoogleStorageClientAsync(string googleStorageCredential, CancellationToken token) | ||
{ | ||
var credential = await GetGoogleClientAsync(googleStorageCredential, token); | ||
return await StorageClient.CreateAsync(credential); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Collections.Generic; | ||
using System.CommandLine; | ||
using System.Threading.Tasks; | ||
using TCC.Lib.Options; | ||
|
||
namespace TCC.Parser | ||
{ | ||
public class AutoDecompressOptionBinding : DecompressOption | ||
{ | ||
public AutoDecompressOptionBinding() | ||
{ | ||
base.Threads = 1; | ||
} | ||
public new string Threads { set => base.Threads = ParseCommandLineHelper.ThreadsParsing(value); } | ||
public string Password { set => ParseCommandLineHelper.ExtractInlinePassword(this, value); } | ||
public string PassFile { set => ParseCommandLineHelper.ExtractPasswordFile(this, value); } | ||
public string Key { set => ParseCommandLineHelper.ExtractAsymetricFile(this, Mode.Decompress, value); } | ||
public string GoogleStorageCredential { get; set; } | ||
public string GoogleProjectId { get; set; } | ||
public string GoogleSubscriptionId { get; set; } | ||
public string TemporaryDirectory { get; set; } | ||
} | ||
|
||
|
||
public class AutoDecompressCommand : TccCommand<AutoDecompressOptionBinding> | ||
{ | ||
public AutoDecompressCommand() : base("auto-decompress", "Continuous decompress from Google Cloud Storage") | ||
{ | ||
} | ||
|
||
protected override IEnumerable<Argument> CreateArguments() | ||
{ | ||
yield break; | ||
} | ||
protected override IEnumerable<Option> CreateOptions() | ||
{ | ||
foreach (var option in BaseCmdOptions.CreateBaseOptions()) | ||
{ | ||
yield return option; | ||
} | ||
yield return new Option<string>(new[] { "--googleStorageCredential" }, "Google Cloud Storage credential json, either full path or base64"); | ||
yield return new Option<string>(new[] { "--googleProjectId" }, "Google Cloud Pub/Sub, storage projectId"); | ||
yield return new Option<string>(new[] { "--googleSubscriptionId" }, "Google Cloud Pub/Sub subscriptionId"); | ||
yield return new Option<string>(new[] { "--temporaryDirectory" }, "Directory where archive are downloaded temporary"); | ||
} | ||
|
||
protected override Task RunAsync(ITccController controller, AutoDecompressOptionBinding option) | ||
=> controller.AutoDecompressAsync(option); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters