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

chore: add readOnlyProperties to metadata #1898

Merged
merged 3 commits into from
Dec 11, 2024

Conversation

corymhall
Copy link
Contributor

This PR adds readOnlyProperties to the pulumi metadata. It also fixes
an issue with all properties (readOnly/createOnly/writeOnly) where
nested properties where not converted to the correct sdk name value.

@corymhall
Copy link
Contributor Author

corymhall commented Dec 10, 2024

This change is part of the following stack:

Change managed by git-spice.

Copy link
Contributor

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.36%. Comparing base (83e6a73) to head (4be1bc4).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1898      +/-   ##
==========================================
+ Coverage   49.29%   49.36%   +0.07%     
==========================================
  Files          46       47       +1     
  Lines        6804     6814      +10     
==========================================
+ Hits         3354     3364      +10     
  Misses       3206     3206              
  Partials      244      244              

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

provider/pkg/schema/resource_props_test.go Show resolved Hide resolved
// - `Foo/Bar/Baz` => `foo/bar/baz`
// - `Foo/*/BarBaz` => `foo/*/barBaz`
func (r *ResourceProperty) ToSdkName() string {
arrayProps := strings.Split(string(*r), "/*/")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would panic right now when called on an r that's nil.

Copy link
Member

Choose a reason for hiding this comment

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

contract.Assertf(r != nil, "ResourceProperty should not be nil")

panics are good sometimes - this should not be nil I think.

Copy link
Contributor

@flostadler flostadler Dec 11, 2024

Choose a reason for hiding this comment

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

I'd argue that the provider shouldn't crash on a panic and rather exit with a proper error message.
If this shouldn't be nil, then we shouldn't accept a nil as the input imo. From what I can tell we're actually using it on a regular string and not a pointer right now

Copy link
Member

Choose a reason for hiding this comment

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

That's a better idea. I checked around and this seems fine:

func (r ResourceProperty) ToSdkName() string

Copy link
Member

Choose a reason for hiding this comment

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

If you want to be more pedantic, which is not always bad, then this:

n := ResourceProperty(strings.TrimPrefix(v.(string), "/properties/"))

Should instead be:

parseResourceProperty(string) (ResourceProperty, error)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched it to not be a pointer receiver.

@@ -22,6 +22,7 @@ type CloudAPIResource struct {
AutoNamingSpec *AutoNamingSpec `json:"autoNamingSpec,omitempty"`
Required []string `json:"required,omitempty"`
CreateOnly []string `json:"createOnly,omitempty"`
ReadOnly []string `json:"readOnly,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Here is an opportunity for a documentation comment on what this is about and a few examples of how this data looks like, specifically that nested names will be separated by "/", and that the names themselves are using Pulumi notation e.g. groupArn. If array element separator is used (is it '*')? also good to document there. It is still a little weird that "/" is the separator but that we can live with.

Having a doc comment will save future maintainers some jumping around! Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some docs.

This PR adds `readOnlyProperties` to the pulumi metadata. It also fixes
an issue with all properties (`readOnly/createOnly/writeOnly`) where
nested properties where not converted to the correct sdk name value.
@corymhall corymhall force-pushed the corymhall/read-only-metadata branch from b7c6613 to 17d3bad Compare December 11, 2024 15:17
@corymhall corymhall enabled auto-merge (squash) December 11, 2024 15:21
@corymhall corymhall merged commit 7ca5a58 into master Dec 11, 2024
18 checks passed
@corymhall corymhall deleted the corymhall/read-only-metadata branch December 11, 2024 15:33
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.

3 participants