MCPcopy
hub / github.com/cloudfoundry/cli / Execute

Method Execute

cf/commands/plugin/install_plugin.go:95–167  ·  view source on GitHub ↗
(c flags.FlagContext)

Source from the content-addressed store, hash-verified

93}
94
95func (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

Callers

nothing calls this directly

Calls 15

confirmWithUserMethod · 0.95
RemoveFileMethod · 0.95
InstallMethod · 0.95
installPluginMethod · 0.95
NewDownloaderFunction · 0.92
NewPluginInstallerFunction · 0.92
ArgsMethod · 0.65
SayMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected