Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new install plugin from server function #10955

Merged
merged 13 commits into from Oct 24, 2022
10 changes: 10 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions sdk/go/auto/example_test.go
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions sdk/go/auto/local_workspace.go
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions sdk/go/auto/workspace.go
Expand Up @@ -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
jaxxstorm marked this conversation as resolved.
Show resolved Hide resolved
// RemovePlugin deletes the plugin matching the specified name and version.
RemovePlugin(context.Context, string, string) error
// ListPlugins lists all installed plugins.
Expand Down
11 changes: 11 additions & 0 deletions sdk/nodejs/automation/localWorkspace.ts
Expand Up @@ -495,6 +495,17 @@ export class LocalWorkspace implements Workspace {
async installPlugin(name: string, version: string, kind = "resource"): Promise<void> {
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<void> {
jaxxstorm marked this conversation as resolved.
Show resolved Hide resolved
await this.runPulumiCmd(["plugin", "install", "resource", name, version, "--server", server]);
}
/**
* Removes a plugin from the Workspace matching the specified name and version.
*
Expand Down
8 changes: 8 additions & 0 deletions sdk/nodejs/automation/workspace.ts
Expand Up @@ -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<void>;
/**
* 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<void>;
/**
* Removes a plugin from the Workspace matching the specified name and version.
Expand Down
2 changes: 2 additions & 0 deletions sdk/nodejs/tests/automation/localWorkspace.spec.ts
Expand Up @@ -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();
}));
Expand Down
5 changes: 5 additions & 0 deletions sdk/python/lib/pulumi/automation/_local_workspace.py
Expand Up @@ -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:
jaxxstorm marked this conversation as resolved.
Show resolved Hide resolved
self._run_pulumi_cmd_sync(
["plugin", "install", "resource", name, version, "--server", server]
)

def remove_plugin(
self,
name: Optional[str] = None,
Expand Down
10 changes: 10 additions & 0 deletions sdk/python/lib/pulumi/automation/_workspace.py
Expand Up @@ -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,
Expand Down