Repository: datreeio/datree
Pull request #801 (2022-09-18 14:04:26)

fix: add login url to formatted outputs


Patch:
diff --git a/pkg/evaluation/non_interactive_evaluator_types.go b/pkg/evaluation/non_interactive_evaluator_types.go
index dca69fa..626dc85 100644
--- a/pkg/evaluation/non_interactive_evaluator_types.go
+++ b/pkg/evaluation/non_interactive_evaluator_types.go
@@ -10,6 +10,7 @@ type FormattedOutput struct {
 	EvaluationSummary       NonInteractiveEvaluationSummary `yaml:"evaluationSummary" json:"evaluationSummary" xml:"evaluationSummary"`
 	YamlValidationResults   []*extractor.InvalidFile        `yaml:"yamlValidationResults" json:"yamlValidationResults" xml:"yamlValidationResults"`
 	K8sValidationResults    []*extractor.InvalidFile        `yaml:"k8sValidationResults" json:"k8sValidationResults" xml:"k8sValidationResults"`
+	LoginUrl                string                          `yaml:"loginUrl" json:"loginUrl" xml:"loginUrl"`
 }
 
 type NonInteractiveEvaluationResults struct {
diff --git a/pkg/evaluation/printer.go b/pkg/evaluation/printer.go
index 171aa97..eacb321 100644
--- a/pkg/evaluation/printer.go
+++ b/pkg/evaluation/printer.go
@@ -115,8 +115,8 @@ func getFormattedOutput(resultsData *PrintResultsData) FormattedOutput {
 		},
 		YamlValidationResults: resultsData.InvalidYamlFiles,
 		K8sValidationResults:  resultsData.InvalidK8sFiles,
+		LoginUrl:              resultsData.LoginURL,
 	}
-
 	return formattedOutput
 }
 


Test patch:
diff --git a/pkg/evaluation/printer_test.go b/pkg/evaluation/printer_test.go
index 9251af2..20387c8 100644
--- a/pkg/evaluation/printer_test.go
+++ b/pkg/evaluation/printer_test.go
@@ -272,6 +272,7 @@ func createFormattedOutput() FormattedOutput {
 			K8sValidation:               "1/1",
 			PassedPolicyValidationCount: 0,
 		},
+		LoginUrl: "https://app.datree.io/login?t=tDJhAU478UTDeSwxGAy99y",
 	}
 }
 
@@ -366,6 +367,7 @@ func createFormattedOutputWithDocumentationUrl() FormattedOutput {
 			K8sValidation:               "1/1",
 			PassedPolicyValidationCount: 0,
 		},
+		LoginUrl: "https://app.datree.io/login?t=tDJhAU478UTDeSwxGAy99y",
 	}
 }
 
@@ -448,7 +450,7 @@ func printResults(outputFormat string) *printResultsTestCase {
 			invalidYamlFiles:  []*extractor.InvalidFile{},
 			invalidK8sFiles:   []*extractor.InvalidFile{},
 			evaluationSummary: printer.EvaluationSummary{},
-			loginURL:          "login/url",
+			loginURL:          "https://app.datree.io/login?t=tDJhAU478UTDeSwxGAy99y",
 			outputFormat:      outputFormat,
 		},
 		expected: nil,
diff --git a/pkg/evaluation/printer_test_expected_outputs/json_output.json b/pkg/evaluation/printer_test_expected_outputs/json_output.json
index 7b70b63..b287048 100644
--- a/pkg/evaluation/printer_test_expected_outputs/json_output.json
+++ b/pkg/evaluation/printer_test_expected_outputs/json_output.json
@@ -1,1 +1,1 @@
-{"policyValidationResults":[{"fileName":"File1","ruleResults":[{"identifier":"CONTAINERS_MISSING_IMAGE_VALUE_VERSION","name":"Ensure each container image has a pinned (tag) version","messageOnFailure":"Incorrect value for key `image` - specify an image version to avoid unpleasant \"version surprises\" in the future","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0.image","failedErrorLine":10,"failedErrorColumn":20}]}]},{"identifier":"CONTAINERS_MISSING_MEMORY_LIMIT_KEY","name":"Ensure each container has a configured memory limit","messageOnFailure":"Missing property object `limits.memory` - value should be within the accepted boundaries recommended by the organization","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0.resources.limits","failedErrorLine":95,"failedErrorColumn":15}]}]},{"identifier":"WORKLOAD_INVALID_LABELS_VALUE","name":"Ensure workload has valid label values","messageOnFailure":"Incorrect value for key(s) under `labels` - the vales syntax is not valid so the Kubernetes engine will not accept it","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"metadata.labels.owner","failedErrorLine":7,"failedErrorColumn":12}]}]},{"identifier":"CONTAINERS_MISSING_LIVENESSPROBE_KEY","name":"Ensure each container has a configured liveness probe","messageOnFailure":"Missing property object `livenessProbe` - add a properly configured livenessProbe to catch possible deadlocks","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0","failedErrorLine":22,"failedErrorColumn":11}]}]}]}],"policySummary":{"policyName":"Default","totalRulesInPolicy":21,"totalSkippedRules":0,"totalRulesFailed":4,"totalPassedCount":0},"evaluationSummary":{"configsCount":1,"filesCount":1,"passedYamlValidationCount":1,"k8sValidation":"1/1","passedPolicyValidationCount":0},"yamlValidationResults":null,"k8sValidationResults":null}
+{"policyValidationResults":[{"fileName":"File1","ruleResults":[{"identifier":"CONTAINERS_MISSING_IMAGE_VALUE_VERSION","name":"Ensure each container image has a pinned (tag) version","messageOnFailure":"Incorrect value for key `image` - specify an image version to avoid unpleasant \"version surprises\" in the future","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0.image","failedErrorLine":10,"failedErrorColumn":20}]}]},{"identifier":"CONTAINERS_MISSING_MEMORY_LIMIT_KEY","name":"Ensure each container has a configured memory limit","messageOnFailure":"Missing property object `limits.memory` - value should be within the accepted boundaries recommended by the organization","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0.resources.limits","failedErrorLine":95,"failedErrorColumn":15}]}]},{"identifier":"WORKLOAD_INVALID_LABELS_VALUE","name":"Ensure workload has valid label values","messageOnFailure":"Incorrect value for key(s) under `labels` - the vales syntax is not valid so the Kubernetes engine will not accept it","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"metadata.labels.owner","failedErrorLine":7,"failedErrorColumn":12}]}]},{"identifier":"CONTAINERS_MISSING_LIVENESSPROBE_KEY","name":"Ensure each container has a configured liveness probe","messageOnFailure":"Missing property object `livenessProbe` - add a properly configured livenessProbe to catch possible deadlocks","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0","failedErrorLine":22,"failedErrorColumn":11}]}]}]}],"policySummary":{"policyName":"Default","totalRulesInPolicy":21,"totalSkippedRules":0,"totalRulesFailed":4,"totalPassedCount":0},"evaluationSummary":{"configsCount":1,"filesCount":1,"passedYamlValidationCount":1,"k8sValidation":"1/1","passedPolicyValidationCount":0},"yamlValidationResults":null,"k8sValidationResults":null,"loginUrl":"https://app.datree.io/login?t=tDJhAU478UTDeSwxGAy99y"}
diff --git a/pkg/evaluation/printer_test_expected_outputs/json_output_verbose.json b/pkg/evaluation/printer_test_expected_outputs/json_output_verbose.json
index 92da676..f7c72e7 100644
--- a/pkg/evaluation/printer_test_expected_outputs/json_output_verbose.json
+++ b/pkg/evaluation/printer_test_expected_outputs/json_output_verbose.json
@@ -1,1 +1,1 @@
-{"policyValidationResults":[{"fileName":"File1","ruleResults":[{"identifier":"CONTAINERS_MISSING_IMAGE_VALUE_VERSION","name":"Ensure each container image has a pinned (tag) version","messageOnFailure":"Incorrect value for key `image` - specify an image version to avoid unpleasant \"version surprises\" in the future","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0.image","failedErrorLine":10,"failedErrorColumn":20}]}],"documentationUrl":"https://hub.datree.io/ensure-image-pinned-version"},{"identifier":"CONTAINERS_MISSING_MEMORY_LIMIT_KEY","name":"Ensure each container has a configured memory limit","messageOnFailure":"Missing property object `limits.memory` - value should be within the accepted boundaries recommended by the organization","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0.resources.limits","failedErrorLine":95,"failedErrorColumn":15}]}],"documentationUrl":"https://hub.datree.io/ensure-memory-limit"},{"identifier":"WORKLOAD_INVALID_LABELS_VALUE","name":"Ensure workload has valid label values","messageOnFailure":"Incorrect value for key(s) under `labels` - the vales syntax is not valid so the Kubernetes engine will not accept it","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"metadata.labels.owner","failedErrorLine":7,"failedErrorColumn":12}]}],"documentationUrl":"https://hub.datree.io/ensure-labels-value-valid"},{"identifier":"CONTAINERS_MISSING_LIVENESSPROBE_KEY","name":"Ensure each container has a configured liveness probe","messageOnFailure":"Missing property object `livenessProbe` - add a properly configured livenessProbe to catch possible deadlocks","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0","failedErrorLine":22,"failedErrorColumn":11}]}],"documentationUrl":"https://hub.datree.io/ensure-liveness-probe"}]}],"policySummary":{"policyName":"Default","totalRulesInPolicy":21,"totalSkippedRules":0,"totalRulesFailed":4,"totalPassedCount":0},"evaluationSummary":{"configsCount":1,"filesCount":1,"passedYamlValidationCount":1,"k8sValidation":"1/1","passedPolicyValidationCount":0},"yamlValidationResults":null,"k8sValidationResults":null}
+{"policyValidationResults":[{"fileName":"File1","ruleResults":[{"identifier":"CONTAINERS_MISSING_IMAGE_VALUE_VERSION","name":"Ensure each container image has a pinned (tag) version","messageOnFailure":"Incorrect value for key `image` - specify an image version to avoid unpleasant \"version surprises\" in the future","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0.image","failedErrorLine":10,"failedErrorColumn":20}]}],"documentationUrl":"https://hub.datree.io/ensure-image-pinned-version"},{"identifier":"CONTAINERS_MISSING_MEMORY_LIMIT_KEY","name":"Ensure each container has a configured memory limit","messageOnFailure":"Missing property object `limits.memory` - value should be within the accepted boundaries recommended by the organization","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0.resources.limits","failedErrorLine":95,"failedErrorColumn":15}]}],"documentationUrl":"https://hub.datree.io/ensure-memory-limit"},{"identifier":"WORKLOAD_INVALID_LABELS_VALUE","name":"Ensure workload has valid label values","messageOnFailure":"Incorrect value for key(s) under `labels` - the vales syntax is not valid so the Kubernetes engine will not accept it","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"metadata.labels.owner","failedErrorLine":7,"failedErrorColumn":12}]}],"documentationUrl":"https://hub.datree.io/ensure-labels-value-valid"},{"identifier":"CONTAINERS_MISSING_LIVENESSPROBE_KEY","name":"Ensure each container has a configured liveness probe","messageOnFailure":"Missing property object `livenessProbe` - add a properly configured livenessProbe to catch possible deadlocks","occurrencesDetails":[{"metadataName":"rss-site","kind":"Deployment","skipMessage":"","occurrences":1,"isSkipped":false,"failureLocations":[{"schemaPath":"spec.template.spec.containers.0","failedErrorLine":22,"failedErrorColumn":11}]}],"documentationUrl":"https://hub.datree.io/ensure-liveness-probe"}]}],"policySummary":{"policyName":"Default","totalRulesInPolicy":21,"totalSkippedRules":0,"totalRulesFailed":4,"totalPassedCount":0},"evaluationSummary":{"configsCount":1,"filesCount":1,"passedYamlValidationCount":1,"k8sValidation":"1/1","passedPolicyValidationCount":0},"yamlValidationResults":null,"k8sValidationResults":null,"loginUrl":"https://app.datree.io/login?t=tDJhAU478UTDeSwxGAy99y"}
diff --git a/pkg/evaluation/printer_test_expected_outputs/xml_output.xml b/pkg/evaluation/printer_test_expected_outputs/xml_output.xml
index abf8463..47599d6 100644
--- a/pkg/evaluation/printer_test_expected_outputs/xml_output.xml
+++ b/pkg/evaluation/printer_test_expected_outputs/xml_output.xml
@@ -85,4 +85,5 @@
 		<k8sValidation>1/1</k8sValidation>
 		<passedPolicyValidationCount>0</passedPolicyValidationCount>
 	</evaluationSummary>
+	<loginUrl>https://app.datree.io/login?t=tDJhAU478UTDeSwxGAy99y</loginUrl>
 </FormattedOutput>
diff --git a/pkg/evaluation/printer_test_expected_outputs/yaml_output.yaml b/pkg/evaluation/printer_test_expected_outputs/yaml_output.yaml
index 7e523dd..13d4668 100644
--- a/pkg/evaluation/printer_test_expected_outputs/yaml_output.yaml
+++ b/pkg/evaluation/printer_test_expected_outputs/yaml_output.yaml
@@ -71,4 +71,5 @@ evaluationSummary:
   passedPolicyValidationCount: 0
 yamlValidationResults: []
 k8sValidationResults: []
+loginUrl: https://app.datree.io/login?t=tDJhAU478UTDeSwxGAy99y