Skip to content

Commit

Permalink
bump AVPRClient, use Hash functions from AVPRIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jun 18, 2024
1 parent dcc0070 commit d0183b6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 113 deletions.
111 changes: 10 additions & 101 deletions src/AVPRClient/AVPRClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ public virtual async System.Threading.Tasks.Task<ValidationPackage> CreatePackag
throw new ApiException("A server side error occurred.", status_, responseText_, headers_, null);
}
else
if (status_ == 422)
{
var objectResponse_ = await ReadObjectResponseAsync<string>(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
throw new ApiException<string>("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
Expand Down Expand Up @@ -602,107 +612,6 @@ public virtual async System.Threading.Tasks.Task VerifyPackageContentAsync(Packa
}
}

/// <summary>
/// Create a content hash for a given package.
/// </summary>
/// <remarks>
/// Create a content hash for a given package. Hashes are MD5 hex fingerprints. This Endpoint requires API Key authentication.
/// </remarks>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<PackageContentHash> CreatePackageContentHashAsync(PackageContentHash hashedPackage)
{
return CreatePackageContentHashAsync(hashedPackage, System.Threading.CancellationToken.None);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Create a content hash for a given package.
/// </summary>
/// <remarks>
/// Create a content hash for a given package. Hashes are MD5 hex fingerprints. This Endpoint requires API Key authentication.
/// </remarks>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<PackageContentHash> CreatePackageContentHashAsync(PackageContentHash hashedPackage, System.Threading.CancellationToken cancellationToken)
{
if (hashedPackage == null)
throw new System.ArgumentNullException("hashedPackage");

var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
{
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(hashedPackage, _settings.Value);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));

var urlBuilder_ = new System.Text.StringBuilder();
if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl);
// Operation Path: "api/v1/verify/hashes"
urlBuilder_.Append("api/v1/verify/hashes");

PrepareRequest(client_, request_, urlBuilder_);

var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);

PrepareRequest(client_, request_, url_);

var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = new System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>>();
foreach (var item_ in response_.Headers)
headers_[item_.Key] = item_.Value;
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync<PackageContentHash>(response_, headers_, cancellationToken).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
if (status_ == 409)
{
string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("A server side error occurred.", status_, responseText_, headers_, null);
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}

/// <summary>
/// Get all download statistics
/// </summary>
Expand Down
20 changes: 17 additions & 3 deletions src/AVPRClient/AVPRClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,27 @@
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/RELEASE_NOTES.md"))</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageVersion>0.0.7</PackageVersion>
<PackageVersion>0.0.8</PackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<None Include="README.md" Pack="true" PackagePath="\" />
<ProjectReference Include="..\AVPRIndex\AVPRIndex.fsproj" />
<ProjectReference Include="..\AVPRIndex\AVPRIndex.fsproj" PackageVersion="[0.1.2, 1.0.0)" />
</ItemGroup>

<Target Name="UseExplicitPackageVersions" BeforeTargets="GenerateNuspec">
<ItemGroup>
<_ProjectReferenceWithExplicitPackageVersion Include="@(ProjectReference->'%(FullPath)')" Condition="'%(ProjectReference.PackageVersion)' != ''" />
<_ProjectReferenceWithExactPackageVersion Include="@(ProjectReference->'%(FullPath)')" Condition="'%(ProjectReference.ExactVersion)' == 'true'" />
<_ProjectReferenceWithReassignedVersion Include="@(_ProjectReferencesWithVersions)" Condition="'%(Identity)' != '' And '@(_ProjectReferenceWithExplicitPackageVersion)' == '@(_ProjectReferencesWithVersions)'">
<ProjectVersion>@(_ProjectReferenceWithExplicitPackageVersion->'%(PackageVersion)')</ProjectVersion>
</_ProjectReferenceWithReassignedVersion>
<_ProjectReferenceWithReassignedVersion Include="@(_ProjectReferencesWithVersions)" Condition="'%(Identity)' != '' And '@(_ProjectReferenceWithExactPackageVersion)' == '@(_ProjectReferencesWithVersions)'">
<ProjectVersion>@(_ProjectReferenceWithExplicitPackageVersion->'%(PackageVersion)')</ProjectVersion>
</_ProjectReferenceWithReassignedVersion>
<_ProjectReferencesWithVersions Remove="@(_ProjectReferenceWithReassignedVersion)" />
<_ProjectReferencesWithVersions Include="@(_ProjectReferenceWithReassignedVersion)" />
</ItemGroup>
</Target>
</Project>
10 changes: 1 addition & 9 deletions src/AVPRClient/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,10 @@ public static AVPRClient.PackageContentHash toPackageContentHash(
{
if ( HashFileDirectly)
{
MD5 md5 = MD5.Create();
return new AVPRClient.PackageContentHash
{
PackageName = indexedPackage.Metadata.Name,
Hash = Convert.ToHexString(
md5.ComputeHash(
Encoding.UTF8.GetBytes(
File.ReadAllText(indexedPackage.RepoPath)
.ReplaceLineEndings("\n")
)
)
),
Hash = Hash.hashFile(indexedPackage.RepoPath),
PackageMajorVersion = indexedPackage.Metadata.MajorVersion,
PackageMinorVersion = indexedPackage.Metadata.MinorVersion,
PackagePatchVersion = indexedPackage.Metadata.PatchVersion
Expand Down
3 changes: 3 additions & 0 deletions src/AVPRClient/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.0.8
- Use AVPRIndex for all package hash calculations

## v0.0.7
- Further TypeExtension improvements and fixes

Expand Down

0 comments on commit d0183b6

Please sign in to comment.