Commit Graph

18 Commits

Author SHA1 Message Date
Will Jones 98d7246ea8
Don't rewrite step operations following failure ()
When displaying the progress of a Pulumi operation to the user, we want
the operation being displayed to reflect what is actually happening at
that moment in time. Most of the time, this means "just display the
operation in question" -- if a `create` is being executed, show
"creating", if a `delete` just completed, show "deleted", and so on.
However, there are cases where we can do better than just displaying the
"raw" operation. Specifically, our "replacement-like" operations
comprise a _series_ of steps that must execute for the operation as a
whole to make sense. For create-before-replace, we have:

* `create replacement` resource
* `replace` the old resource
* `delete original` resource

Other sequences, such as delete-before-replace, are similar (in the case
of delete-before-replace, the `delete original` step comes first).

While it might make sense to display the underlying steps as the
operation progresses, when the series of steps has _completed_, it's
(arguably) much clearer to simply render the string `replaced` so that
the user knows what has gone on. Similarly, during a preview, it (again
arguably) makes more sense for us to state that the intention is to
`replace`, rather than any one of `create replacement`/`replace`/`delete
original` and so on.

Alas, there is a case where this is potentially misleading and thus
undesirable behaviour. If an _error_ occurs during execution, the
operation will terminate at the next opportunity. In doing so, it will
enter a "done" state. At this point, we _do not_ want to rewrite the
step that was actually happening before the error interrupted it (e.g.
`create replacement`) with the "end" state (e.g. `replaced`), since the
error may mean we never reached that desired state. We want the display
to be as true to the raw series of steps as possible. This PR implements
this change, so that programs which terminate due to errors do not
rewrite their steps.

This PR addresses some of the confusion in , in which we
incorrectly reported that a delete-before-replace resource had been
`replaced` when in fact we had only completed the deletion before being
interrupted by an error elsewhere.
2024-05-31 10:48:07 +00:00
Justin Van Patten 82c546d873
Fix mangled diffs of strings containing url-encoded chars ()
Fix mangled diffs of strings containing url-encoded chars

Currently, modifying a stack output that contains url-encoded characters
can lead to it showing the value as `"!(NOVERB)"` or `"!(MISSING)"`.

For example, changing a stack output `path` from `"%2F"` to `"%2f"`
shows the diff as:

```
Outputs:
  ~ path: "%!(NOVERB)F" => "%!(NOVERB)f"
```

The expected diff output should be:

```
Outputs:
  ~ path: "%2F" => "%2f"
```

This is happening because the code that emits parts of the diff is
expecting a format string. Go is trying to parse the `%` in the value as
a format string and is having problems parsing it.

The fix is to emit the parts of the diff verbatim, so it isn't treated
as a format string.

Fixes 

Note: I've done an audit of the other calls to `write` in
`object_diff.go` and all the other call sites are passing actual format
strings or constants. This was the only case where we were passing user
input as a format string.
2024-05-08 08:23:40 +00:00
Fraser Waters dc12644fe4
Never show property diffs for OpSame ()
<!--- 
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/15944.

## 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. -->

---------

Co-authored-by: Thomas Gummerer <t.gummerer@gmail.com>
2024-05-02 12:28:43 +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