Skip to content

Commit

Permalink
Merge #10840
Browse files Browse the repository at this point in the history
10840: [codegen/dotnet] Fix codegen for functions with secret parameters r=justinvp a=justinvp

The non-`Output<T>` returning functions take parameters as plain values, which cannot be made secrets. Before this change, .NET codegen was trying to convert the inputs into secrets (for any input property that is marked as a `secret` in the schema), but this would error during compilation because the plain types are not `Input<T>`.

Note: Arguably, for the `Output<T>` returning functions, we could force any secret input properties to be secrets since they are typed as `Input<T>`, and similarly, force the resulting `Output<T>` to be a secret if any of the output properties are marked as secret. But that is something we could consider doing subsequently, as it would be a change for all languages. Tracking this in #10841.

Fixes #10838

Co-authored-by: Justin Van Patten <jvp@justinvp.com>
  • Loading branch information
bors[bot] and justinvp committed Sep 24, 2022
2 parents f1f841f + 94fef80 commit 255495e
Show file tree
Hide file tree
Showing 42 changed files with 2,333 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: sdkgen/dotnet
description: Fixes a .NET SDK codegen bug when emitting functions with secret parameters.
2 changes: 1 addition & 1 deletion pkg/codegen/dotnet/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ func (pt *plainType) genInputProperty(w io.Writer, prop *schema.Property, indent
fmt.Fprintf(w, "%s{\n", indent)
fmt.Fprintf(w, "%s get => %s;\n", indent, backingFieldName)
}
if prop.Secret {
if prop.Secret && isInputType(prop.Type) {
fmt.Fprintf(w, "%s set\n", indent)
fmt.Fprintf(w, "%s {\n", indent)
// Since we can't directly assign the Output from CreateSecret to the property, use an Output.All or
Expand Down
5 changes: 5 additions & 0 deletions pkg/codegen/testing/test/sdk_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ var PulumiPulumiSDKTests = []*SDKTest{
Description: "Generate a resource that outputs [][][]Foo",
Skip: allLanguages.Except("go/any"),
},
{
Directory: "functions-secrets",
// Secret properties for non-Output<T> returning functions cannot be secret because they are plain.
Description: "functions that have properties that are secrets in the schema",
},
}

var genSDKOnly bool
Expand Down
33 changes: 33 additions & 0 deletions pkg/codegen/testing/test/testdata/functions-secrets/docs/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: "mypkg"
title_tag: "mypkg.mypkg"
meta_desc: ""
layout: api
no_edit_this_page: true
---

<!-- WARNING: this file was generated by test. -->
<!-- Do not edit by hand unless you're certain you know what you are doing! -->



<h2 id="resources">Resources</h2>
<ul class="api">
<li><a href="provider" title="Provider"><span class="api-symbol api-symbol--resource"></span>Provider</a></li>
</ul>

<h2 id="functions">Functions</h2>
<ul class="api">
<li><a href="funcwithsecrets" title="FuncWithSecrets"><span class="api-symbol api-symbol--function"></span>FuncWithSecrets</a></li>
</ul>

<h2 id="package-details">Package Details</h2>
<dl class="package-details">
<dt>Repository</dt>
<dd><a href=""></a></dd>
<dt>License</dt>
<dd></dd>
<dt>Version</dt>
<dd>0.0.1</dd>
</dl>

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"emittedFiles": [
"_index.md",
"funcwithsecrets/_index.md",
"provider/_index.md"
]
}

Large diffs are not rendered by default.

0 comments on commit 255495e

Please sign in to comment.