pulumi/pkg/cmd/pulumi/plugin_install.go
CyrusNajmabadi 66bd3f4aa8
Breaking changes due to Feature 2.0 work
* Make `async:true` the default for `invoke` calls (#3750)

* Switch away from native grpc impl. (#3728)

* Remove usage of the 'deasync' library from @pulumi/pulumi. (#3752)

* Only retry as long as we get unavailable back.  Anything else continues. (#3769)

* Handle all errors for now. (#3781)


* Do not assume --yes was present when using pulumi in non-interactive mode (#3793)

* Upgrade all paths for sdk and pkg to v2

* Backport C# invoke classes and other recent gen changes (#4288)

Adjust C# generation

* Replace IDeployment with a sealed class (#4318)

Replace IDeployment with a sealed class

* .NET: default to args subtype rather than Args.Empty (#4320)

* Adding system namespace for Dotnet code gen

This is required for using Obsolute attributes for deprecations

```
Iam/InstanceProfile.cs(142,10): error CS0246: The type or namespace name 'ObsoleteAttribute' could not be found (are you missing a using directive or an assembly reference?) [/Users/stack72/code/go/src/github.com/pulumi/pulumi-aws/sdk/dotnet/Pulumi.Aws.csproj]
Iam/InstanceProfile.cs(142,10): error CS0246: The type or namespace name 'Obsolete' could not be found (are you missing a using directive or an assembly reference?) [/Users/stack72/code/go/src/github.com/pulumi/pulumi-aws/sdk/dotnet/Pulumi.Aws.csproj]
```

* Fix the nullability of config type properties in C# codegen (#4379)
2020-04-14 09:30:25 +01:00

198 lines
6.8 KiB
Go

// Copyright 2016-2018, 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 main
import (
"fmt"
"io"
"os"
"github.com/blang/semver"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/pulumi/pulumi/pkg/v2/backend/display"
"github.com/pulumi/pulumi/sdk/v2/go/common/diag"
"github.com/pulumi/pulumi/sdk/v2/go/common/util/cmdutil"
"github.com/pulumi/pulumi/sdk/v2/go/common/util/contract"
"github.com/pulumi/pulumi/sdk/v2/go/common/workspace"
)
func newPluginInstallCmd() *cobra.Command {
var serverURL string
var cloudURL string
var exact bool
var file string
var reinstall bool
var verbose bool
var cmd = &cobra.Command{
Use: "install [KIND NAME VERSION]",
Args: cmdutil.MaximumNArgs(3),
Short: "Install one or more plugins",
Long: "Install one or more plugins.\n" +
"\n" +
"This command is used manually install plugins required by your program. It may\n" +
"be run either with a specific KIND, NAME, and VERSION, or by omitting these and\n" +
"letting Pulumi compute the set of plugins that may be required by the current\n" +
"project. VERSION cannot be a range: it must be a specific number.\n" +
"\n" +
"If you let Pulumi compute the set to download, it is conservative and may end up\n" +
"downloading more plugins than is strictly necessary.",
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
displayOpts := display.Options{
Color: cmdutil.GetGlobalColorization(),
}
if serverURL != "" && cloudURL != "" {
return errors.New("only one of server and cloud-url may be specified")
}
if cloudURL != "" {
cmdutil.Diag().Warningf(diag.Message("", "cloud-url is deprecated, please pass '--server "+
"%s/releases/plugins' instead."), cloudURL)
serverURL = cloudURL + "/releases/plugins"
}
// Note we don't presently set this as the default value for `--server` so we can play games like the above
// where we want to ensure at most one of `--server` or `--cloud-url` is set.
if serverURL == "" {
serverURL = "https://api.pulumi.com/releases/plugins"
}
// Parse the kind, name, and version, if specified.
var installs []workspace.PluginInfo
if len(args) > 0 {
if !workspace.IsPluginKind(args[0]) {
return errors.Errorf("unrecognized plugin kind: %s", args[0])
} else if len(args) < 2 {
return errors.New("missing plugin name argument")
} else if len(args) < 3 {
return errors.New("missing plugin version argument")
}
version, err := semver.ParseTolerant(args[2])
if err != nil {
return errors.Wrap(err, "invalid plugin semver")
}
installs = append(installs, workspace.PluginInfo{
Kind: workspace.PluginKind(args[0]),
Name: args[1],
Version: &version,
ServerURL: serverURL,
})
} else {
if file != "" {
return errors.New("--file (-f) is only valid if a specific package is being installed")
}
// If a specific plugin wasn't given, compute the set of plugins the current project needs.
plugins, err := getProjectPlugins()
if err != nil {
return err
}
for _, plugin := range plugins {
// Skip language plugins; by definition, we already have one installed.
// TODO[pulumi/pulumi#956]: eventually we will want to honor and install these in the usual way.
if plugin.Kind != workspace.LanguagePlugin {
installs = append(installs, plugin)
}
}
}
// Now for each kind, name, version pair, download it from the release website, and install it.
for _, install := range installs {
label := fmt.Sprintf("[%s plugin %s]", install.Kind, install)
cmdutil.Diag().Infoerrf(
diag.Message("", "%s installing"), label)
// If the plugin already exists, don't download it unless --reinstall was passed. Note that
// by default we accept plugins with >= constraints, unless --exact was passed which requires ==.
if !reinstall {
if exact {
if workspace.HasPlugin(install) {
if verbose {
cmdutil.Diag().Infoerrf(
diag.Message("", "%s skipping install (existing == match)"), label)
}
continue
}
} else {
if has, _ := workspace.HasPluginGTE(install); has {
if verbose {
cmdutil.Diag().Infoerrf(
diag.Message("", "%s skipping install (existing >= match)"), label)
}
continue
}
}
}
// If we got here, actually try to do the download.
var source string
var tarball io.ReadCloser
var err error
if file == "" {
if verbose {
cmdutil.Diag().Infoerrf(
diag.Message("", "%s downloading from %s"), label, install.ServerURL)
}
var size int64
if tarball, size, err = install.Download(); err != nil {
return errors.Wrapf(err, "%s downloading from %s", label, install.ServerURL)
}
tarball = workspace.ReadCloserProgressBar(tarball, size, "Downloading plugin", displayOpts.Color)
} else {
source = file
if verbose {
cmdutil.Diag().Infoerrf(
diag.Message("", "%s opening tarball from %s"), label, file)
}
if tarball, err = os.Open(file); err != nil {
return errors.Wrapf(err, "opening file %s", source)
}
}
if verbose {
cmdutil.Diag().Infoerrf(
diag.Message("", "%s installing tarball ..."), label)
}
if err = install.Install(tarball); err != nil {
return errors.Wrapf(err, "installing %s from %s", label, source)
}
}
return nil
}),
}
cmd.PersistentFlags().StringVar(&serverURL,
"server", "", "A URL to download plugins from")
cmd.PersistentFlags().StringVarP(&cloudURL,
"cloud-url", "c", "", "A cloud URL to download releases from")
cmd.PersistentFlags().BoolVar(&exact,
"exact", false, "Force installation of an exact version match (usually >= is accepted)")
cmd.PersistentFlags().StringVarP(&file,
"file", "f", "", "Install a plugin from a tarball file, instead of downloading it")
cmd.PersistentFlags().BoolVar(&reinstall,
"reinstall", false, "Reinstall a plugin even if it already exists")
cmd.PersistentFlags().BoolVar(&verbose,
"verbose", false, "Print detailed information about the installation steps")
// We are moving away from supporting this option, for now we mark it hidden.
contract.AssertNoError(cmd.PersistentFlags().MarkHidden("cloud-url"))
return cmd
}