-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
backend_run_warning.go
49 lines (40 loc) · 1.04 KB
/
backend_run_warning.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package cloud
import (
"context"
"fmt"
"strings"
tfe "github.com/hashicorp/go-tfe"
)
const (
changedPolicyEnforcementAction = "changed_policy_enforcements"
changedTaskEnforcementAction = "changed_task_enforcements"
ignoredPolicySetAction = "ignored_policy_sets"
)
func (b *Cloud) renderRunWarnings(ctx context.Context, client *tfe.Client, runId string) error {
if b.CLI == nil {
return nil
}
result, err := client.RunEvents.List(ctx, runId, nil)
if err != nil {
return err
}
if result == nil {
return nil
}
// We don't have to worry about paging as the API doesn't support it yet
for _, re := range result.Items {
switch re.Action {
case changedPolicyEnforcementAction, changedTaskEnforcementAction, ignoredPolicySetAction:
if re.Description != "" {
b.CLI.Warn(b.Colorize().Color(strings.TrimSpace(fmt.Sprintf(
runWarningHeader, re.Description)) + "\n"))
}
}
}
return nil
}
const runWarningHeader = `
[reset][yellow]Warning:[reset] %s
`