diff --git a/changelog/pending/20221012--auto--pluginfromserver.yaml b/changelog/pending/20221012--auto--pluginfromserver.yaml new file mode 100644 index 000000000000..41923b6cac35 --- /dev/null +++ b/changelog/pending/20221012--auto--pluginfromserver.yaml @@ -0,0 +1,10 @@ +changes: +- type: feat + scope: auto/go + description: Add InstallPluginFromServer method +- type: feat + scope: auto/nodejs + description: Add InstallPluginFromServer +- type: feat + scope: auto/python + description: Add install_plugin_from_server diff --git a/sdk/go/auto/example_test.go b/sdk/go/auto/example_test.go index ea41b1b5465b..9cd9e7f3f0be 100644 --- a/sdk/go/auto/example_test.go +++ b/sdk/go/auto/example_test.go @@ -368,6 +368,13 @@ func ExampleLocalWorkspace_InstallPlugin() { w.InstallPlugin(ctx, "aws", "v3.2.0") } +func ExampleLocalWorkspace_InstallPluginFromServer() { + ctx := context.Background() + // create a workspace from a local project + w, _ := NewLocalWorkspace(ctx, WorkDir(filepath.Join(".", "program"))) + w.InstallPluginFromServer(ctx, "scaleway", "v1.2.0", "github://api.github.com/lbrlabs") +} + func ExampleNewLocalWorkspace() { ctx := context.Background() // WorkDir sets the working directory for the LocalWorkspace. The workspace will look for a default diff --git a/sdk/go/auto/local_workspace.go b/sdk/go/auto/local_workspace.go index 15aae0f6c44c..00e08c878509 100644 --- a/sdk/go/auto/local_workspace.go +++ b/sdk/go/auto/local_workspace.go @@ -381,6 +381,21 @@ func (l *LocalWorkspace) InstallPlugin(ctx context.Context, name string, version return nil } +// InstallPluginFromServer acquires the plugin matching the specified name and version from a third party server. +func (l *LocalWorkspace) InstallPluginFromServer( + ctx context.Context, + name string, + version string, + server string, +) error { + stdout, stderr, errCode, err := l.runPulumiCmdSync( + ctx, "plugin", "install", "resource", name, version, "--server", server) + if err != nil { + return newAutoError(errors.Wrap(err, "failed to install plugin"), stdout, stderr, errCode) + } + return nil +} + // RemovePlugin deletes the plugin matching the specified name and verision. func (l *LocalWorkspace) RemovePlugin(ctx context.Context, name string, version string) error { stdout, stderr, errCode, err := l.runPulumiCmdSync(ctx, "plugin", "rm", "resource", name, version, "--yes") diff --git a/sdk/go/auto/workspace.go b/sdk/go/auto/workspace.go index 201f2a437bb7..877553cd235a 100644 --- a/sdk/go/auto/workspace.go +++ b/sdk/go/auto/workspace.go @@ -92,6 +92,8 @@ type Workspace interface { ListStacks(context.Context) ([]StackSummary, error) // InstallPlugin acquires the plugin matching the specified name and version. InstallPlugin(context.Context, string, string) error + // InstallPluginFromServer acquires the plugin matching the specified name and version. + InstallPluginFromServer(context.Context, string, string, string) error // RemovePlugin deletes the plugin matching the specified name and version. RemovePlugin(context.Context, string, string) error // ListPlugins lists all installed plugins. diff --git a/sdk/nodejs/automation/localWorkspace.ts b/sdk/nodejs/automation/localWorkspace.ts index 829f1fdb3c80..62d65ac6ea4c 100644 --- a/sdk/nodejs/automation/localWorkspace.ts +++ b/sdk/nodejs/automation/localWorkspace.ts @@ -495,6 +495,17 @@ export class LocalWorkspace implements Workspace { async installPlugin(name: string, version: string, kind = "resource"): Promise { await this.runPulumiCmd(["plugin", "install", kind, name, version]); } + /** + * Installs a plugin in the Workspace, from a third party server. + * + * @param name the name of the plugin. + * @param version the version of the plugin e.g. "v1.0.0". + * @param kind the kind of plugin, defaults to "resource" + * @param server the server to install the plugin from + */ + async installPluginFromServer(name: string, version: string, server: string): Promise { + await this.runPulumiCmd(["plugin", "install", "resource", name, version, "--server", server]); + } /** * Removes a plugin from the Workspace matching the specified name and version. * diff --git a/sdk/nodejs/automation/workspace.ts b/sdk/nodejs/automation/workspace.ts index 7088e9ac43a8..e65f13dc20cb 100644 --- a/sdk/nodejs/automation/workspace.ts +++ b/sdk/nodejs/automation/workspace.ts @@ -178,6 +178,14 @@ export interface Workspace { * @param version the version of the plugin e.g. "v1.0.0". * @param kind the kind of plugin e.g. "resource" */ + installPluginFromServer(name: string, version: string, server: string): Promise; + /** + * Installs a plugin in the Workspace from a remote server, for example a third party plugin. + * + * @param name the name of the plugin. + * @param version the version of the plugin e.g. "v1.0.0". + * @param server the server to install the plugin into + */ installPlugin(name: string, version: string, kind?: string): Promise; /** * Removes a plugin from the Workspace matching the specified name and version. diff --git a/sdk/nodejs/tests/automation/localWorkspace.spec.ts b/sdk/nodejs/tests/automation/localWorkspace.spec.ts index 95cebf85961a..48a5e268db91 100644 --- a/sdk/nodejs/tests/automation/localWorkspace.spec.ts +++ b/sdk/nodejs/tests/automation/localWorkspace.spec.ts @@ -57,6 +57,8 @@ describe("LocalWorkspace", () => { it(`adds/removes/lists plugins successfully`, asyncTest(async () => { const ws = await LocalWorkspace.create({}); await ws.installPlugin("aws", "v3.0.0"); + // See https://github.com/pulumi/pulumi/issues/11013 for why this is disabled + //await ws.installPluginFromServer("scaleway", "v1.2.0", "github://api.github.com/lbrlabs"); await ws.removePlugin("aws", "3.0.0"); await ws.listPlugins(); })); diff --git a/sdk/python/lib/pulumi/automation/_local_workspace.py b/sdk/python/lib/pulumi/automation/_local_workspace.py index 84e68373da67..dbdc64f64e29 100644 --- a/sdk/python/lib/pulumi/automation/_local_workspace.py +++ b/sdk/python/lib/pulumi/automation/_local_workspace.py @@ -302,6 +302,11 @@ def list_stacks(self) -> List[StackSummary]: def install_plugin(self, name: str, version: str, kind: str = "resource") -> None: self._run_pulumi_cmd_sync(["plugin", "install", kind, name, version]) + def install_plugin_from_server(self, name: str, version: str, server: str) -> None: + self._run_pulumi_cmd_sync( + ["plugin", "install", "resource", name, version, "--server", server] + ) + def remove_plugin( self, name: Optional[str] = None, diff --git a/sdk/python/lib/pulumi/automation/_workspace.py b/sdk/python/lib/pulumi/automation/_workspace.py index 2b0669d363ce..9d1fa870cf2a 100644 --- a/sdk/python/lib/pulumi/automation/_workspace.py +++ b/sdk/python/lib/pulumi/automation/_workspace.py @@ -325,6 +325,16 @@ def install_plugin(self, name: str, version: str, kind: str = "resource") -> Non :param kind: The kind of plugin. """ + @abstractmethod + def install_plugin_from_server(self, name: str, version: str, server: str) -> None: + """ + Installs a plugin in the Workspace from a remote server, for example a third party plugin. + + :param name: The name of the plugin to install. + :param version: The version to install. + :param server: The server to install from. + """ + @abstractmethod def remove_plugin( self,