Skip to content
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 non-pulumi owned provider import alias #10447

Merged
merged 14 commits into from Aug 29, 2022
Merged

Fix non-pulumi owned provider import alias #10447

merged 14 commits into from Aug 29, 2022

Conversation

aq17
Copy link
Contributor

@aq17 aq17 commented Aug 19, 2022

Description

Fixes pulumi/pulumi-yaml#309

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@aq17 aq17 requested review from AaronFriel and iwahbe August 19, 2022 03:48
@aq17 aq17 changed the title fix codegen Fix non-pulumi owned provider import alias Aug 24, 2022
@aq17 aq17 marked this pull request as ready for review August 24, 2022 23:05
@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

Comment on lines 102 to 104
if strings.HasPrefix(name, "pulumi_") {
name = strings.TrimPrefix(name, "pulumi_")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting this here in makeValidIdentifier seems like it would affect more than just imports. It looks like the package name is inconsistently handled. I'd look at genPreamble to figure out why the import is generated as pulumi_eventstorecloud.

The schema for Pulumi package says its name is eventstorecloud: https://github.com/EventStore/pulumi-eventstorecloud/blob/main/provider/cmd/pulumi-resource-eventstorecloud/schema.json

But the NPM package is @eventstore/pulumi-eventstorecloud.

Is genPreamble generating the import * as name from the name of the NPM package instead of the name of the Pulumi package? That'd be my hunch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package name is correctly @eventstore/pulumi-eventstorecloud. We strip it to pulumi-eventstorecloud with Base(), then swap the - for _. It looks like we'll need a way of determining this provider originates from a non-pulumi repo, similar to the change here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - I think the issue is that we're working with the wrong string here. The issue isn't detecting whether it's "Pulumi owned", it's that we're doing:

makeValidIdentifier(NPM package name after the /)

Instead of:

makeValidIdentifier(Pulumi package name)

Where:

  • NPM package name: @eventstore/pulumi-eventstorecloud
  • Pulumi package name: eventstorecloud

The NPM package name ending in the same string as the Pulumi package name here is a coincidence and a misdirect.

Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makeValidIdentifier is (and should remain) special purposed to take an identifier and deterministically make it valid. It should not be used for correcting pulumi names.

Pulumi does not reserve the pulumi_ namespace, so this is not a reliable way to determine if a package is Pulumi owned. The schema allows you to override package import names, so the only valid way to get an import name is to look at the schema:

// NodePackageInfo contains NodeJS-specific information for a package.
type NodePackageInfo struct {
// Custom name for the NPM package.
PackageName string `json:"packageName,omitempty"`

The only way to correctly determine if a package is Pulumi owned is to check the Package.Publisher == "Pulumi" field. I'm scared of code that relies on that for correctness though.

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@aq17 aq17 requested review from AaronFriel and iwahbe August 25, 2022 20:39
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to see a test here. Otherwise this looks simple and sweet.

@aq17
Copy link
Contributor Author

aq17 commented Aug 26, 2022

I would love to see a test here. Otherwise this looks simple and sweet.

Double checked this for other languages – python and dotnet look fine, but in go, we incorrectly import it as "github.com/pulumi/pulumi-eventstorecloud/sdk/go/eventstorecloud" whereas the actual import is github.com/EventStore/....

Update: looks like this is an error in the provider schema. We should update that and can ignore it here? @iwahbe

@aq17 aq17 requested a review from iwahbe August 26, 2022 17:28
@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@aq17 aq17 dismissed AaronFriel’s stale review August 26, 2022 18:29

No longer relevant

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@aq17 aq17 merged commit 522f506 into master Aug 29, 2022
@pulumi-bot pulumi-bot deleted the aqiu/non-pu-codegen branch August 29, 2022 18:38
@aq17 aq17 self-assigned this Sep 2, 2022
@aq17 aq17 added this to the 0.77 milestone Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert - (Typescript) Providers are Incorrectly Referenced with Non Pulumi Owned Provider Packages
4 participants