Skip to content

Commit c338f48

Browse files
authored
Show rule type details vertically in get call (#2029)
This shows more details for the rule type in a vertical table. e.g. ```bash $ minder ruletype get -i 7f1bbee6-a27a-4318-95f5-7408f2fcb106 No config file present, using default values. +-------------+-----------------------------------------------------------+ | RULE TYPE | | +-------------+-----------------------------------------------------------+ | ID | 7f1bbee6-a27a-4318-95f5-7408f2fcb106 | +-------------+-----------------------------------------------------------+ | Name | dependabot_configured | +-------------+-----------------------------------------------------------+ | Provider | github | +-------------+-----------------------------------------------------------+ | Project | jaormx | +-------------+-----------------------------------------------------------+ | Description | Verifies that Dependabot is configured for the repository | +-------------+-----------------------------------------------------------+ | Ingest type | git | +-------------+-----------------------------------------------------------+ | Eval type | rego | +-------------+-----------------------------------------------------------+ | Remediation | pull_request | +-------------+-----------------------------------------------------------+ | Alert | security_advisory | +-------------+-----------------------------------------------------------+ ``` ```bash $ minder ruletype get -i 7361c508-f954-414b-a103-589c2cb4bbc5 No config file present, using default values. +-------------+---------------------------------------------------------------------------------------+ | RULE TYPE | | +-------------+---------------------------------------------------------------------------------------+ | ID | 7361c508-f954-414b-a103-589c2cb4bbc5 | +-------------+---------------------------------------------------------------------------------------+ | Name | repo_action_allow_list | +-------------+---------------------------------------------------------------------------------------+ | Provider | github | +-------------+---------------------------------------------------------------------------------------+ | Project | jaormx | +-------------+---------------------------------------------------------------------------------------+ | Description | Verifies that the github workflows in a repo only use actions enumerated in the rule. | | | | +-------------+---------------------------------------------------------------------------------------+ | Ingest type | git | +-------------+---------------------------------------------------------------------------------------+ | Eval type | rego | +-------------+---------------------------------------------------------------------------------------+ | Remediation | unsupported | +-------------+---------------------------------------------------------------------------------------+ | Alert | security_advisory | +-------------+---------------------------------------------------------------------------------------+ ``` ```bash $ minder ruletype get -i 9ae5a1d0-df12-402b-861c-797d4217bdfb No config file present, using default values. +-------------+--------------------------------------------------------------------------------+ | RULE TYPE | | +-------------+--------------------------------------------------------------------------------+ | ID | 9ae5a1d0-df12-402b-861c-797d4217bdfb | +-------------+--------------------------------------------------------------------------------+ | Name | pr_trusty_check | +-------------+--------------------------------------------------------------------------------+ | Provider | github | +-------------+--------------------------------------------------------------------------------+ | Project | jaormx | +-------------+--------------------------------------------------------------------------------+ | Description | Verifies that pull requests do not add any dependencies with low Trusty scores | +-------------+--------------------------------------------------------------------------------+ | Ingest type | diff | +-------------+--------------------------------------------------------------------------------+ | Eval type | trusty | +-------------+--------------------------------------------------------------------------------+ | Remediation | unsupported | +-------------+--------------------------------------------------------------------------------+ | Alert | unsupported | +-------------+--------------------------------------------------------------------------------+ ``` Closes: #1062
1 parent 467dae6 commit c338f48

File tree

7 files changed

+49
-18
lines changed

7 files changed

+49
-18
lines changed

cmd/cli/app/ruletype/common.go

+30-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,34 @@ func shouldSkipFile(f string) bool {
9999
}
100100
}
101101

102-
// initializeTable initializes the table for the rule type
103-
func initializeTable() table.Table {
104-
return table.New(table.Simple, layouts.RuleType, nil)
102+
// initializeTableForList initializes the table for the rule type
103+
func initializeTableForList() table.Table {
104+
return table.New(table.Simple, layouts.RuleTypeList, nil)
105+
}
106+
107+
// initializeTableForList initializes the table for the rule type
108+
func initializeTableForOne() table.Table {
109+
return table.New(table.Simple, layouts.RuleTypeOne, nil)
110+
}
111+
112+
func oneRuleTypeToRows(t table.Table, rt *minderv1.RuleType) {
113+
t.AddRow("ID", *rt.Id)
114+
t.AddRow("Name", rt.Name)
115+
t.AddRow("Provider", *rt.Context.Provider)
116+
t.AddRow("Project", *rt.Context.Project)
117+
t.AddRow("Description", rt.Description)
118+
t.AddRow("Ingest type", rt.Def.Ingest.Type)
119+
t.AddRow("Eval type", rt.Def.Eval.Type)
120+
rem := "unsupported"
121+
if rt.Def.GetRemediate() != nil {
122+
rem = rt.Def.GetRemediate().Type
123+
}
124+
t.AddRow("Remediation", rem)
125+
126+
alert := "unsupported"
127+
if rt.Def.GetAlert() != nil {
128+
alert = rt.Def.GetAlert().Type
129+
}
130+
131+
t.AddRow("Alert", alert)
105132
}

cmd/cli/app/ruletype/ruletype_apply.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func applyCommand(_ context.Context, cmd *cobra.Command, conn *grpc.ClientConn)
6565
return cli.MessageAndError("Error expanding file args", err)
6666
}
6767

68-
table := initializeTable()
68+
table := initializeTableForList()
6969

7070
applyFunc := func(ctx context.Context, fileName string, rt *minderv1.RuleType) (*minderv1.RuleType, error) {
7171
createResp, err := client.CreateRuleType(ctx, &minderv1.CreateRuleTypeRequest{

cmd/cli/app/ruletype/ruletype_create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func createCommand(_ context.Context, cmd *cobra.Command, conn *grpc.ClientConn)
6464
return cli.MessageAndError("Error expanding file args", err)
6565
}
6666

67-
table := initializeTable()
67+
table := initializeTableForList()
6868

6969
createFunc := func(ctx context.Context, fileName string, rt *minderv1.RuleType) (*minderv1.RuleType, error) {
7070
resprt, err := client.CreateRuleType(ctx, &minderv1.CreateRuleTypeRequest{

cmd/cli/app/ruletype/ruletype_get.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,10 @@ func getCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn)
8080
cmd.Println(out)
8181
case app.Table:
8282
// Initialize the table
83-
table := initializeTable()
83+
table := initializeTableForOne()
8484
rt := rtype.GetRuleType()
85+
oneRuleTypeToRows(table, rt)
8586
// add the rule type to the table rows
86-
table.AddRow(
87-
*rt.Context.Provider,
88-
*rt.Context.Project,
89-
*rt.Id,
90-
rt.Name,
91-
rt.Description,
92-
)
9387
table.Render()
9488
}
9589
return nil

cmd/cli/app/ruletype/ruletype_list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func listCommand(ctx context.Context, cmd *cobra.Command, conn *grpc.ClientConn)
7676
}
7777
cmd.Println(out)
7878
case app.Table:
79-
table := initializeTable()
79+
table := initializeTableForList()
8080
for _, rt := range resp.RuleTypes {
8181
table.AddRow(
8282
*rt.Context.Provider,

internal/util/cli/table/layouts/layouts.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ type TableLayout string
2323
const (
2424
// KeyValue is the key value table layout
2525
KeyValue TableLayout = "keyvalue"
26-
// RuleType is the rule type table layout
27-
RuleType TableLayout = "ruletype"
26+
// RuleTypeOne is the rule type table layout
27+
RuleTypeOne TableLayout = "ruletype"
28+
// RuleTypeList is the rule type table layout
29+
RuleTypeList TableLayout = "ruletype_list"
2830
// ProfileSettings is the profile settings table layout
2931
ProfileSettings TableLayout = "profile_settings"
3032
// Profile is the profile table layout

internal/util/cli/table/simple/simple.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ func New(layout layouts.TableLayout, header []string) *Table {
3434
switch layout {
3535
case layouts.KeyValue:
3636
keyValueLayout(table)
37-
case layouts.RuleType:
37+
case layouts.RuleTypeOne:
3838
ruleTypeLayout(table)
39+
case layouts.RuleTypeList:
40+
ruleTypeListLayout(table)
3941
case layouts.ProfileSettings:
4042
profileSettingsLayout(table)
4143
case layouts.Profile:
@@ -120,11 +122,17 @@ func repoListLayout(table *tablewriter.Table) {
120122
table.SetHeader([]string{"ID", "Project", "Provider", "Upstream ID", "Owner", "Name"})
121123
}
122124

123-
func ruleTypeLayout(table *tablewriter.Table) {
125+
func ruleTypeListLayout(table *tablewriter.Table) {
124126
defaultLayout(table)
125127
table.SetHeader([]string{"Provider", "Project Name", "ID", "Name", "Description"})
126128
table.SetAutoMergeCellsByColumnIndex([]int{0, 1, 2, 3})
127129
// This is needed for the rule definition and rule parameters
128130
table.SetAutoWrapText(false)
131+
}
129132

133+
func ruleTypeLayout(table *tablewriter.Table) {
134+
defaultLayout(table)
135+
table.SetHeader([]string{"Rule Type"})
136+
// This is needed for the rule definition and rule parameters
137+
table.SetAutoWrapText(false)
130138
}

0 commit comments

Comments
 (0)