Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always apply schema level secrets #286

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Jan 13, 2025

This will resolve pulumi/pulumi-docker-build#403 when pulumi-docker-build upgrades to this version.

@iwahbe iwahbe requested review from thomas11, t0yv0 and a team January 13, 2025 18:41
@@ -933,7 +942,6 @@ func callCustomCheck[T any](
//
// It also adds defaults to inputs as necessary, as defined by [Annotator.SetDefault].
func DefaultCheck[I any](ctx context.Context, inputs resource.PropertyMap) (I, []p.CheckFailure, error) {
inputs = applySecrets[I](inputs)
Copy link
Member

@t0yv0 t0yv0 Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on maybe leaving this as is? Doing it twice is no harm?

Perhaps as an undocumented behavior of the exported DefaultCheck it's ok to remove it though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller of DefaultCheck only witnesses the effects of applySecrets[I] here when they see values that were previously secret show up as secret again (in the returned value of Check).

This doesn't change observable behavior from the user's perspective (except that applySecrets[I] covers values added in CustomCheck.Check, the goal of the PR).

var r R
if r, ok := ((interface{})(r)).(CustomCheck[I]); ok {
// The user implemented check manually, so call that.
//
// We do not apply defaults or secrets if the user has implemented Check
// themselves. Defaults and secrets are applied by [DefaultCheck].

defCheckEnc, i, failures, err := callCustomCheck(ctx, r, req.Urn.Name(), req.Olds, req.News)
backupEncoder, _, _, _ := decodeCheckingMapErrors[I](req.News)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure failures, err need no handling here?

What if the backupEncoder moves under this if block:

if encoder == nil {
			encoder = &backupEncoder
}

So as to compute it lazily if really needed, and it that case still may handle the error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 - it may be correct now but doesn't look robust

Copy link
Member Author

@iwahbe iwahbe Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure failures, err need no handling here?

I'll explain why in a comment. The tldr is: the backup encoder might not be derived from a shape that matches the shape of I, so it might not fit correctly. It will encode correctly without prior information (excluding marker types).

var r R
if r, ok := ((interface{})(r)).(CustomCheck[I]); ok {
// The user implemented check manually, so call that.
//
// We do not apply defaults or secrets if the user has implemented Check
// themselves. Defaults and secrets are applied by [DefaultCheck].

defCheckEnc, i, failures, err := callCustomCheck(ctx, r, req.Urn.Name(), req.Olds, req.News)
backupEncoder, _, _, _ := decodeCheckingMapErrors[I](req.News)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 - it may be correct now but doesn't look robust

infer/tests/check_test.go Show resolved Hide resolved
This will resolve pulumi/pulumi-docker-build#403 when
pulumi-docker-build upgrades to this version.
@iwahbe iwahbe force-pushed the iwahbe/always-apply-schema-level-secrets branch from 1401699 to 768c3fc Compare January 14, 2025 10:16
Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 53.57143% with 13 lines in your changes missing coverage. Please review.

Project coverage is 69.17%. Comparing base (eb05f00) to head (768c3fc).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
infer/resource.go 42.10% 9 Missing and 2 partials ⚠️
infer/tests/provider.go 60.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #286   +/-   ##
=======================================
  Coverage   69.17%   69.17%           
=======================================
  Files          37       37           
  Lines        5109     5116    +7     
=======================================
+ Hits         3534     3539    +5     
- Misses       1306     1308    +2     
  Partials      269      269           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@iwahbe iwahbe merged commit 7854e52 into main Jan 14, 2025
8 checks passed
@iwahbe iwahbe deleted the iwahbe/always-apply-schema-level-secrets branch January 14, 2025 10:38
@pulumi-bot
Copy link

This PR has been shipped in release v0.24.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ACTIONS_RUNTIME_TOKEN leak
4 participants