Commit Graph

114 Commits

Author SHA1 Message Date
Ian Wahbe 541721f844
Fix a typo () 2024-08-07 13:23:32 +00:00
Fraser Waters 4cf62528c2
Fix marshalling of plain properties ()
Fixes https://github.com/pulumi/pulumi/issues/16810.

The container types already marshalled correctly here, but other types
like refs and primitives didn't keep their Plain attribute.
2024-07-26 21:36:22 +00:00
Fraser Waters 26f70d4780
Change parameterization in schemas to base64 strings ()
Follow on to https://github.com/pulumi/pulumi/pull/16606. Allow the
schema to express any bytes value.

---------

Co-authored-by: Julien <julien@caffeine.lu>
2024-07-10 15:36:05 +00:00
Florian Stadler 74e8928cff
Add ability to constrain supported languages of resource and function overlays ()
The existing overlays (e.g. Chart v3 in Kubernetes, or CallbackFunction
in AWS) are not available in every language Pulumi supports. This often
confuses users because the generated docs include all languages Pulumi
supports (e.g. see
https://github.com/pulumi/pulumi-kubernetes/issues/2181).

To solve that problem, this change adds a new optional parameter to the
schema that allows configuring the languages an overlay (resource or
function) supports.
To support this in docsgen the existing Language Chooser
(`LangChooserLanguages`) of resources is made configurable and extended
to functions.

Note: This doesn't support resource methods right now. They'll need
extra handling because and overlay resource method might not support all
of the languages its resource supports. I'll tackle this in a follow up
PR.

Here's a screenshot of how this will look like for the Helm v3 chart for
example:
<img width="1046" alt="Screenshot 2024-07-01 at 16 11 23"
src="https://github.com/pulumi/pulumi/assets/2453580/b1a1365a-6dee-4099-829a-2859639a4c8c">

The PR contains the following commits. I'd recommend to look at the
first three ones and then check the regenerated golden files in the last
one:
- **Add schema parameter to constrain supported languages for overlays**
- **Update developer docs and changelog**
- **Refactor LanguageChooser and always pass supported languages**
- **Regenerate testdata**

relates to 
2024-07-09 14:54:50 +00:00
Fraser Waters 22b9faa1d0
Add Paramaterization to the Pulumi schema ()
This adds the parameterisation spec to the pulumi schema. This will
allow providers to take a dependency on these types to start defining
parameterized schemes from tfbridge.

They _should not_ be considered completely stable. We may still need to
change things here as work continues.
2024-07-02 10:29:39 +00:00
coderwander 93748ad958
chore: fix some comments ()
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

Fix some names in comments to match the attached code names.

Signed-off-by: coderwander <770732124@qq.com>
2024-04-16 07:21:22 +00:00
Aaron Friel e211f2e3d4
feat: declare a new type for 'any resource' ()
This commit exists to enable the Java SDK to update and use it, which
then unblocks the next commit passing tests.

Part of 

---------

Co-authored-by: Eron Wright <eron@pulumi.com>
2024-04-09 07:59:16 +00:00
Fraser Waters 3043adeeb3
Add SupportPack to schemas to write out in the new style ()
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->


This adds a new flag to the schema metadata to tell codegen to use the
new proposed style of SDKs where we fill in versions and write go.mods
etc.

I've reworked pack to operate on packages assuming they're in this new
style. That is pack no longer has the responsibility to fill in any
version information.

This updates python and node codegen to write out SDKs in this new
style, and fixes their core libraries to still be buildable via pack.
There are two approaches to fixing those, I've chosen option 1 below but
could pretty easily rework for option 2.

1) Write the version information directly to the SDKs at the same time
as we edit the .version file. To simplify this I've added a new
'set-version.py' script that takes a version string an writes it to all
the relevant places (.version, package.json, etc).

2) Write "pack" in the language host to search up the directory tree for
the ".version" file and then fill in the version information as we we're
doing before with envvar tricks and copying and editing package.json.

I think 1 is simpler long term, but does force some amount of cleanup in
unrelated bits of the system right now (release makefiles need a small
edit). 2 is much more localised but keeps this complexity that
sdk/nodejs sdk/python aren't actually valid source modules.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-03-22 09:25:46 +00:00
Fraser Waters f8e821c861
Fix a datarace ()
Seen while running tests for another PR:
https://github.com/pulumi/pulumi/actions/runs/7639934341/job/20814238592?pr=15232

```
WARNING: DATA RACE
Read at 0x00c0009e8480 by goroutine 46:
  github.com/pulumi/pulumi/pkg/v3/codegen/schema.(*Package).TokenToModule()
      /home/runner/work/pulumi/pulumi/pkg/codegen/schema/schema.go:873 +0x13e
  github.com/pulumi/pulumi/pkg/v3/codegen/schema.packageDefRef.TokenToModule()
      /home/runner/work/pulumi/pulumi/pkg/codegen/schema/package_reference.go:171 +0x84
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.canonicalizeToken()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_schema.go:181 +0x10d
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*packageSchema).initResourceMap()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_schema.go:111 +0x124
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*packageSchema).LookupResource()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_schema.go:84 +0xf7
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*binder).bindResourceTypes()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_resource.go:197 +0xeb8
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*binder).bindResource()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_resource.go:37 +0x79
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*binder).bindNode()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_nodes.go:62 +0x819
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.BindProgram()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder.go:219 +0x1a31
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.TestBindResourceOptions.func1()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_resource_test.go:104 +0x6f8
  testing.tRunner()
      /opt/hostedtoolcache/go/1.21.5/x64/src/testing/testing.go:1595 +0x261
  testing.(*T).Run.func1()
      /opt/hostedtoolcache/go/1.21.5/x64/src/testing/testing.go:1648 +0x44

Previous write at 0x00c0009e8480 by goroutine 42:
  github.com/pulumi/pulumi/pkg/v3/codegen/schema.(*Package).TokenToModule()
      /home/runner/work/pulumi/pulumi/pkg/codegen/schema/schema.go:874 +0x17c
  github.com/pulumi/pulumi/pkg/v3/codegen/schema.packageDefRef.TokenToModule()
      /home/runner/work/pulumi/pulumi/pkg/codegen/schema/package_reference.go:171 +0x84
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.canonicalizeToken()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_schema.go:181 +0x10d
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*packageSchema).initResourceMap()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_schema.go:111 +0x124
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*packageSchema).LookupResource()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_schema.go:84 +0xf7
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*binder).bindResourceTypes()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_resource.go:197 +0xeb8
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*binder).bindResource()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_resource.go:37 +0x79
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.(*binder).bindNode()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_nodes.go:62 +0x819
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.BindProgram()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder.go:219 +0x1a31
  github.com/pulumi/pulumi/pkg/v3/codegen/pcl.TestBindResourceOptions.func1()
      /home/runner/work/pulumi/pulumi/pkg/codegen/pcl/binder_resource_test.go:104 +0x6f8
  testing.tRunner()
      /opt/hostedtoolcache/go/1.21.5/x64/src/testing/testing.go:1595 +0x261
  testing.(*T).Run.func1()
      /opt/hostedtoolcache/go/1.21.5/x64/src/testing/testing.go:1648 +0x44
```
2024-01-24 15:33:42 +00:00
Zaid Ajaj 4ec6d6057b
[schema] Fix package get-schema marking resource properties as plain ()
# Description

Follow up for  because when I tried it against existing providers
as follows:
```
~/.pulumi-dev/bin/pulumi package get-schema random
```
It marks all resource properties as plain even when they are not. This
PR fixes it and extends the unit test to assert both plain and non-plain
properties of resources and object types

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-12-01 19:41:51 +00:00
Zaid Ajaj 5e5357d259
[schema] Fixes marshalling the "plain" flag from object or resource properties ()
# Description

When marshalling a schema that has resources or types with plain
properties, the `plain` flag was not preserved. This PR fixes it and
adds a roundtrip test for the plain properties.

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-27 11:05:03 +00:00
Anton Tayanovskyy ba039c20f8
Support returning plain values from methods ()
Support returning plain values from methods.

Implements Node, Python and Go support.

Remaining:

- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
   - [x] https://github.com/pulumi/pulumi-yaml/issues/499
   - [x] https://github.com/pulumi/pulumi-java/issues/1193
   - [x] https://github.com/pulumi/pulumi-dotnet/issues/170 

Known limitations:

- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true

- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing

- resources cannot return plain values yet

- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet

<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

Fixes https://github.com/pulumi/pulumi/issues/12709

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
Zaid Ajaj d90aef60f9
[go/sdk-gen] Generate output-versioned invokes for functions without inputs ()
# Description

Partially addressing  implements output-versioned invokes for
functions without inputs for go.


## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-10-02 12:53:06 +00:00
Justin Van Patten 5e19f60665
Correctly roundtrip enums in schema marshalling ()
The code to marshal an enum was not keeping the enum's comment.

Fixes 
2023-09-12 18:34:40 +00:00
Fraser Waters 94dfb68c56 Correctly roundtip overlay type tokens in schema marshalling
Fixes https://github.com/pulumi/pulumi/issues/13671.

The code to marshal a TokenType back to a `$ref` simple copied the token
across, but that didn't correctly reconstruct the URL that `$ref`s
expect.
2023-08-08 19:28:51 +01:00
Fraser Waters dd376a7475 Fix ReplaceOnChanges being dropped in schema marshalling
Fixes https://github.com/pulumi/pulumi/issues/13492.
2023-07-18 14:19:51 +01:00
Fraser Waters 571fadae3f Use slice.Prealloc instead of make([]T, 0, ...)
Fixes https://github.com/pulumi/pulumi/issues/12738

https://github.com/pulumi/pulumi/pull/11834 turned on the prealloc
linter and changed a load of slice uses from just `var x T[]` to `x :=
make([]T, 0, preallocSize)`. This was good for performance but it turns
out there are a number of places in the codebase that treat a `nil`
slice as semnatically different to an empty slice.

Trying to test that, or even reason that through for every callsite is
untractable, so this PR replaces all expressions of the form `make([]T,
0, size)` with a call to `slice.Prealloc[T](size)`. When size is 0 that
returns a nil array, rather than an empty array.
2023-06-29 11:27:50 +01:00
Fraser Waters 0a33b66692 Fix version number in typerefs when marshalling schemas
Fixes https://github.com/pulumi/pulumi/issues/13000
2023-05-24 08:16:20 +01:00
bors[bot] f43c92b05e
Merge
12459: Remove mutually exclusion between ReturnType and Outputs. r=RobbieMcKinstry a=RobbieMcKinstry

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

This commit removes an assertion in schema JSON marshaling that function return types are mutually exclusive with Outputs. This assertion was false; in practice, packages like AWS and DigitalOcean both have functions that provide both ReturnType and Outputs (perhaps inadvisedly). This assertion broke the `package get-schema` subcommand. _e.g._, `pulumi package get-schema aws@5.24.0` or
`pulumi package get-schema digitalocean@4.19.0`. Removing this assertion restored this functionality.
Examples of functions that provide both a ReturnType and Outputs:
* `DigitalOcean.get_account()`
* `DigitalOcean.get_app()`
* `DigitalOcean.get_certificate()`
* `aws.ses.getDomainIdentity()`

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes https://github.com/pulumi/pulumi/issues/12457

**Question:** Any tips on how to add a regression test to prevent this class of bug again? In this case, any kind of regression test against a major provider would have caught this bug; I don't think many users use `get-schema` but it looks like it was probably broken for about two months without anyone noticing.

Also, I'm not well versed enough in PCL/schemaland to verify the correctness of the initial assertion. This fix could be trivializing a more sophisticated issue. Please let me know if there's a "bigger iceberg" here that I'm missing :) 

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Robbie McKinstry <robbie@pulumi.com>
2023-04-05 14:24:56 +00:00
Daniel Bradley 6e0dafae29
Fix documentation of valid schema type strings 2023-03-28 21:43:35 +01:00
Abhinav Gupta acda1e3b13
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.

Full list of issues:

**pkg**

```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```

**sdk**

```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```

**tests**

```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-21 08:55:11 -07:00
Robbie McKinstry 764ad59ca9
Remove mutually exclusion between ReturnType and Outputs.
This commit removes an assertion in schema JSON marshalling that function
return types are mutually exclusive with Outputs. This assertion was
false; in practice packages like AWS and DigitalOcean both has functions
that provide both ReturnType and Outputs (perhaps inadvisedly).
This assertion broke the `package get-schema` subcommand. E.g.
`pulumi package get-schema aws@5.24.0` or
`pulumi package get-schema digitalocean@4.19.0`. Removing this assertion
restored this functionality.
Examples of functions that provide both a ReturnType and Outputs:
* `DigitalOcean.get_account()`
* `DigitalOcean.get_app()`
* `DigitalOcean.get_certificate()`
* `aws.ses.getDomainIdentity()`
2023-03-20 16:18:02 -04:00
Abhinav Gupta acaf79bc10
all: Drop //nolint:goconst
Drops the nolint:goconst directive
now that the goconst linter is no longer enabled.
2023-03-09 11:15:21 -08:00
Abhinav Gupta 7aa5b77a0c
all: Reformat with gofumpt
Per team discussion, switching to gofumpt.

[gofumpt][1] is an alternative, stricter alternative to gofmt.
It addresses other stylistic concerns that gofmt doesn't yet cover.

  [1]: https://github.com/mvdan/gofumpt

See the full list of [Added rules][2], but it includes:

- Dropping empty lines around function bodies
- Dropping unnecessary variable grouping when there's only one variable
- Ensuring an empty line between multi-line functions
- simplification (`-s` in gofmt) is always enabled
- Ensuring multi-line function signatures end with
  `) {` on a separate line.

  [2]: https://github.com/mvdan/gofumpt#Added-rules

gofumpt is stricter, but there's no lock-in.
All gofumpt output is valid gofmt output,
so if we decide we don't like it, it's easy to switch back
without any code changes.

gofumpt support is built into the tooling we use for development
so this won't change development workflows.

- golangci-lint includes a gofumpt check (enabled in this PR)
- gopls, the LSP for Go, includes a gofumpt option
  (see [installation instrutions][3])

  [3]: https://github.com/mvdan/gofumpt#installation

This change was generated by running:

```bash
gofumpt -w $(rg --files -g '*.go' | rg -v testdata | rg -v compilation_error)
```

The following files were manually tweaked afterwards:

- pkg/cmd/pulumi/stack_change_secrets_provider.go:
  one of the lines overflowed and had comments in an inconvenient place
- pkg/cmd/pulumi/destroy.go:
  `var x T = y` where `T` wasn't necessary
- pkg/cmd/pulumi/policy_new.go:
  long line because of error message
- pkg/backend/snapshot_test.go:
  long line trying to assign three variables in the same assignment

I have included mention of gofumpt in the CONTRIBUTING.md.
2023-03-03 09:00:24 -08:00
bors[bot] 8915911825
Merge
11819: Cleanup diag error for protected resources r=dixler a=iwahbe

Change the error message for deleting protected resources so it sounds less like we tried and failed to delete the resource, and more like we chose not to. 

Fixes 


11834: Preallocate slices with a known capacity. r=dixler a=RobbieMcKinstry

Enable the prealloc linter, which identifies slices with a known capacity, but are not preallocated, which results in unnecessary allocations and memcpys.

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] N/A: enabling a linter. I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] **N/A: not a user-facing change.** I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


11842: Changelog and go.mod updates for v3.51.1 r=dixler a=justinvp



11845: Move SecretsProvider to pkg/secrets r=dixler a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Trying to push DefaultSecretsProvider up past the backends resulted in a module loop between pkg/resource/stack and pkg/resource/deploy. This places SecretProvider in the secrets module to avoid that.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works - N/A Just moving interface declaration 
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change - N/A Internal code changes
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version - No
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Ian Wahbe <ian@wahbe.com>
Co-authored-by: Robbie McKinstry <robbie@pulumi.com>
Co-authored-by: Abhinav Gupta <abhinav@pulumi.com>
Co-authored-by: Robbie McKinstry <thesnowmancometh@gmail.com>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Fraser Waters <fraser@pulumi.com>
2023-01-12 20:11:42 +00:00
Robbie McKinstry 4959522a53
Repair tests expecting nil slices 2023-01-11 21:53:04 -08:00
Zaid Ajaj 330676a0d0 Initial implementation of simplified invokes for dotnet and nodejs 2023-01-11 14:17:14 -08:00
Robbie McKinstry 1f78baae71
Preallocate slices with a known capacity.
Enable the prealloc linter, which identifies slices
with a known capacity, but are not preallocated, which
results in unnecessary allocations and memcpys.
2023-01-11 12:52:51 -08:00
Abhinav Gupta 0bff0b8716 sdk/go: Remove 'nolint' directives from package docs
Go treats comments that match the following regex as directives.

    //[a-z0-9]+:[a-z0-9]

Comments that are directives don't show in an entity's documentation.
5a550b6951 (diff-f56160fd9fcea272966a8a1d692ad9f49206fdd8dbcbfe384865a98cd9bc2749R165)

Our code has `//nolint` directives that now show in the API Reference.
This is because these directives are in one of the following forms,
which don't get this special treatment.

    // nolint:foo
    //nolint: foo

This change fixes all such directives found by the regex:
`// nolint|//nolint: `.
See bottom of commit for command used for the fix.

Verification:
Here's the output of `go doc` on some entities
before and after this change.

Before
```
% go doc github.com/pulumi/pulumi/sdk/v3/go/pulumi | head -n8
package pulumi // import "github.com/pulumi/pulumi/sdk/v3/go/pulumi"

nolint: lll, interfacer

nolint: lll, interfacer

const EnvOrganization = "PULUMI_ORGANIZATION" ...
var ErrPlugins = errors.New("pulumi: plugins requested")
```

After
```
% go doc github.com/pulumi/pulumi/sdk/v3/go/pulumi | head -n8
package pulumi // import "github.com/pulumi/pulumi/sdk/v3/go/pulumi"

const EnvOrganization = "PULUMI_ORGANIZATION" ...
var ErrPlugins = errors.New("pulumi: plugins requested")
func BoolRef(v bool) *bool
func Float64Ref(v float64) *float64
func IntRef(v int) *int
func IsSecret(o Output) bool
```

Before
```
% go doc github.com/pulumi/pulumi/sdk/v3/go/pulumi URN_
package pulumi // import "github.com/pulumi/pulumi/sdk/v3/go/pulumi"

func URN_(o string) ResourceOption
    URN_ is an optional URN of a previously-registered resource of this type to
    read from the engine. nolint: revive
```

After:
```
% go doc github.com/pulumi/pulumi/sdk/v3/go/pulumi URN_
package pulumi // import "github.com/pulumi/pulumi/sdk/v3/go/pulumi"

func URN_(o string) ResourceOption
    URN_ is an optional URN of a previously-registered resource of this type to
    read from the engine.
```

Note that golangci-lint offers a 'nolintlint'  linter
that finds such miuses of nolint,
but it also finds other issues so I've deferred that to a follow up PR.

Resolves 

Related: https://github.com/golangci/golangci-lint/issues/892

[git-generate]
FILES=$(mktemp)
rg -l '// nolint|//nolint: ' |
  tee "$FILES" |
  xargs perl -p -i -e '
    s|// nolint|//nolint|g;
    s|//nolint: |//nolint:|g;
  '
rg '.go$' < "$FILES" | xargs gofmt -w -s
2023-01-06 09:06:47 -08:00
Aaron Friel a682a1ab06
Revert "Simplified invokes: SDK-gen and program-gen implementation for dotnet and nodejs" 2022-12-20 17:47:29 -08:00
Zaid Ajaj a6f26d2355 Initial implementation of simplified invokes for dotnet and nodejs 2022-12-16 13:39:03 +01:00
Ian Wahbe 878cf9055a Delete `*Package` fields from schema types
Fix NeedsGoOutputVersion.
2022-12-14 10:29:30 +01:00
bors[bot] c11a8ebb30
Merge
11596: [sdk/gen] Avoid generating Result types for functions with empty outputs r=Zaid-Ajaj a=Zaid-Ajaj

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Part of  where we shouldn't generate result types for function invokes that have no properties. 

This is a separate PR to showcase the exact changes required to improve the situation and reduce the diff from 

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
2022-12-09 16:18:00 +00:00
Zaid Ajaj b0b4add2a6 Do not generate Result types for functions with empty outputs 2022-12-09 14:36:44 +01:00
Ian Wahbe 65b6b01abd Don't use *schema.Package in python codegen 2022-12-07 17:54:38 +01:00
Fraser Waters 7f99cbff01 Fix typo in error message 2022-11-09 16:30:08 +00:00
Ian Wahbe 453222555e Higher fidelity schema marshalling
I noticed this when trying to round-trip a schema out of a provider SDK
2022-10-24 16:16:13 -07:00
Aaron Friel a4b1d6b2a7 ci: gofmt 1.18+ clean 2022-09-21 09:48:39 -07:00
Ian Wahbe 8e7c799a2a
Omit more empty fields in PackageSpec () 2022-08-25 11:15:31 +02:00
Ian Wahbe e4cbb79e23
Include pkg reference in bound schema types ()
* Include type references in schema types

* Fix lint

* Fix enum tests
2022-06-23 16:27:44 -07:00
Pat Gavlin 5a96693d5b
[schema] Make PartialPackage concurrency-safe ()
This change is composed of two pieces: one to guard access to the binding
operations and their results using a mutex, and one to make the result of
PartialPackage.Snapshot safe to use concurrently.

The former set of changes is pretty straighforward, and just involves
adding a mutex and appropriate locking/unlocking around binding operations
and reads/writes from/to PartialPackage.def.

The latter change is a bit riskier. The result of PartialPackage.Snapshot
is a *Package. Prior to these changes, multiple calls to Snapshot would
return a pointer to the same Package value after updating its fields.
Becuase the *Package API is field-based instead of method-based, there is
no way to make the update itself concurrency-safe, as there's nowhere to
add locking, and it is not possible to atomically update some of the
fields that are being updated (e.g. slice-typed fields). After these
changes, each call to Snapshot will return a new copy of the package.
By far the riskiest part of this change is that pointer equality can no
longer be used with the result of Snapshot to determine whether or not
two *Package values are the same. To facilitate proper equality
comparison, these changes add Equals() and Identity() methods to the
*Package API. The former compares two *Packages; the latter returns a
stringified version of the *Package's name and version that can be used
as a map key.

Fixes .
2022-05-24 17:47:43 -07:00
Ian Wahbe c719a08f9b
Fix default handling for schema.UnionType.String ()
* Fix default handling for schema.UnionType.String

* Make test parallel
2022-05-24 15:05:16 -07:00
Pat Gavlin 36cbf572f4
[schema] Add support for on-demand binding. ()
These changes extend the public API of `pkg/codegen/schema` to support
on-demand binding of package members. On-demand binding is appropriate for
scenarios that do not require the entire package, especially those such as
program code generation or the YAML LSP server that require only specific
types/functions/etc.

The extensions to the public API consist of two new types and several new
methods. The most notable of these are `PackageReference` and
`Loader.LoadPackageReference`. The former provides the on-demand binding
interface, while the latter creates instances of the former (n.b. it was
my intent to make a breaking change to the signature of `Loader.LoadPackage`
s.t. it returns a `PackageReference`, but the circular dependency between
this Go module and those for YAML and Java prevented that change).

These changes _dramatically_ reduce the memory required to interace with
Pulumi Packages, and only require memory proportional to the number of
accessed package members. We may be able to improve on this in the future
by removing type/resource/function interning, which would allow those
values to be garbage collected at a granaular level rather than at a
package level. That is a more radical change, though, as it requires new
equality semantics for each of the affected types (some of which are
currently used as map keys).
2022-05-23 15:44:35 -07:00
Ian Wahbe b281b482dc
Pass through resource replacement in the schema ()
* Pass through resource replacement in the schema

* Add property

* Ignore files in .pytest_cache

* Remove .pytest_cache files

* Add a test + Fix
2022-05-17 13:59:47 -07:00
Pat Gavlin e6095194a9
[schema] Move the binder into its own file. ()
Just what it says on the tin.
2022-05-09 19:08:43 -07:00
Ian Wahbe 3015d6948a
Patch go plain input ()
* Revert , Leave sidechannel

* Associated test update

* Correct input Objects marked as plain

* Update associated tests

* Fix unused import import bug

* Restore type names test

* Correctly handle plain types with default methods

* Changelog

* Remove unused field
2022-04-29 09:54:42 -07:00
Ian Wahbe 9a8d8d928f
Correctly import plain types ()
* Add test case

* Correctly import plain types

* Update tests

* Update type_driver tests

* Update CHANGELOG_PENDING.md
2022-04-21 11:29:30 +02:00
Pat Gavlin 3b68ecc0fd
[codegen/schema] Do not validate in ImportSchema. ()
Allow consumers to load package specs without validating them against
the Pulumi package metaschema. This dramatically reduces the package
load time for scenarios in which packages can be assumed to be
well-formed (e.g. program codegen + packages that are referenced by a
root schema).

Fixes .
2021-12-15 15:02:14 -08:00
Ian Wahbe 6edcf25fd8
[codegen/schema] Add package name allowlist ()
* Add allowlist for package name tokens

* Update tests

* Add changelog

* Add same name/file intercept test

* Add test for foreign enum

* Make naming uniform
2021-12-07 21:21:04 -08:00
Ian Wahbe 3bee4804d7
[codegen/schema] forbid bad schema prefix ()
* Forbid type tokens with an invalid prefix

* Add unit tests

* Fix integration tests

* Update CHANGELOG_PENDING.md

* Update tests

* Fix lint
2021-12-06 11:35:27 -08:00