Instead of requesting all scopes up front, each sub-section of the backup/restore will request the permissions that are relevant for the operation. The effect is that it is not required to grant all permissions to get a backup running. If permissions are failing, that part of the backup will generate warnings for items that are excluded.
48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
// Copyright (c) 2026 Duplicati Inc. All rights reserved.
|
|
|
|
using Duplicati.Library.Common.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems;
|
|
|
|
internal class GroupAliasesSourceEntry(SourceProvider provider, string parentPath, string groupEmail)
|
|
: StreamResourceEntryBase(SystemIO.IO_OS.PathCombine(parentPath, "aliases.json"), DateTime.UnixEpoch, DateTime.UnixEpoch)
|
|
{
|
|
public override long Size => -1;
|
|
|
|
public override async Task<Stream> OpenRead(CancellationToken cancellationToken)
|
|
{
|
|
var service = provider.ApiHelper.GetDirectoryServiceForGroups();
|
|
var request = service.Groups.Get(groupEmail);
|
|
var group = await request.ExecuteAsync(cancellationToken);
|
|
|
|
var aliases = new List<string>();
|
|
|
|
if (group.Aliases != null)
|
|
{
|
|
aliases.AddRange(group.Aliases);
|
|
}
|
|
|
|
if (group.NonEditableAliases != null)
|
|
{
|
|
aliases.AddRange(group.NonEditableAliases);
|
|
}
|
|
|
|
var json = JsonSerializer.Serialize(aliases, 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.GroupAliases.ToString() },
|
|
{ "gsuite:Name", "aliases.json" },
|
|
{ "gsuite:Id", groupEmail }
|
|
}
|
|
.Where(kv => !string.IsNullOrEmpty(kv.Value))
|
|
.ToDictionary(kv => kv.Key, kv => kv.Value));
|
|
}
|
|
}
|