pulumi/pkg/util/plugin.go

104 lines
2.9 KiB
Go
Raw Permalink Normal View History

// Copyright 2016-2023, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package util
import (
Use the yaml converter plugin rather than Eject (#14437) <!--- 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. --> We add some hooks to ensure we always use the version of pulumi-converter-yaml that matches the version of yaml we've linked the CLI to, this preserves the behaviour we have today that eject code matches the gen code. At some point it will make sense to decouple these and often just default to the the latest converter instead. This unlinks one part of the yaml codebase from the cli. We still need to do codegen and docgen, but this at least means breaking changes can be made to the eject interface without breaking the build because of the circular dependency cycle. ## 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. --> - [x] I have added tests that prove my fix is effective or that my feature works - Covered by `TestYamlConvertSmoke` <!--- 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. -->
2023-12-08 08:55:49 +00:00
"runtime/debug"
"github.com/blang/semver"
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
Use the yaml converter plugin rather than Eject (#14437) <!--- 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. --> We add some hooks to ensure we always use the version of pulumi-converter-yaml that matches the version of yaml we've linked the CLI to, this preserves the behaviour we have today that eject code matches the gen code. At some point it will make sense to decouple these and often just default to the the latest converter instead. This unlinks one part of the yaml codebase from the cli. We still need to do codegen and docgen, but this at least means breaking changes can be made to the eject interface without breaking the build because of the circular dependency cycle. ## 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. --> - [x] I have added tests that prove my fix is effective or that my feature works - Covered by `TestYamlConvertSmoke` <!--- 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. -->
2023-12-08 08:55:49 +00:00
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
)
// SetKnownPluginDownloadURL sets the PluginDownloadURL for the given PluginSpec if it's a known plugin.
// Returns true if it filled in the URL.
func SetKnownPluginDownloadURL(spec *workspace.PluginSpec) bool {
// If the download url is already set don't touch it
if spec.PluginDownloadURL != "" {
return false
}
// Zaid's arm and bicep converters so that `pulumi convert --from arm/bicep` just works.
if spec.Kind == apitype.ConverterPlugin && (spec.Name == "arm" || spec.Name == "bicep") {
spec.PluginDownloadURL = "github://api.github.com/Zaid-Ajaj"
return true
}
pulumiversePlugins := []string{
"acme",
"aquasec",
"astra",
"aws-eksa",
"buildkite",
"concourse",
"configcat",
"doppler",
"exoscale",
"gandi",
"github-credentials",
"googleworkspace",
"harbor",
"hcp",
"heroku",
"matchbox",
"mssql",
"ngrok",
"purrl",
"sentry",
"statuscake",
"time",
"unifi",
"vra",
"zitadel",
}
if spec.Kind == apitype.ResourcePlugin {
for _, plugin := range pulumiversePlugins {
if spec.Name == plugin {
spec.PluginDownloadURL = "github://api.github.com/pulumiverse"
return true
}
}
}
return false
}
Use the yaml converter plugin rather than Eject (#14437) <!--- 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. --> We add some hooks to ensure we always use the version of pulumi-converter-yaml that matches the version of yaml we've linked the CLI to, this preserves the behaviour we have today that eject code matches the gen code. At some point it will make sense to decouple these and often just default to the the latest converter instead. This unlinks one part of the yaml codebase from the cli. We still need to do codegen and docgen, but this at least means breaking changes can be made to the eject interface without breaking the build because of the circular dependency cycle. ## 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. --> - [x] I have added tests that prove my fix is effective or that my feature works - Covered by `TestYamlConvertSmoke` <!--- 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. -->
2023-12-08 08:55:49 +00:00
// SetKnownPluginVersion sets the Version for the given PluginSpec if it's a known plugin.
// Returns true if it filled in the version.
func SetKnownPluginVersion(spec *workspace.PluginSpec) bool {
// If the version is already set don't touch it
if spec.Version != nil {
return false
}
if spec.Kind == apitype.ConverterPlugin && spec.Name == "yaml" {
Use the yaml converter plugin rather than Eject (#14437) <!--- 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. --> We add some hooks to ensure we always use the version of pulumi-converter-yaml that matches the version of yaml we've linked the CLI to, this preserves the behaviour we have today that eject code matches the gen code. At some point it will make sense to decouple these and often just default to the the latest converter instead. This unlinks one part of the yaml codebase from the cli. We still need to do codegen and docgen, but this at least means breaking changes can be made to the eject interface without breaking the build because of the circular dependency cycle. ## 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. --> - [x] I have added tests that prove my fix is effective or that my feature works - Covered by `TestYamlConvertSmoke` <!--- 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. -->
2023-12-08 08:55:49 +00:00
// By default use the version of yaml we've linked to. N.B. This has to be tested manually because
// ReadBuildInfo doesn't return anything in test builds (https://github.com/golang/go/issues/33976).
info, ok := debug.ReadBuildInfo()
contract.Assertf(ok, "expected to be able to read build info")
for _, dep := range info.Deps {
if dep.Path == "github.com/pulumi/pulumi-yaml" {
v, err := semver.ParseTolerant(dep.Version)
contract.AssertNoErrorf(err, "expected to be able to parse version for yaml got %q", dep.Version)
spec.Version = &v
return true
}
}
}
return false
}