Files
duplicati/proprietary/GoogleWorkspace/SourceItems/SharedDrivePermissionsSourceEntry.cs
T
Kenneth Skovhede da246874ec Initial implementation of Google Workspace backup.
This is a WIP and still needs the restore part implemented.

Not all resources are fully tested but basic elements work.
2026-02-04 15:44:23 +01:00

38 lines
1.6 KiB
C#

// Copyright (c) 2026 Duplicati Inc. All rights reserved.
using Duplicati.Library.Common.IO;
using Google.Apis.Drive.v3.Data;
using System.Text.Json;
namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems;
internal class SharedDrivePermissionsSourceEntry(SourceProvider provider, string parentPath, Drive drive)
: StreamResourceEntryBase(SystemIO.IO_OS.PathCombine(parentPath, "permissions.json"), drive.CreatedTimeDateTimeOffset.HasValue ? drive.CreatedTimeDateTimeOffset.Value.UtcDateTime : DateTime.UnixEpoch, DateTime.UnixEpoch)
{
public override long Size => -1;
public override async Task<Stream> OpenRead(CancellationToken cancellationToken)
{
var service = provider.ApiHelper.GetDriveService();
var request = service.Permissions.List(drive.Id);
request.SupportsAllDrives = true;
var permissions = await request.ExecuteAsync(cancellationToken);
var json = JsonSerializer.Serialize(permissions, new JsonSerializerOptions { WriteIndented = true });
return new MemoryStream(System.Text.Encoding.UTF8.GetBytes(json));
}
public override Task<Dictionary<string, string?>> GetMinorMetadata(CancellationToken cancellationToken)
{
return Task.FromResult(new Dictionary<string, string?>
{
{ "gsuite:v", "1" },
{ "gsuite:Type", SourceItemType.DrivePermission.ToString() },
{ "gsuite:Name", "permissions.json" },
{ "gsuite:id", drive.Id }
}
.Where(kv => !string.IsNullOrEmpty(kv.Value))
.ToDictionary(kv => kv.Key, kv => kv.Value));
}
}