Skip to content

Commit 39314ef

Browse files
author
Pavan Sokke Nagaraj
authored
chore: export error ErrInsufficientPermissionsToRun and func ShowTextResultsStructured (#1297)
* chore: move ErrInsufficientPermissions to collect * chore: export func ShowTextResultsStructured * chore: rename to ErrInsufficientPermissionsToRun
1 parent 73c7dba commit 39314ef

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

pkg/collect/collect.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import (
1515
var (
1616
// ErrCollectorNotFound is returned when an undefined host collector is
1717
// specified by the user.
18-
ErrHostCollectorNotFound = errors.New("unrecognized host collector")
18+
ErrHostCollectorNotFound = errors.New("unrecognized host collector")
19+
ErrInsufficientPermissionsToRun = errors.New("insufficient permissions to run all collectors")
1920
)
2021

2122
type CollectorRunOpts struct {
@@ -129,7 +130,7 @@ func CollectRemote(c *troubleshootv1beta2.RemoteCollector, additionalRedactors *
129130

130131
if foundForbidden && !opts.CollectWithoutPermissions {
131132
collectResult.isRBACAllowed = false
132-
return collectResult, errors.New("insufficient permissions to run all collectors")
133+
return collectResult, ErrInsufficientPermissionsToRun
133134
}
134135

135136
// Run collectors synchronously.

pkg/preflight/collect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func CollectWithContext(ctx context.Context, opts CollectOpts, p *troubleshootv1
227227

228228
if foundForbidden && !opts.IgnorePermissionErrors {
229229
collectResult.isRBACAllowed = false
230-
return collectResult, errors.New("insufficient permissions to run all collectors")
230+
return collectResult, collect.ErrInsufficientPermissionsToRun
231231
}
232232

233233
for i, collector := range allCollectors {

pkg/preflight/text_results.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,29 @@ func showTextResultsHuman(preflightName string, analyzeResults []*analyzerunner.
6464
return results, nil
6565
}
6666

67-
type textResultOutput struct {
67+
type TextResultOutput struct {
6868
Title string `json:"title" yaml:"title"`
6969
Message string `json:"message" yaml:"message"`
7070
URI string `json:"uri,omitempty" yaml:"uri,omitempty"`
7171
Strict bool `json:"strict,omitempty" yaml:"strict,omitempty"`
7272
}
7373

74-
type textOutput struct {
75-
Pass []textResultOutput `json:"pass,omitempty" yaml:"pass,omitempty"`
76-
Warn []textResultOutput `json:"warn,omitempty" yaml:"warn,omitempty"`
77-
Fail []textResultOutput `json:"fail,omitempty" yaml:"fail,omitempty"`
74+
type TextOutput struct {
75+
Pass []TextResultOutput `json:"pass,omitempty" yaml:"pass,omitempty"`
76+
Warn []TextResultOutput `json:"warn,omitempty" yaml:"warn,omitempty"`
77+
Fail []TextResultOutput `json:"fail,omitempty" yaml:"fail,omitempty"`
7878
}
7979

8080
// Used by both JSON and YAML outputs
81-
func showTextResultsStructured(preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) *textOutput {
82-
output := textOutput{
83-
Pass: []textResultOutput{},
84-
Warn: []textResultOutput{},
85-
Fail: []textResultOutput{},
81+
func ShowTextResultsStructured(preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) *TextOutput {
82+
output := TextOutput{
83+
Pass: []TextResultOutput{},
84+
Warn: []TextResultOutput{},
85+
Fail: []TextResultOutput{},
8686
}
8787

8888
for _, analyzeResult := range analyzeResults {
89-
resultOutput := textResultOutput{
89+
resultOutput := TextResultOutput{
9090
Title: analyzeResult.Title,
9191
Message: analyzeResult.Message,
9292
URI: analyzeResult.URI,
@@ -109,7 +109,7 @@ func showTextResultsStructured(preflightName string, analyzeResults []*analyzeru
109109
}
110110

111111
func showTextResultsJSON(preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) (string, error) {
112-
output := showTextResultsStructured(preflightName, analyzeResults)
112+
output := ShowTextResultsStructured(preflightName, analyzeResults)
113113

114114
b, err := json.MarshalIndent(*output, "", " ")
115115
if err != nil {
@@ -120,7 +120,7 @@ func showTextResultsJSON(preflightName string, analyzeResults []*analyzerunner.A
120120
}
121121

122122
func showTextResultsYAML(preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) (string, error) {
123-
output := showTextResultsStructured(preflightName, analyzeResults)
123+
output := ShowTextResultsStructured(preflightName, analyzeResults)
124124

125125
b, err := yaml.Marshal(*output)
126126
if err != nil {

pkg/supportbundle/collect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func runCollectors(ctx context.Context, collectors []*troubleshootv1beta2.Collec
142142
}
143143

144144
if foundForbidden && !opts.CollectWithoutPermissions {
145-
return nil, errors.New("insufficient permissions to run all collectors")
145+
return nil, collect.ErrInsufficientPermissionsToRun
146146
}
147147

148148
for _, collector := range allCollectors {

0 commit comments

Comments
 (0)