-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix pulumi new
creates new project when stack reference project name and project name don't match
#13250
Conversation
Changelog[uncommitted] (2023-06-29)Bug Fixes
|
pulumi new
creates new project when stack reference project name and project name don't match
pkg/cmd/pulumi/new.go
Outdated
@@ -82,6 +82,11 @@ func runNew(ctx context.Context, args newArgs) error { | |||
IsInteractive: args.interactive, | |||
} | |||
|
|||
// Check project name and stack reference project name are the same. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should just make --stack have to be a plain name. I.e. validate it's a tokens.Name
not a QName
. I realize the scuppers the idea of using a fully qualified ref here to set the org, but I think I'm coming around to preferring your idea of adding an "--org" flag to override that. Hell maybe we could even add a prompt as part of the new workflow to give users the choice for org if they haven't set that flag (The backend can suggest which orgs the user has access to, and if they only have one we can just default select it and not prompt so most users wouldn't see any difference here).
This might also interact with your other PR (#13234) so if we like this approach I'd put that PR on a short hold to make this change first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is sensible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally sounds reasonable to me, but we should discuss a concrete proposal in ideation.
Though, I don't think we can get away with forcing --stack
to be only a plain name, because it can be a fully qualified name already today. As such, this change to do this validation looks reasonable to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though, I don't think we can get away with forcing --stack to be only a plain name, because it can be a fully qualified name already today.
I think we've only run into problems trying to pass a ref here internally, I haven't seen any users doing this? I suspect it would be OK to do this.
As such, this change to do this validation looks reasonable to me.
If we are going to allow a ref here then yes we should validate the project matches but we should do that by calling the backends ParseStackReference method and checking the refs Project() property. Not by doing the string split currently proposed in this change.
That Parse will also cover a lot of other validation of the ref like checking its actually a valid name.
e1fa860
to
8135649
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a reasonable change.
Minus the minor comments, would appreciate comments on some of the key behavioral bits.
And we should maybe tweak the error message a bit, WDYT?
valid: false, | ||
}, | ||
{ | ||
projectName: "", | ||
stackRef: "org/foo/dev", | ||
valid: true, | ||
}, | ||
{ | ||
projectName: "foo", | ||
stackRef: "", | ||
valid: true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional: can omit zero-value fields.
valid: false, | |
}, | |
{ | |
projectName: "", | |
stackRef: "org/foo/dev", | |
valid: true, | |
}, | |
{ | |
projectName: "foo", | |
stackRef: "", | |
valid: true, | |
}, | |
}, | |
{ | |
stackRef: "org/foo/dev", | |
valid: true, | |
}, | |
{ | |
projectName: "foo", | |
valid: true, | |
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but I feel that it would be nicer to show this implicit detail since it's a list and I imagine it's easier to chunk if they all have the same structure.
d96d39d
to
d03d607
Compare
pkg/cmd/pulumi/new.go
Outdated
} | ||
|
||
// Catch the case where the user has specified a fully qualified stack reference. | ||
if strings.Count(stackName, "/") == 2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check for if there's two "/" here, just let the backend do the parse.
pkg/cmd/pulumi/new_test.go
Outdated
valid: true, | ||
}, | ||
} | ||
b, err := currentBackend(context.Background(), nil, display.Options{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be testing against the real backend.
c69227f
to
d6651d6
Compare
Assuming Justin's checked my comments and I'm off today
bors merge |
13250: fix `pulumi new` creates new project when stack reference project name and project name don't match r=dixler a=dixler <!--- 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 `pulumi new` `--stack` and `--name` check that the project name matches before creating a new project. Fixes #13248 ## 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. --> Co-authored-by: Kyle Dixler <kyle@pulumi.com>
13250: fix `pulumi new` creates new project when stack reference project name and project name don't match r=dixler a=dixler <!--- 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 `pulumi new` `--stack` and `--name` check that the project name matches before creating a new project. Fixes #13248 ## 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. --> Co-authored-by: Kyle Dixler <kyle@pulumi.com>
bors merge |
Already running a review |
Build failed: |
bors merge |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Description
pulumi new
--stack
and--name
check that the project name matches before creating a new project.Fixes #13248
Checklist
make tidy
to update any new dependenciesmake lint
to verify my code passes the lint checkgofumpt
make changelog
and committed thechangelog/pending/<file>
documenting my change