diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-09-06 09:02:31 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2026-09-06 09:02:31 +1000 |
| commit | a9bc03fb01b5d1ac41bf5592f384d22df5425aa4 (patch) | |
| tree | 16ae13e19d2a3cd7488202c30790d09557559d70 /src/marlin.core/functional/TokenGitCredential.cs | |
| parent | c00992ffad24212c4398736efd6d707d4cb0cc0d (diff) | |
feat: vcs and secret management support
Diffstat (limited to 'src/marlin.core/functional/TokenGitCredential.cs')
| -rw-r--r-- | src/marlin.core/functional/TokenGitCredential.cs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/marlin.core/functional/TokenGitCredential.cs b/src/marlin.core/functional/TokenGitCredential.cs new file mode 100644 index 0000000..5dfef66 --- /dev/null +++ b/src/marlin.core/functional/TokenGitCredential.cs @@ -0,0 +1,32 @@ +namespace marlin.core.functional; + +using System.Diagnostics; +using System.Text; + +/// <summary> +/// HTTPS auth via a bearer/basic token. Injected as an Authorization header for a +/// single git invocation through GIT_CONFIG_* env vars, so it never appears in argv +/// (visible via ps) or in git's own error output (which echoes the URL, not headers). +/// </summary> +public sealed class TokenGitCredential : IGitCredential +{ + private readonly string _username; + private readonly string _token; + + public TokenGitCredential(string token, string username = "x-access-token") + { + this._token = token; + this._username = username; + } + + public Task<IAsyncDisposable> ApplyAsync(ProcessStartInfo psi) + { + string header = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{this._username}:{this._token}")); + + psi.Environment["GIT_CONFIG_COUNT"] = "1"; + psi.Environment["GIT_CONFIG_KEY_0"] = "http.extraheader"; + psi.Environment["GIT_CONFIG_VALUE_0"] = $"AUTHORIZATION: basic {header}"; + + return Task.FromResult<IAsyncDisposable>(NoopAsyncDisposable.Instance); + } +} |
