in src/Google.Cloud.Functions.Framework/GcfEvents/GcfConverters.cs [432:461]
protected override void PopulateAttributes(Request request, CloudEvent evt)
{
string resource = request.Context.Resource.Name!;
string service = request.Context.Resource.Service!;
string? domain = request.Domain;
if (string.IsNullOrEmpty(domain))
{
throw new ConversionException("Firebase RTDB event does not contain a domain");
}
string location = domain == FirebaseDefaultDomain
? FirebaseDefaultLocation
: domain.Split('.').First();
string[] resourceSegments = resource.Split('/', SubjectStartIndex + 1);
if (resourceSegments.Length < SubjectStartIndex ||
!resourceSegments[SubjectStartIndex].StartsWith(ExpectedSubjectPrefix, StringComparison.Ordinal))
{
// This is odd... just put everything in the source as normal.
base.PopulateAttributes(request, evt);
}
else
{
// We need to convert "projects/_/instances/{instance}" to "projects/_/locations/{location}/instances/{instance}".
string sourcePath = string.Join('/',
resourceSegments.Take(2).Concat(new[] { "locations", location }).Concat(resourceSegments.Skip(2).Take(2)));
evt.Subject = resourceSegments[SubjectStartIndex];
evt.Source = FormatSource(service, sourcePath);
}
}