Commit Graph

40 Commits

Author SHA1 Message Date
Paul C. Roberts f0fffe6fb2
Better error messages for schema validation ()
This PR improves the error messages produced during project schema
validation so that, where possible, we suggest valid attribute names
that the user may have meant to type. For instance, if they provide a
"Name" attribute where we wanted "name" (lowercase "n"), we'll now say
so. Where there is not a close match, we'll enumerate the full list of
valid names to try and guide the user.

Matching is implemented using Levenshtein distances and ignores case.
Some examples of the new functionality:

* `{"Name": ...}` yields `project is missing a 'name' attribute; found
'Name' instead`
* `{..., "rutnime": ...}` yields `project is missing a 'runtime'
attribute; found 'rutnime' instead`
* `{..., "template": {"displayNameDisplayName": ...}, ...}` yields
`'displayNameDisplayName' not allowed; the allowed attributes are
'config', 'description', 'displayName', 'important', 'metadata' and
'quickstart'`

Co-authored-by: Will Jones <will@sacharissa.co.uk>
2024-06-14 09:03:22 +00:00
Fraser Waters b6645b372f
Lift context parameter for ApplyProjectConfig ()
<!--- 
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. -->

`mergeConfig` uses `Crypter.Encrypt` that needs a context and was using
`context.TODO()`. This lifts that to a context parameter and fixes up
all call sites.

## 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
  - [ ] 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. -->
2024-04-22 06:37:34 +00:00
Fraser Waters 3560333ae6
Clean up uses of .Error() ()
Combination of a few cleanups.

1. Don't call .Error() on errors that are being passed to "%s" format
functions. Format will call `Error()` itself.
2. Don't call assert.Error then assert.Equal/Contains, just use
assert.ErrorEqual/ErrorContains instead.
3. Use "%w" if appropriate, instead of "%v"/"%s".
2023-12-20 15:54:06 +00:00
Fraser Waters 797ab3d099
Replace some more uses of assert.Contains(err.Error()) with assert.ErrorContains () 2023-12-15 17:45:32 +00:00
Fraser Waters 0f4ddc2ccf
Use EqualError/ErrorContains instead of Error ()
<!--- 
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 is a pass over all of /sdk to replace asserts that just checked we
had an error with asserts for what the error value is.

Just checking for an error is a weak test that can result in error paths
being broken and tests not detecting it.
2023-12-08 06:40:14 +00:00
Pat Gavlin 064fb93587
[esc] Add commands for managing stack environments ()
These changes add two commands for managing a stack's environments:

- `pulumi config env add`, which adds environments to a stack's import
list
- `pulumi config env rm`, which removes an environment from a stack's
import list

As implied by their paths, these commands hang off of a new sub-command
of `pulumi config`, `pulumi config env`.

From the usage:

* `pulumi config env add`

Adds environments to the end of a stack's import list. Imported
environments are merged in order per the ESC merge rules. The list of
stacks behaves as if it were the import list in an anonymous
environment.

* `pulumi config env rm`

Removes an environment from a stack's import list.

Each of these commands previews the new stack environment and shows the
environment definition. These commands print a warning if the stack's
environment does not define any of the `environmentVariables`, `files`,
or `pulumiConfig` properties.
2023-11-22 05:04:14 +00:00
Pat Gavlin 4d3b82cb9f
[cli] Add support for environments ()
These changes add support for ESC environments to the Pulumi CLI. This
involves two major changes:

- Support for the `env` subcommand
- Support for the `environment` stanza in stack config files

The former reuses the command from `esc` itself with a little
rebranding.

The latter adds support to stack config files for an `environment`
property of the form:

```yaml
environment:
  - list
  - of
  - environment
  - names
```

If this property is present in a stack's config file, the CLI will open
the and merge the listed environments during `pulumi up` et. al. If an
object-valued `pulumiConfig` property is present in the opened
environment, its values will be merged on top of the stack's config
prior to whatever operation is to be performed. If an object-valued
`environmentVariables` property is present inthe opened environment, its
values will be published as environment variables prior to the Pulumi
operation. Any values in the open environment's `pulumiConfig` or
`environmentVariables` that are marked as secret will be encrypted in
the resulting config and will be filtered from the command's logs.
2023-10-10 01:35:39 +00:00
Fraser Waters a8c46416a0 Test project roundtrips 2023-03-07 09:42:56 +00: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
Abhinav Gupta 1158d4acee
all: Drop ioutil
Stop using io/ioutil across the entire repository.
The io/ioutil package was deprecated in Go 1.16 (2021-02)
with replacements provided in other packages.
Specifically:

    ioutil.Discard   => io.Discard
    ioutil.NopCloser => io.NopCloser
    ioutil.ReadAll   => io.ReadAll
    ioutil.ReadFile  => os.ReadFile
    ioutil.TempDir   => os.MkdirTemp
    ioutil.TempFile  => os.CreateTemp
    ioutil.WriteFile => os.WriteFile

This change switches all of these entities
across the repository.

Following this change,
the only references to ioutil are in schema files:

    % rg -l ioutil
    pkg/codegen/testing/test/testdata/aws-4.26.0.json
    pkg/codegen/testing/test/testdata/aws-4.36.0.json
    pkg/codegen/testing/test/testdata/aws-4.37.1.json
    pkg/codegen/testing/test/testdata/aws-5.4.0.json
    pkg/codegen/testing/test/testdata/aws-5.16.2.json

The bulk of this change was generated automatically
with manual touch ups afterwards.
2023-01-06 16:35:14 -08:00
Aaron Friel f5ca60dccc ci: adjust test based on new yaml library 2022-12-10 14:26:14 -08:00
Zaid Ajaj 88558b271b typing made optional in hierarchical config and relaxed stack config validation 2022-10-30 23:42:39 +01:00
Fraser Waters ea609d546f Add 'secret' to config
Also separate the validation and merging of project-to-stack values, to
allow us to apply in values even if they're secure and we don't have an
available decrypter. We can't validate that they're all correct, but it
means at least `config get` can do a best effort retrival for config
values.
2022-10-24 09:22:24 +01:00
Zaid Ajaj c60675790e fix TestProjectLoadYAML expected error messages 2022-10-12 16:01:49 +02:00
Zaid Ajaj 0766b866a6 Merge branch 'master' into minimal-config 2022-10-12 15:38:21 +02:00
Fraser Waters 800e6b4b53 Wrap project load errors with the path that failed 2022-10-09 12:08:05 +01:00
Fraser Waters dae83dd53c Improve the error message for Pulumi.yaml with wrong type of data
"expected an object" isn't very informative, "expected project to be an object, was 'string'" is much better.
2022-10-07 18:14:32 +01:00
Zaid Ajaj c739adbe7c Fix tests that have incomplete project config. Correct docs for CreatePulumiRepo 2022-10-04 21:29:42 +02:00
Zaid Ajaj 9a9a39bbf9 Make sure config defined by a stack are also defined by the project + a whole bunch of tests 2022-10-04 21:13:43 +02:00
Zaid Ajaj fbc68cb644 Project namespace is now optional when defining stack config 2022-09-26 12:30:55 +02:00
Zaid Ajaj 5bd9b80256 namespaced config values don't need the project as root namespace 2022-09-24 14:51:08 +02:00
Zaid Ajaj 0498be116b Rewrite config to stackConfigDir when provided as string 2022-09-24 14:32:11 +02:00
Zaid Ajaj 7975498b71 lint 2022-09-22 18:27:08 +02:00
Zaid Ajaj d419605d1b Moaar unit tests for config validation 2022-09-22 17:32:18 +02:00
Zaid Ajaj 6531b668fd test config schemas that use short hand version 2022-09-22 10:27:27 +02:00
Zaid Ajaj 6c6b5cec7e Initial work on project-level config (MVP) 2022-09-20 20:13:45 +02:00
Fraser Waters 05f75b7315 lint 2022-09-16 17:24:34 +01:00
Fraser Waters 95e703bcdd Fix json test 2022-09-16 17:05:40 +01:00
Fraser Waters 735314d51a Handle nulls 2022-09-16 16:38:14 +01:00
Fraser Waters 80ae4f49f7 Fix backend schema 2022-09-02 19:38:22 +01:00
Fraser Waters 75f4b821e6 lint 2022-09-02 19:12:57 +01:00
Fraser Waters 49d6ef0db9 Validate as part of Load not Unmarshal 2022-09-02 18:26:49 +01:00
Fraser Waters 5b1917550b wip 2022-09-02 18:26:49 +01:00
Fraser Waters 10205c46b9 Fix yaml parsing 2022-09-02 18:26:49 +01:00
Fraser Waters 23f0240204 lint 2022-09-02 10:35:14 +01:00
Fraser Waters 5ff65320e2 Use project schema to validate projects we load 2022-09-02 10:09:24 +01:00
Aaron Friel c8d3bd16c8
Revert "[cli] Allow Pulumi.yaml files to contain additional, preserved keys" ()
This reverts commit 8441ea2eee.
2022-08-15 10:36:33 -07:00
Aaron Friel 8441ea2eee [cli] Allow Pulumi.yaml files to contain additional, preserved keys 2022-08-09 13:20:49 -07:00
Aaron Friel ed2923653c ci: radical idea - what if slow tests & no stdout makes GH consider runner dead? 2022-03-06 14:52:13 -08:00
evanboyle 8fb3f428b0 move pkg/workspace -> sdk/go/common/workspace 2020-03-18 14:35:53 -07:00