Add permalink to policy publish (#3757)

This commit is contained in:
Erin Krengel 2020-01-15 17:08:14 -08:00 committed by GitHub
parent ae13d6672c
commit 77bcba412e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

View file

@ -9,6 +9,8 @@ CHANGELOG
- Breaking change for Policy which is in Public Preview: Change `pulumi policy apply` to `pulumi policy enable`, and allow users to specify the Policy Group.
- Add Permalink to output when publishing a Policy Pack.
## 1.8.1 (2019-12-20)
- Fix a panic in `pulumi stack select`. [#3687](https://github.com/pulumi/pulumi/pull/3687)

View file

@ -497,9 +497,10 @@ func (pc *Client) StartUpdate(ctx context.Context, update UpdateIdentifier,
return resp.Version, resp.Token, nil
}
// PublishPolicyPack publishes a `PolicyPack` to the Pulumi service.
// PublishPolicyPack publishes a `PolicyPack` to the Pulumi service. If it's successful, it returns
// the version that was published.
func (pc *Client) PublishPolicyPack(ctx context.Context, orgName string,
analyzerInfo plugin.AnalyzerInfo, dirArchive io.Reader) error {
analyzerInfo plugin.AnalyzerInfo, dirArchive io.Reader) (int, error) {
//
// Step 1: Send POST containing policy metadata to service. This begins process of creating
@ -517,7 +518,7 @@ func (pc *Client) PublishPolicyPack(ctx context.Context, orgName string,
var resp apitype.CreatePolicyPackResponse
err := pc.restCall(ctx, "POST", publishPolicyPackPath(orgName), nil, req, &resp)
if err != nil {
return errors.Wrapf(err, "Publish policy pack failed")
return 0, errors.Wrapf(err, "Publish policy pack failed")
}
fmt.Printf("Published as version %d\n", resp.Version)
@ -529,12 +530,12 @@ func (pc *Client) PublishPolicyPack(ctx context.Context, orgName string,
putS3Req, err := http.NewRequest(http.MethodPut, resp.UploadURI, dirArchive)
if err != nil {
return errors.Wrapf(err, "Failed to upload compressed PolicyPack")
return 0, errors.Wrapf(err, "Failed to upload compressed PolicyPack")
}
_, err = http.DefaultClient.Do(putS3Req)
if err != nil {
return errors.Wrapf(err, "Failed to upload compressed PolicyPack")
return 0, errors.Wrapf(err, "Failed to upload compressed PolicyPack")
}
//
@ -544,10 +545,10 @@ func (pc *Client) PublishPolicyPack(ctx context.Context, orgName string,
err = pc.restCall(ctx, "POST",
publishPolicyPackPublishComplete(orgName, analyzerInfo.Name, resp.Version), nil, nil, nil)
if err != nil {
return errors.Wrapf(err, "Request to signal completion of the publish operation failed")
return 0, errors.Wrapf(err, "Request to signal completion of the publish operation failed")
}
return nil
return resp.Version, nil
}
// ApplyPolicyPack enables a `PolicyPack` to the Pulumi organization. If policyGroup is not empty,

View file

@ -158,11 +158,13 @@ func (pack *cloudPolicyPack) Publish(
fmt.Println("Uploading policy pack to Pulumi service")
err = pack.cl.PublishPolicyPack(ctx, pack.ref.orgName, analyzerInfo, bytes.NewReader(packTarball))
version, err := pack.cl.PublishPolicyPack(ctx, pack.ref.orgName, analyzerInfo, bytes.NewReader(packTarball))
if err != nil {
return result.FromError(err)
}
fmt.Printf("\nPermalink: %s/policypacks/%s/%d\n", pack.Backend().URL(), pack.ref.Name(), version)
return nil
}