(c flags.FlagContext)
| 93 | } |
| 94 | |
| 95 | func (cmd *PluginInstall) Execute(c flags.FlagContext) error { |
| 96 | if !cmd.confirmWithUser( |
| 97 | c, |
| 98 | T("**Attention: Plugins are binaries written by potentially untrusted authors. Install and use plugins at your own risk.**\n\nDo you want to install the plugin {{.Plugin}}?", |
| 99 | map[string]interface{}{ |
| 100 | "Plugin": c.Args()[0], |
| 101 | }), |
| 102 | ) { |
| 103 | return errors.New(T("Plugin installation cancelled")) |
| 104 | } |
| 105 | |
| 106 | fileDownloader := downloader.NewDownloader(os.TempDir()) |
| 107 | |
| 108 | removeTmpFile := func() { |
| 109 | err := fileDownloader.RemoveFile() |
| 110 | if err != nil { |
| 111 | cmd.ui.Say(T("Problem removing downloaded binary in temp directory: ") + err.Error()) |
| 112 | } |
| 113 | } |
| 114 | defer removeTmpFile() |
| 115 | |
| 116 | deps := &plugininstaller.Context{ |
| 117 | Checksummer: cmd.checksum, |
| 118 | GetPluginRepos: cmd.config.PluginRepos, |
| 119 | FileDownloader: fileDownloader, |
| 120 | PluginRepo: cmd.pluginRepo, |
| 121 | RepoName: c.String("r"), |
| 122 | UI: cmd.ui, |
| 123 | } |
| 124 | installer := plugininstaller.NewPluginInstaller(deps) |
| 125 | pluginSourceFilepath := installer.Install(c.Args()[0]) |
| 126 | |
| 127 | _, pluginExecutableName := filepath.Split(pluginSourceFilepath) |
| 128 | |
| 129 | cmd.ui.Say(T( |
| 130 | "Installing plugin {{.PluginPath}}...", |
| 131 | map[string]interface{}{ |
| 132 | "PluginPath": pluginExecutableName, |
| 133 | }), |
| 134 | ) |
| 135 | |
| 136 | pluginDestinationFilepath := filepath.Join(cmd.pluginConfig.GetPluginPath(), pluginExecutableName) |
| 137 | |
| 138 | err := cmd.ensurePluginBinaryWithSameFileNameDoesNotAlreadyExist(pluginDestinationFilepath, pluginExecutableName) |
| 139 | if err != nil { |
| 140 | return err |
| 141 | } |
| 142 | |
| 143 | pluginMetadata, err := cmd.runBinaryAndObtainPluginMetadata(pluginSourceFilepath) |
| 144 | if err != nil { |
| 145 | return err |
| 146 | } |
| 147 | |
| 148 | err = cmd.ensurePluginIsSafeForInstallation(pluginMetadata, pluginDestinationFilepath, pluginSourceFilepath) |
| 149 | if err != nil { |
| 150 | return err |
| 151 | } |
| 152 |
nothing calls this directly
no test coverage detected