Skip to content

Commit

Permalink
feat: support for symbol file signatures (#59)
Browse files Browse the repository at this point in the history
* Support for symbol file signatures

* Moved signature to a default parameter for the public API

* Extracted new function AddFormDataOptionalSignature()

* Better variable names

* Use string.IsNullOrEmpty()

* Removed unneeded files

* chore: code review suggestions

* chore: update BugSplatDotNetStandard/Api/VersionsClient.cs

* chore: update BugSplatDotNetStandard/Api/VersionsClient.cs

Co-authored-by: Bobby Galli <[email protected]>
  • Loading branch information
daveplunkett and bobbyg603 authored Sep 8, 2022
1 parent c4ea4c7 commit 68d3b7d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
21 changes: 19 additions & 2 deletions BugSplatDotNetStandard.Test/SymbolUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void SymbolUploader_UploadSymbolFile_ShouldUploadSymbolFileToBugSplat()
var sut = SymbolUploader.CreateSymbolUploader(email, password);
var symbolFileInfo = new FileInfo("Files/myConsoleCrasher.exe");
var response = sut.UploadSymbolFile(
"fred",
database,
"myConsoleCrasher",
"2022.5.2.0",
symbolFileInfo
Expand All @@ -52,7 +52,7 @@ public void SymbolUploader_UploadSymbolFiles_ShouldUploadSymbolFilesToBugSplat()
new FileInfo("Files/myConsoleCrasher.pdb")
};
var responses = sut.UploadSymbolFiles(
"fred",
database,
"myConsoleCrasher",
"2022.5.2.0",
symbolFileInfos
Expand All @@ -64,5 +64,22 @@ public void SymbolUploader_UploadSymbolFiles_ShouldUploadSymbolFilesToBugSplat()
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
}
}

[Test]
public void SymbolUploader_UploadSymbolFileWithSignature_ShouldUploadSymbolFileToBugSplat()
{
var sut = SymbolUploader.CreateSymbolUploader(email, password);
var symbolFileInfo = new FileInfo("Files/myConsoleCrasher.exe");
var response = sut.UploadSymbolFile(
database,
"myConsoleCrasher",
"2022.5.2.0",
symbolFileInfo,
"62702A2F26000"
).Result;
var body = response.Content.ReadAsStringAsync().Result;

Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
}
}
}
47 changes: 39 additions & 8 deletions BugSplatDotNetStandard/Api/VersionsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ public async Task<HttpResponseMessage> GetVersions(string database)
/// <param name="application">BugSplat application value to associate with the symbol file</param>
/// <param name="version">BugSplat version value to associate with the symbol file</param>
/// <param name="symbolFileInfo">The symbol file that will be uploaded to BugSplat</param>
/// <param name="signature">Optional, the unique symbol file signature</param>
public async Task<HttpResponseMessage> UploadSymbolFile(
string database,
string application,
string version,
FileInfo symbolFileInfo
FileInfo symbolFileInfo,
string optionalSignature = null
)
{
ThrowIfArgumentIsNullOrEmpty(database, "database");
Expand All @@ -82,15 +84,28 @@ FileInfo symbolFileInfo
{
var zipFileInfo = ZipUtils.CreateZipFile(zipFileFullName, new List<FileInfo>() { symbolFileInfo });

var optionalSymbolFileLastWriteTimeStr = string.Empty;
var optionalModuleName = string.Empty;
if (!string.IsNullOrEmpty(optionalSignature))
{
var symbolFileLastWriteTime = File.GetLastWriteTime(symbolFileInfo.FullName);
var unixTime = ((DateTimeOffset)symbolFileLastWriteTime).ToUnixTimeSeconds();
optionalSymbolFileLastWriteTimeStr = unixTime.ToString();
optionalModuleName = symbolFileInfo.Name;
}

using (var zipFileStream = ZipUtils.CreateZipFileStream(zipFileFullName))
using (
var presignedUrlResponse = await this.GetSymbolUploadUrl(
database,
application,
version,
zipFileInfo.Length,
zipFileInfo.Name
)
database,
application,
version,
zipFileInfo.Length,
zipFileInfo.Name,
optionalModuleName,
optionalSymbolFileLastWriteTimeStr,
optionalSignature
)
)
{
ThrowIfHttpRequestFailed(presignedUrlResponse);
Expand Down Expand Up @@ -136,7 +151,10 @@ private async Task<HttpResponseMessage> GetSymbolUploadUrl(
string application,
string version,
long symbolFileSize,
string symbolFileName
string symbolFileName,
string moduleName = null,
string lastModified = null,
string signature = null
)
{
var route = "/api/versions";
Expand All @@ -150,7 +168,20 @@ string symbolFileName
{ new StringContent(symbolFileName), "symFileName" },
};

AddFormDataOptionalSignature(formData, moduleName, signature, lastModified);

return await this.bugsplatApiClient.PostAsync(route, formData);
}

private void AddFormDataOptionalSignature(MultipartFormDataContent formData, string moduleName, string signature, string lastModified)
{
if(!string.IsNullOrEmpty(moduleName) && !string.IsNullOrEmpty(lastModified) && !string.IsNullOrEmpty(signature))
{
formData.Add(new StringContent("bsv1"), "SendPdbsVersion");
formData.Add(new StringContent(moduleName), "moduleName");
formData.Add(new StringContent(lastModified), "lastModified");
formData.Add(new StringContent(signature), "dbgId");
}
}
}
}
5 changes: 3 additions & 2 deletions BugSplatDotNetStandard/SymbolUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ public static SymbolUploader CreateSymbolUploader(string email, string password)
/// <param name="application">BugSplat application value to associate with the symbol file</param>
/// <param name="version">BugSplat version value to associate with the symbol file</param>
/// <param name="symbolFileInfo">The symbol file that will be uploaded to BugSplat</param>
public async Task<HttpResponseMessage> UploadSymbolFile(string database, string application, string version, FileInfo symbolFileInfo)
/// <param name="signature">Optional, the unique symbol file signature</param>
public async Task<HttpResponseMessage> UploadSymbolFile(string database, string application, string version, FileInfo symbolFileInfo, string signature=null)
{
if (!bugsplatApiClient.Authenticated)
{
await bugsplatApiClient.Authenticate();
}

return await versionsClient.UploadSymbolFile(database, application, version, symbolFileInfo);
return await versionsClient.UploadSymbolFile(database, application, version, symbolFileInfo, signature);
}

/// <summary>
Expand Down

0 comments on commit 68d3b7d

Please sign in to comment.