Commit Graph

21 Commits

Author SHA1 Message Date
Fraser Waters fe8f413b14
Fix JSON/YAML diffs ()
<!--- 
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/13981.

This regressed in https://github.com/pulumi/pulumi/pull/11803. I've
added tests to this PR to show both the value diffing and text diffing
for when the JSON/YAML string is different but the values are the same.

## 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.
-->
- [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. -->
2024-01-18 14:19:54 +00:00
Joe Duffy 96a9a77167
Policy remediations feature ()
This PR implements the new policy transforms feature, which allows
policy packs to not only issue warnings and errors in response to policy
violations, but actually fix them by rewriting resource property state.
This can be used, for instance, to auto-tag resources, remove Internet
access on the fly, or apply encryption to storage, among other use
cases.
2023-10-09 18:31:17 +00:00
Fraser Waters dd35a2a94f Fix diff display partially parsing JSON/YAML
Fixes https://github.com/pulumi/pulumi/issues/10312

When attempting to decode a string property value as JSON or YAML the
decoder would return a partial parse as valid. This resulted in strings
like "{} stuff" being reported as an empty JSON object, rather than the
literal string "{} stuff".

This also fixes the decoder to ignore whitespace around the value so for
example "   [1, 2]   " is now treated as a JSON array, not a string
literal.
2023-06-22 09:31:10 +01:00
Fraser Waters 1912bffe89 Don't use printf without a fixed format string
Fixes https://github.com/pulumi/pulumi/issues/11990

There were a few places we were passing an already formatted string in
as the format argument for printf. This replaces those calls with
non-formatting print calls.
2023-06-21 11:44:06 +01:00
Martin Lehmann 623aac46dd update snapshots with 'View in Browser' links 2023-06-01 13:55:36 +02:00
Martin Lehmann b98abc7dd9 add fix & update test data 2023-06-01 13:55:36 +02:00
Martin Lehmann ccb27fb417 add a test 2023-06-01 13:55:36 +02:00
Abhinav Gupta fff9a8dd5d
display: Switch "Open in Browser" to "View in Browser"
Switch this to "View in Browser" per discussion
which is closer to the old "View Live" message.

sdk/go/auto doesn't need an update because the regex there
is still using "View in Browser".
2023-03-10 10:52:43 -07:00
Pat Gavlin 2bad0a85e8 [cli] Add an "open in browser" keybinding
Add support for using Ctrl+O to open the current update in the browser
for backends that support permalinks.

The keybinding is advertised in the interactive display as part of the
message that displays the permalink:

```
Previewing update (dev)

View in Browser (Ctrl+O): https://<some-url>

     Type                          Name      Plan
 +   pulumi:pulumi:Stack           vpc-dev   create
 +   ├─ aws:ec2:Vpc                vpc       create
 +   ├─ aws:ec2:SecurityGroup      secgroup  create
 +   ├─ aws:ec2:SecurityGroupRule  rule-2    create
 +   ├─ aws:ec2:SecurityGroupRule  rule-0    create
 +   ├─ aws:ec2:SecurityGroupRule  rule-1    create
 +   └─ aws:ec2:SecurityGroupRule  rule-3    create
```

In order to maintain backwards compatibility with older versions of the
Automation API, the message is not changed for non-interactive
scenarios.
2023-03-09 15:52:13 -08:00
Pat Gavlin 5c77ce69fc [cli] Add autoscrolling and support page-{down,up}
- If the display is scrolled to the bottom, autoscroll it as new lines are
  added to the output.

- Add support for scrolling the interactive display using page-down and
  page-up. These keys scroll the display N lines at a time, where N is the
  height of the terminal.
2023-03-07 12:16:02 -08:00
aq17 cdd95f8cee Display text-based diff if yaml/json diff is semantically equal 2023-01-17 17:04:41 -08:00
Pat Gavlin 2e84add9da Update test baselines 2022-12-20 10:27:31 -08:00
Pat Gavlin 3aecebe5cb [color] Use graphemes to measure strings.
The number of Unicode code points in a string is not the same as the
number of user-visible characters (graphemes). When measuring colorized
strings, we want the latter rather than the former. Notably, these
changes fix some issues where the interactive display cut off before the
right edge of the terminal.
2022-11-09 08:23:00 -08:00
Pat Gavlin a20ddffde5 [cli] Abstract out terminal interactions
Replace direct interaction with the terminal with an abstraction. This
abstraction is tightly constrained to the capabilities needed for the
CLI's display. Using this abstraction allows for straightforward testing
of the interactive renderers.
2022-11-08 17:13:56 -08:00
Alex Qiu e07f0f038a
Display outputs last in diff view () 2022-09-01 12:09:54 -07:00
Alex Qiu 94a21fceae
Truncate long stack outputs ()
Co-authored-by: Ian Wahbe <ian@wahbe.com>
2022-07-12 11:24:21 -07:00
Pat Gavlin dba04339ee
[cli] Render JSON/YAML encoded values as objects. ()
Reuse the support for decoding JSON/YAML strings into objects to display
such values as objects during create, same, and delete operations (we
already do this for updates).

These changes also unexport a number of methods that should be internal
to the display package.
2022-04-28 16:16:06 -07:00
Pat Gavlin b443c26c4e
[cli] Do not render missing sames in arrays. ()
When rendering an array diff, do not render an unchanged element if we
do not have a value for the element.

Fixes .
2022-04-21 11:59:38 -07:00
Pat Gavlin f6c849209a
[cli] Show rich diffs for JSON/YAML objects/arrays ()
When displaying a diff between textual values, first try to decode the
old and new values as JSON and YAML. If both values decode successfully,
render the diff between the decoded values rather than the diff between
the text.

Fixes .
2022-04-13 10:31:36 -07:00
Pat Gavlin 21b9f2912c
[cli] Render changes to text properties as diffs. ()
Instead of simply rendering the old and new values for textual
properties, compute the diff between the old and new values and render
that. For single-line values, the diff is computed and rendered
character-wise, with simplification applied to avoid "small" diffs. For
multi-line values, the diff is computed and rendered linewise (as we
already to for textual assets).

Fixes .
2022-04-11 09:12:03 -07:00
Pat Gavlin 66a4150b71
[cli] Refactor the diff printer. ()
Instead of passing around a set of arguments that are mostly immutable,
collect the common parameters to most of our diff printing functions in
a struct and hang the various print methods off of that struct.
2022-04-09 16:04:35 -07:00