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
1 change: 1 addition & 0 deletions .github/workflows/ci-run-test.yml
Expand Up @@ -305,6 +305,7 @@ jobs:
env:
PULUMI_NODE_MODULES: ${{ runner.temp }}/opt/pulumi/node_modules
PULUMI_ROOT: ${{ runner.temp }}/opt/pulumi
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jaxxstorm marked this conversation as resolved.
Show resolved Hide resolved
- name: Convert Node coverage data
if: ${{ inputs.platform != 'windows-latest' }}
run: |
Expand Down
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
19 changes: 15 additions & 4 deletions sdk/nodejs/automation/localWorkspace.ts
Expand Up @@ -492,8 +492,19 @@ export class LocalWorkspace implements Workspace {
* @param version the version of the plugin e.g. "v1.0.0".
* @param kind the kind of plugin, defaults to "resource"
*/
async installPlugin(name: string, version: string, kind = "resource"): Promise<void> {
await this.runPulumiCmd(["plugin", "install", kind, name, version]);
async installPlugin(name: string, version: string): Promise<void> {
await this.runPulumiCmd(["plugin", "install", "resource", 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 All @@ -503,8 +514,8 @@ export class LocalWorkspace implements Workspace {
* e.g. "1.0.0", ">1.0.0".
* @param kind he kind of plugin, defaults to "resource".
*/
async removePlugin(name?: string, versionRange?: string, kind = "resource"): Promise<void> {
jaxxstorm marked this conversation as resolved.
Show resolved Hide resolved
const args = ["plugin", "rm", kind];
async removePlugin(name?: string, versionRange?: string): Promise<void> {
const args = ["plugin", "rm", "resource"];
if (name) {
args.push(name);
}
Expand Down
1 change: 1 addition & 0 deletions sdk/nodejs/tests/automation/localWorkspace.spec.ts
Expand Up @@ -57,6 +57,7 @@ describe("LocalWorkspace", () => {
it(`adds/removes/lists plugins successfully`, asyncTest(async () => {
const ws = await LocalWorkspace.create({});
await ws.installPlugin("aws", "v3.0.0");
await ws.installPluginFromServer("scaleway", "v1.2.0", "github://api.github.com/lbrlabs");
await ws.removePlugin("aws", "3.0.0");
await ws.listPlugins();
}));
Expand Down
12 changes: 8 additions & 4 deletions sdk/python/lib/pulumi/automation/_local_workspace.py
Expand Up @@ -299,16 +299,20 @@ def list_stacks(self) -> List[StackSummary]:
stack_list.append(stack)
return stack_list

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(self, name: str, version: str) -> None:
self._run_pulumi_cmd_sync(["plugin", "install", "resource", 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,
version_range: Optional[str] = None,
kind: str = "resource",
) -> None:
args = ["plugin", "rm", kind]
args = ["plugin", "rm", "resource"]
if name:
args.append(name)
if version_range:
Expand Down