Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Datree
Commits
868b76f1
Unverified
Commit
868b76f1
authored
2 years ago
by
Roy Hadad
Committed by
GitHub
2 years ago
Browse files
Options
Download
Email Patches
Plain Diff
refactor: small refactors in printers (#662)
parent
c6d9ca9e
use_DI_to_get_config_home
620-disable-spinner-when-detecting-runs-in-ci-to-avoid-messing-up-logs-with-spinner-etc
702-datree-not-working-in-our-air-gapped-environment
746-offline-mode-does-not-work
762-unexpected-yaml-validation-error-did-not-find-expected-indicator
DAT-4105-remove-validate-yaml
DAT-4341-create-a-new-default-policy-all-rules
DAT-4389-verbose-support-all-output-formats
DAT-4405-remove-travis-cicd-impl
DAT-4427-cli-add-save-rendered-flag
ISSUE#799_pre-commit_permission_denied_fix
add-v-tag-rc
add_cluster_integration_submodule
add_rego_support
add_tests_to_fragile_areas_of_code
adjust_error_message_for_k8s_schema_not_found
argoproj
cverule
debug_save_read_default_rules_files
error-misspelling-metadataname
fix-version-message-print-empty
hadar-co-patch-1
line-err
logfile
offerings
patch-1-resove-conflicts
pre_commit_hook_with_datreeci
prestoprule
probe-rules
refactor_datree_kustomize_test
refactor_datree_kustomize_test_2
release/1.5.0
release/1.5.15
release/1.5.16
release/1.5.17
release/1.5.19
release/1.5.2
release/1.5.20
release/1.5.25
release/1.5.29
release/1.5.3
release/1.5.30
release/1.5.35
release/1.5.36
release/1.5.37
release/1.5.7
release/1.5.9
release/1.6.0
release/1.6.12
release/1.6.13
release/1.6.14
release/1.6.16
release/1.6.18
release/1.6.19
release/1.6.23
release/1.6.24
release/1.6.25
release/1.6.26
release/1.6.27
release/1.6.28
release/1.6.29
release/1.6.32
release/1.6.33
release/1.6.36
release/1.6.37
release/1.6.40
release/1.6.42
release/1.6.44
release/1.6.46
release/1.6.48
release/1.6.6
release/1.7.1
release/1.7.3
release/1.8.0
release/1.8.1
resty-client
sarif
schemadir
secretrules
skip-schema-validation-flag
svg-logo
test_pre_commit_hook
update-architecture-img
1.8.2-rc
1.8.1
1.8.1-rc
1.8.0
1.8.0-rc
1.7.3
1.7.3-rc
1.7.2-rc
1.7.1
1.7.1-rc
1.7.0-rc
1.6.49-rc
1.6.48
1.6.48-rc
1.6.47-rc
1.6.46
1.6.46-rc
1.6.45-rc
1.6.44
1.6.44-rc
1.6.43-rc
1.6.42
1.6.42-rc
1.6.41-rc
1.6.40
1.6.40-rc
1.6.39-rc
1.6.38-rc
1.6.37
1.6.37-rc
1.6.36
1.6.36-rc
1.6.35-rc
1.6.34-rc
1.6.33
1.6.33-rc
1.6.32
1.6.32-rc
1.6.31-rc
1.6.30-rc
1.6.29
1.6.29-rc
1.6.28
1.6.28-rc
1.6.27
1.6.27-rc
1.6.26
1.6.26-rc
1.6.25
1.6.25-rc
1.6.24
1.6.24-rc
1.6.23
1.6.23-rc
1.6.22-rc
1.6.21-rc
1.6.20-rc
1.6.19
1.6.19-rc
1.6.18
1.6.18-rc
1.6.17-rc
1.6.16
1.6.16-rc
1.6.15-rc
1.6.14
1.6.14-rc
1.6.13
1.6.13-rc
1.6.12
1.6.12-rc
1.6.11-rc
1.6.10-rc
1.6.9-rc
1.6.8-rc
1.6.7-rc
1.6.6
1.6.6-rc
1.6.5-rc
1.6.4-rc
1.6.3-rc
1.6.2-rc
1.6.1-rc
1.6.0
1.6.0-rc
1.5.38-rc
1.5.37
1.5.37-rc
1.5.36
1.5.36-rc
1.5.35
1.5.35-rc
1.5.34-rc
1.5.33-rc
1.5.32-rc
1.5.31-rc
1.5.30
1.5.30-rc
1.5.29
1.5.29-rc
1.5.28-rc
1.5.27-rc
1.5.26-rc
1.5.25
1.5.25-rc
1.5.24-rc
1.5.23-rc
1.5.22-rc
1.5.21-rc
1.5.20
1.5.20-rc
1.5.19
1.5.19-rc
1.5.18-rc
1.5.17
1.5.17-rc
1.5.16
1.5.16-rc
1.5.15
1.5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.5.33-rc
v1.5.32-rc
v1.5.31-rc
v1.5.30
v1.5.30-rc
v1.5.29
v1.5.29-rc
v1.5.28-rc
v1.5.27-rc
v1.5.26-rc
v1.5.25
v1.5.25-rc
v1.5.24-rc
v1.5.23-rc
v1.5.22-rc
v1.5.21-rc
v1.5.20
v1.5.20-rc
v1.5.19
v1.5.19-rc
v1.5.18-rc
v1.5.17
v1.5.17-rc
v1.5.16
v1.5.16-rc
v1.5.15
v1.5.15-rc
v1.5.14
v1.5.13
v1.5.12
v1.5.11
v1.5.10
v1.5.9
v1.5.7
v1.5.4-rc
v1.5.3
v1.5.3-rc
v1.5.2
v1.5.0
v1.4.43-rc
v1.4.40-rc-dima-test
v0.0.189798_tzlil_debug
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/validate-yaml/main.go
+1
-8
cmd/validate-yaml/main.go
pkg/evaluation/printer.go
+13
-13
pkg/evaluation/printer.go
pkg/evaluation/printer_test.go
+5
-5
pkg/evaluation/printer_test.go
pkg/printer/printer.go
+1
-4
pkg/printer/printer.go
with
20 additions
and
30 deletions
+20
-30
cmd/validate-yaml/main.go
+
1
-
8
View file @
868b76f1
...
...
@@ -5,8 +5,6 @@ import (
"fmt"
"strings"
"github.com/fatih/color"
"github.com/datreeio/datree/pkg/cliClient"
pkgExtractor
"github.com/datreeio/datree/pkg/extractor"
"github.com/datreeio/datree/pkg/localConfig"
...
...
@@ -15,8 +13,6 @@ import (
"github.com/spf13/cobra"
)
var
out
=
color
.
Output
const
(
STATUS_PASSED
=
"passed"
STATUS_FAILED
=
"failed"
...
...
@@ -125,10 +121,7 @@ func PrintValidationResults(printer IPrinter, invalidFiles []*pkgExtractor.Inval
validFilesCount
:=
filesCount
-
len
(
invalidFiles
)
sb
.
WriteString
(
printer
.
GetYamlValidationSummaryText
(
validFilesCount
,
filesCount
))
_
,
err
:=
out
.
Write
([]
byte
(
sb
.
String
()))
if
err
!=
nil
{
panic
(
err
)
}
fmt
.
Print
(
sb
.
String
())
}
func
SendResults
(
localConfig
ILocalConfig
,
client
ICliClient
,
cliVersion
string
,
isValid
bool
,
invalidYamlFiles
[]
*
pkgExtractor
.
InvalidFile
,
filesPaths
[]
string
)
{
...
...
This diff is collapsed.
Click to expand it.
pkg/evaluation/printer.go
+
13
-
13
View file @
868b76f1
...
...
@@ -83,18 +83,18 @@ func GetResultsText(resultsData *PrintResultsData) (string, error) {
switch
resultsData
.
OutputFormat
{
case
"json"
:
return
j
sonOutput
(
&
formattedOutput
)
return
getJ
sonOutput
(
&
formattedOutput
)
case
"yaml"
:
return
y
amlOutput
(
&
formattedOutput
)
return
getY
amlOutput
(
&
formattedOutput
)
case
"xml"
:
return
x
mlOutput
(
&
formattedOutput
)
return
getX
mlOutput
(
&
formattedOutput
)
case
"JUnit"
:
return
j
UnitOutput
(
&
formattedOutput
,
resultsData
.
AdditionalJUnitData
)
return
getJ
UnitOutput
(
&
formattedOutput
,
resultsData
.
AdditionalJUnitData
)
default
:
panic
(
errors
.
New
(
"invalid output format"
))
}
}
else
{
return
t
extOutput
(
textOutputData
{
return
getT
extOutput
(
textOutputData
{
results
:
resultsData
.
Results
.
EvaluationResults
,
invalidYamlFiles
:
resultsData
.
InvalidYamlFiles
,
invalidK8sFiles
:
resultsData
.
InvalidK8sFiles
,
...
...
@@ -109,7 +109,7 @@ func GetResultsText(resultsData *PrintResultsData) (string, error) {
}
}
func
j
sonOutput
(
formattedOutput
*
FormattedOutput
)
(
string
,
error
)
{
func
getJ
sonOutput
(
formattedOutput
*
FormattedOutput
)
(
string
,
error
)
{
jsonOutput
,
err
:=
json
.
Marshal
(
formattedOutput
)
if
err
!=
nil
{
return
""
,
err
...
...
@@ -118,7 +118,7 @@ func jsonOutput(formattedOutput *FormattedOutput) (string, error) {
return
fmt
.
Sprintln
(
string
(
jsonOutput
)),
nil
}
func
y
amlOutput
(
formattedOutput
*
FormattedOutput
)
(
string
,
error
)
{
func
getY
amlOutput
(
formattedOutput
*
FormattedOutput
)
(
string
,
error
)
{
yamlOutput
,
err
:=
yaml
.
Marshal
(
formattedOutput
)
if
err
!=
nil
{
return
""
,
err
...
...
@@ -127,15 +127,15 @@ func yamlOutput(formattedOutput *FormattedOutput) (string, error) {
return
fmt
.
Sprintln
(
string
(
yamlOutput
)),
nil
}
func
x
mlOutput
(
formattedOutput
*
FormattedOutput
)
(
string
,
error
)
{
return
getXmlOutput
(
formattedOutput
)
func
getX
mlOutput
(
formattedOutput
*
FormattedOutput
)
(
string
,
error
)
{
return
convertStructToXml
(
formattedOutput
)
}
func
j
UnitOutput
(
formattedOutput
*
FormattedOutput
,
additionalJUnitData
AdditionalJUnitData
)
(
string
,
error
)
{
return
getXmlOutput
(
FormattedOutputToJUnitOutput
(
*
formattedOutput
,
additionalJUnitData
))
func
getJ
UnitOutput
(
formattedOutput
*
FormattedOutput
,
additionalJUnitData
AdditionalJUnitData
)
(
string
,
error
)
{
return
convertStructToXml
(
FormattedOutputToJUnitOutput
(
*
formattedOutput
,
additionalJUnitData
))
}
func
getXmlOutput
(
output
interface
{})
(
string
,
error
)
{
func
convertStructToXml
(
output
interface
{})
(
string
,
error
)
{
xmlOutput
,
err
:=
xml
.
MarshalIndent
(
output
,
""
,
"
\t
"
)
xmlOutput
=
[]
byte
(
xml
.
Header
+
string
(
xmlOutput
))
if
err
!=
nil
{
...
...
@@ -145,7 +145,7 @@ func getXmlOutput(output interface{}) (string, error) {
return
fmt
.
Sprintln
(
string
(
xmlOutput
)),
nil
}
func
t
extOutput
(
outputData
textOutputData
)
(
string
,
error
)
{
func
getT
extOutput
(
outputData
textOutputData
)
(
string
,
error
)
{
sb
:=
strings
.
Builder
{}
pwd
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
pkg/evaluation/printer_test.go
+
5
-
5
View file @
868b76f1
...
...
@@ -111,16 +111,16 @@ func TestCustomOutputs(t *testing.T) {
additionalJUnitData
:=
createAdditionalJUnitData
()
expectedOutputs
:=
getExpectedOutputs
()
jsonStdout
,
_
:=
j
sonOutput
(
&
formattedOutput
)
jsonStdout
,
_
:=
getJ
sonOutput
(
&
formattedOutput
)
assert
.
Equal
(
t
,
expectedOutputs
.
json
,
jsonStdout
)
yamlStdout
,
_
:=
y
amlOutput
(
&
formattedOutput
)
yamlStdout
,
_
:=
getY
amlOutput
(
&
formattedOutput
)
assert
.
Equal
(
t
,
expectedOutputs
.
yaml
,
yamlStdout
)
xmlStdout
,
_
:=
x
mlOutput
(
&
formattedOutput
)
xmlStdout
,
_
:=
getX
mlOutput
(
&
formattedOutput
)
assert
.
Equal
(
t
,
expectedOutputs
.
xml
,
xmlStdout
)
JUnitStdout
,
_
:=
j
UnitOutput
(
&
formattedOutput
,
additionalJUnitData
)
JUnitStdout
,
_
:=
getJ
UnitOutput
(
&
formattedOutput
,
additionalJUnitData
)
assert
.
Equal
(
t
,
expectedOutputs
.
JUnit
,
JUnitStdout
)
}
...
...
@@ -129,7 +129,7 @@ func TestInvalidK8sCustomOutputs(t *testing.T) {
additionalJUnitData
:=
createAdditionalJUnitDataInvalidK8sFile
()
expectedOutputs
:=
getInvalidK8sFileExpectedOutputs
()
JUnitStdout
,
_
:=
j
UnitOutput
(
&
formattedOutput
,
additionalJUnitData
)
JUnitStdout
,
_
:=
getJ
UnitOutput
(
&
formattedOutput
,
additionalJUnitData
)
assert
.
Equal
(
t
,
expectedOutputs
.
JUnit
,
JUnitStdout
)
}
...
...
This diff is collapsed.
Click to expand it.
pkg/printer/printer.go
+
1
-
4
View file @
868b76f1
...
...
@@ -118,10 +118,7 @@ func (p *Printer) getK8sValidationWarningText(warning Warning) string {
}
func
(
p
*
Printer
)
PrintYamlSchemaResults
(
errorsResult
[]
jsonschema
.
Detailed
,
error
error
)
{
_
,
err
:=
out
.
Write
([]
byte
(
p
.
getYamlSchemaResultsText
(
errorsResult
,
error
)))
if
err
!=
nil
{
panic
(
err
)
}
fmt
.
Print
(
p
.
getYamlSchemaResultsText
(
errorsResult
,
error
))
}
func
(
p
*
Printer
)
getYamlSchemaResultsText
(
errorsResult
[]
jsonschema
.
Detailed
,
error
error
)
string
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help