Files
duplicati/proprietary/GoogleWorkspace/SourceItems/ContactGroupsFolderSourceEntry.cs
T
Kenneth Skovhede 910c56b3c4 Reworked the use of scopes.
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.
2026-02-15 22:03:57 +01:00

49 lines
1.8 KiB
C#

// Copyright (c) 2026 Duplicati Inc. All rights reserved.
using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using Google.Apis.PeopleService.v1;
using System.Runtime.CompilerServices;
namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems;
internal class ContactGroupsFolderSourceEntry(string parentPath, PeopleServiceService peopleService)
: MetaEntryBase(Util.AppendDirSeparator(SystemIO.IO_OS.PathCombine(parentPath, "Groups")), null, null)
{
public override async IAsyncEnumerable<ISourceProviderEntry> Enumerate([EnumeratorCancellation] CancellationToken cancellationToken)
{
var request = peopleService.ContactGroups.List();
string? nextPageToken = null;
do
{
if (cancellationToken.IsCancellationRequested) yield break;
request.PageToken = nextPageToken;
var groups = await request.ExecuteAsync(cancellationToken);
if (groups.ContactGroups != null)
{
foreach (var group in groups.ContactGroups)
{
if (cancellationToken.IsCancellationRequested) yield break;
yield return new ContactGroupSourceEntry(this.Path, group);
}
}
nextPageToken = groups.NextPageToken;
} while (!string.IsNullOrEmpty(nextPageToken));
}
public override Task<Dictionary<string, string?>> GetMinorMetadata(CancellationToken cancellationToken)
{
return Task.FromResult(new Dictionary<string, string?>
{
{ "gsuite:v", "1" },
{ "gsuite:Type", SourceItemType.ContactGroup.ToString() }, // Or UserContactGroups?
{ "gsuite:Name", "Groups" },
{ "gsuite:Id", "Groups" }
}
.Where(kv => !string.IsNullOrEmpty(kv.Value))
.ToDictionary(kv => kv.Key, kv => kv.Value));
}
}