Skip to content

Commit

Permalink
Merge commit '7a83a42e1a16edc0c4043aa3c53b9993924402c9'
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollo3zehn committed Mar 18, 2024
2 parents cdca7a0 + 7a83a42 commit 89e6ae6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v2.0.0-beta.29 - 2024-03-18
- Fixed wrong `users` folder location.

## v2.0.0-beta.28 - 2024-03-16
- Fixed a bug where applications could not access the `/api/v1/jobs` endpoint using the new personal access tokens.

Expand Down
1 change: 0 additions & 1 deletion src/Nexus/Core/NexusOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ internal record PathsOptions() : NexusOptionsBase
public string Cache { get; set; } = Path.Combine(PlatformSpecificRoot, "cache");
public string Catalogs { get; set; } = Path.Combine(PlatformSpecificRoot, "catalogs");
public string Artifacts { get; set; } = Path.Combine(PlatformSpecificRoot, "artifacts");
public string Users { get; set; } = Path.Combine(PlatformSpecificRoot, "users");
public string Packages { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nexus", "packages");
// GetGlobalPackagesFolder: https://github.com/NuGet/NuGet.Client/blob/0fc58e13683565e7bdf30e706d49e58fc497bbed/src/NuGet.Core/NuGet.Configuration/Utility/SettingsUtility.cs#L225-L254
// GetFolderPath: https://github.com/NuGet/NuGet.Client/blob/1d75910076b2ecfbe5f142227cfb4fb45c093a1e/src/NuGet.Core/NuGet.Common/PathUtil/NuGetEnvironment.cs#L54-L57
Expand Down
76 changes: 38 additions & 38 deletions src/Nexus/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ internal interface IDatabaseService
bool TryReadProject([NotNullWhen(true)] out string? project);
Stream WriteProject();

/* /config/users */
bool TryReadTokenMap(
string userId,
[NotNullWhen(true)] out string? tokenMap);

Stream WriteTokenMap(
string userId);

/* /catalogs/catalog_id/... */
bool AttachmentExists(string catalogId, string attachmentId);
IEnumerable<string> EnumerateAttachments(string catalogId);
Expand All @@ -31,14 +39,6 @@ internal interface IDatabaseService
bool TryReadCacheEntry(CatalogItem catalogItem, DateTime begin, [NotNullWhen(true)] out Stream? cacheEntry);
bool TryWriteCacheEntry(CatalogItem catalogItem, DateTime begin, [NotNullWhen(true)] out Stream? cacheEntry);
Task ClearCacheEntriesAsync(string catalogId, DateOnly day, TimeSpan timeout, Predicate<string> predicate);

/* /users */
bool TryReadTokenMap(
string userId,
[NotNullWhen(true)] out string? tokenMap);

Stream WriteTokenMap(
string userId);
}

internal class DatabaseService(IOptions<PathsOptions> pathsOptions)
Expand Down Expand Up @@ -114,6 +114,36 @@ public Stream WriteProject()
return File.Open(filePath, FileMode.Create, FileAccess.Write);
}

/* /config/users */
public bool TryReadTokenMap(
string userId,
[NotNullWhen(true)] out string? tokenMap)
{
var folderPath = SafePathCombine(Path.Combine(_pathsOptions.Config, "users"), userId);
var tokenFilePath = Path.Combine(folderPath, "tokens.json");

tokenMap = default;

if (File.Exists(tokenFilePath))
{
tokenMap = File.ReadAllText(tokenFilePath);
return true;
}

return false;
}

public Stream WriteTokenMap(
string userId)
{
var folderPath = SafePathCombine(Path.Combine(_pathsOptions.Config, "users"), userId);
var tokenFilePath = Path.Combine(folderPath, "tokens.json");

Directory.CreateDirectory(folderPath);

return File.Open(tokenFilePath, FileMode.Create, FileAccess.Write);
}

/* /catalogs/catalog_id/... */

public bool AttachmentExists(string catalogId, string attachmentId)
Expand Down Expand Up @@ -332,36 +362,6 @@ private static async Task DeleteCacheEntryAsync(string cacheEntry, TimeSpan time
throw new Exception($"Cannot delete cache entry {cacheEntry}.");
}

/* /users */
public bool TryReadTokenMap(
string userId,
[NotNullWhen(true)] out string? tokenMap)
{
var folderPath = SafePathCombine(_pathsOptions.Users, userId);
var tokenFilePath = Path.Combine(folderPath, "tokens.json");

tokenMap = default;

if (File.Exists(tokenFilePath))
{
tokenMap = File.ReadAllText(tokenFilePath);
return true;
}

return false;
}

public Stream WriteTokenMap(
string userId)
{
var folderPath = SafePathCombine(_pathsOptions.Users, userId);
var tokenFilePath = Path.Combine(folderPath, "tokens.json");

Directory.CreateDirectory(folderPath);

return File.Open(tokenFilePath, FileMode.Create, FileAccess.Write);
}

//
private static string SafePathCombine(string basePath, string relativePath)
{
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "2.0.0",
"suffix": "beta.28"
"suffix": "beta.29"
}

0 comments on commit 89e6ae6

Please sign in to comment.