From 4e0b5df981e3af2973c5e0b7c573f0e7f779cd85 Mon Sep 17 00:00:00 2001 From: Luke Hoban Date: Thu, 6 Aug 2020 16:33:59 -0700 Subject: [PATCH] Support publishing and consuming policy packs using any runtime (#5102) Fixes #5089. --- CHANGELOG.md | 5 +++++ pkg/backend/httpstate/policypack.go | 25 ++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c97c555b8..d7143ff0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,13 @@ CHANGELOG ========= ## HEAD (Unreleased) + - Add nuget badge to README [#5117](https://github.com/pulumi/pulumi/pull/5117) +- Support publishing and consuming Policy Packs using any runtime + [#5102](https://github.com/pulumi/pulumi/pull/5102) + + ## 2.8.1 (2020-08-05) - Fix a bug where passphrase managers were not being diff --git a/pkg/backend/httpstate/policypack.go b/pkg/backend/httpstate/policypack.go index 250e3b773..6e67e5a38 100644 --- a/pkg/backend/httpstate/policypack.go +++ b/pkg/backend/httpstate/policypack.go @@ -185,19 +185,15 @@ func (pack *cloudPolicyPack) Publish( return result.FromError( errors.Wrap(err, "could not publish policies because of error running npm pack")) } - } else if strings.EqualFold(runtime, "python") { + } else { // npm pack puts all the files in a "package" subdirectory inside the .tgz it produces, so we'll do - // the same for Python. That way, after unpacking, we can look for the PulumiPolicy.yaml inside the + // the same for other runtimes. That way, after unpacking, we can look for the PulumiPolicy.yaml inside the // package directory to determine the runtime of the policy pack. packTarball, err = archive.TGZ(op.PlugCtx.Pwd, "package", true /*useDefaultExcludes*/) if err != nil { return result.FromError( errors.Wrap(err, "could not publish policies because of error creating the .tgz")) } - } else { - return result.Errorf( - "failed to publish policies because PulumiPolicy.yaml specifies an unsupported runtime %s", - runtime) } // @@ -298,12 +294,19 @@ func installRequiredPolicy(finalDir string, tarball []byte) error { // TODO[pulumi/pulumi#1334]: move to the language plugins so we don't have to hard code here. if strings.EqualFold(proj.Runtime.Name(), "nodejs") { - return completeNodeJSInstall(finalDir) + if err := completeNodeJSInstall(finalDir); err != nil { + return err + } } else if strings.EqualFold(proj.Runtime.Name(), "python") { - return completePythonInstall(finalDir, projPath, proj) + if err := completePythonInstall(finalDir, projPath, proj); err != nil { + return err + } } - return errors.Errorf("unsupported policy runtime %s", proj.Runtime.Name()) + fmt.Println("Finished installing policy pack") + fmt.Println() + + return nil } func completeNodeJSInstall(finalDir string) error { @@ -314,8 +317,6 @@ func completeNodeJSInstall(finalDir string) error { "in %q before this policy pack works", bin, finalDir) } - fmt.Println("Finished installing policy pack") - fmt.Println() return nil } @@ -331,7 +332,5 @@ func completePythonInstall(finalDir, projPath string, proj *workspace.PolicyPack return err } - fmt.Println("Finished installing policy pack") - fmt.Println() return nil }