-
Notifications
You must be signed in to change notification settings - Fork 0
/
approval_ruleset_proposal_rule.go
57 lines (48 loc) · 1.55 KB
/
approval_ruleset_proposal_rule.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
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"net/url"
"github.com/fullstaq-labs/sqedule/cli"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// approvalRulesetProposalRuleCmd represents the 'approval-ruleset proposal rule' command
var approvalRulesetProposalRuleCmd = &cobra.Command{
Use: "rule",
Short: "Manage rules in an approval ruleset proposal",
}
func approvalRulesetProposalRuleCmd_getRules(ruleset map[string]interface{}) ([]map[string]interface{}, error) {
version := ruleset["version"].(map[string]interface{})
rules := version["approval_rules"].([]interface{})
result := make([]map[string]interface{}, 0, len(rules))
for _, rule := range rules {
result = append(result, rule.(map[string]interface{}))
}
return result, nil
}
func approvalRulesetProposalRuleCmd_patchRules(viper *viper.Viper, config cli.Config, state cli.State, rules []map[string]interface{}) (map[string]interface{}, error) {
req, err := cli.NewApiRequest(config, state)
if err != nil {
return nil, err
}
body := map[string]interface{}{
"approval_rules": rules,
}
var ruleset map[string]interface{}
resp, err := req.
SetBody(&body).
SetResult(&ruleset).
Patch(fmt.Sprintf("/approval-rulesets/%s/proposals/%s",
url.PathEscape(viper.GetString("approval-ruleset-id")),
url.PathEscape(viper.GetString("proposal-id"))))
if err != nil {
return nil, err
}
if resp.IsError() {
return nil, fmt.Errorf("Error updating ruleset: %s", cli.GetApiErrorMessage(resp))
}
return ruleset, nil
}
func init() {
approvalRulesetProposalCmd.AddCommand(approvalRulesetProposalRuleCmd)
}