2019-10-26 01:59:50 +02:00
|
|
|
|
// Copyright 2016-2019, Pulumi Corporation
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
using Pulumi.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Pulumi
|
|
|
|
|
{
|
|
|
|
|
public partial class Deployment
|
|
|
|
|
{
|
2020-07-21 10:50:14 +02:00
|
|
|
|
internal static bool _excessiveDebugOutput = false;
|
2019-10-26 01:59:50 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="SerializeResourcePropertiesAsync"/> walks the props object passed in,
|
|
|
|
|
/// awaiting all interior promises besides those for <see cref="Resource.Urn"/> and <see
|
|
|
|
|
/// cref="CustomResource.Id"/>, creating a reasonable POCO object that can be remoted over
|
|
|
|
|
/// to registerResource.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static Task<SerializationResult> SerializeResourcePropertiesAsync(
|
2020-10-27 18:12:12 +01:00
|
|
|
|
string label, IDictionary<string, object?> args, bool keepResources)
|
2019-10-26 01:59:50 +02:00
|
|
|
|
{
|
|
|
|
|
return SerializeFilteredPropertiesAsync(
|
2020-10-27 18:12:12 +01:00
|
|
|
|
label, args, key => key != Constants.IdPropertyName && key != Constants.UrnPropertyName, keepResources);
|
2019-10-26 01:59:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async Task<Struct> SerializeAllPropertiesAsync(
|
2020-10-27 18:12:12 +01:00
|
|
|
|
string label, IDictionary<string, object?> args, bool keepResources)
|
2019-10-26 01:59:50 +02:00
|
|
|
|
{
|
2020-10-27 18:12:12 +01:00
|
|
|
|
var result = await SerializeFilteredPropertiesAsync(label, args, _ => true, keepResources).ConfigureAwait(false);
|
2019-10-26 01:59:50 +02:00
|
|
|
|
return result.Serialized;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="SerializeFilteredPropertiesAsync"/> walks the props object passed in,
|
|
|
|
|
/// awaiting all interior promises for properties with keys that match the provided filter,
|
|
|
|
|
/// creating a reasonable POCO object that can be remoted over to registerResource.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static async Task<SerializationResult> SerializeFilteredPropertiesAsync(
|
2020-10-27 18:12:12 +01:00
|
|
|
|
string label, IDictionary<string, object?> args, Predicate<string> acceptKey, bool keepResources)
|
2019-10-26 01:59:50 +02:00
|
|
|
|
{
|
|
|
|
|
var propertyToDependentResources = ImmutableDictionary.CreateBuilder<string, HashSet<Resource>>();
|
|
|
|
|
var result = ImmutableDictionary.CreateBuilder<string, object>();
|
|
|
|
|
|
2019-11-21 06:40:38 +01:00
|
|
|
|
foreach (var (key, val) in args)
|
2019-10-26 01:59:50 +02:00
|
|
|
|
{
|
|
|
|
|
if (acceptKey(key))
|
|
|
|
|
{
|
|
|
|
|
// We treat properties with null values as if they do not exist.
|
|
|
|
|
var serializer = new Serializer(_excessiveDebugOutput);
|
2020-10-27 18:12:12 +01:00
|
|
|
|
var v = await serializer.SerializeAsync($"{label}.{key}", val, keepResources).ConfigureAwait(false);
|
2019-10-26 01:59:50 +02:00
|
|
|
|
if (v != null)
|
|
|
|
|
{
|
|
|
|
|
result[key] = v;
|
|
|
|
|
propertyToDependentResources[key] = serializer.DependentResources;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new SerializationResult(
|
|
|
|
|
Serializer.CreateStruct(result.ToImmutable()),
|
|
|
|
|
propertyToDependentResources.ToImmutable());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private struct SerializationResult
|
|
|
|
|
{
|
|
|
|
|
public readonly Struct Serialized;
|
|
|
|
|
public readonly ImmutableDictionary<string, HashSet<Resource>> PropertyToDependentResources;
|
|
|
|
|
|
|
|
|
|
public SerializationResult(
|
|
|
|
|
Struct result,
|
|
|
|
|
ImmutableDictionary<string, HashSet<Resource>> propertyToDependentResources)
|
|
|
|
|
{
|
|
|
|
|
Serialized = result;
|
|
|
|
|
PropertyToDependentResources = propertyToDependentResources;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Deconstruct(
|
|
|
|
|
out Struct serialized,
|
|
|
|
|
out ImmutableDictionary<string, HashSet<Resource>> propertyToDependentResources)
|
|
|
|
|
{
|
|
|
|
|
serialized = Serialized;
|
|
|
|
|
propertyToDependentResources = PropertyToDependentResources;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|